Back to index

lightning-sunbird  0.9+nobinonly
CallTree.java
Go to the documentation of this file.
00001 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * The contents of this file are subject to the Netscape Public
00004  * License Version 1.1 (the "License"); you may not use this file
00005  * except in compliance with the License. You may obtain a copy of
00006  * the License at http://www.mozilla.org/NPL/
00007  *
00008  * Software distributed under the License is distributed on an "AS
00009  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00010  * implied. See the License for the specific language governing
00011  * rights and limitations under the License.
00012  *
00013  * The Original Code is Mozilla Communicator client code, released
00014  * March 31, 1998.
00015  *
00016  * The Initial Developer of the Original Code is Netscape
00017  * Communications Corporation.  Portions created by Netscape are
00018  * Copyright (C) 1998 Netscape Communications Corporation. All
00019  * Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Patrick C. Beard <beard@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the
00026  * terms of the GNU Public License (the "GPL"), in which case the
00027  * provisions of the GPL are applicable instead of those above.
00028  * If you wish to allow use of your version of this file only
00029  * under the terms of the GPL and not to allow others to use your
00030  * version of this file under the NPL, indicate your decision by
00031  * deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL.  If you do not delete
00033  * the provisions above, a recipient may use your version of this
00034  * file under either the NPL or the GPL.
00035  */
00036 
00037 import java.util.Enumeration;
00038 import java.util.Vector;
00039 
00043 public class CallTree {
00044        public static class Node {
00045            int id;
00046            Node parent;
00047            String data;
00048            
00049            public Node(int id, Node parent) {
00050                this.id = id;
00051                this.parent = parent;
00052            }
00053        };
00054 
00055        private Vector nodes = new Vector(16000);
00056        private StringTable strings;
00057 
00058     public CallTree(StringTable strings) {
00059         nodes.addElement(null);
00060         this.strings = strings;
00061     }
00062        
00067        public Node parseNode(String line) {
00068         try {
00069             int start = 1 + line.indexOf('=');
00070             int endTag = line.indexOf('>');
00071             if (line.charAt(endTag - 1) == '/') {
00072                 // just references an already parsed node.
00073                 int id = Integer.parseInt(line.substring(start, endTag - 1));
00074                 return (Node) nodes.elementAt(id);
00075             } else {
00076                 int end = line.indexOf(' ', start + 1);
00077                 int id = Integer.parseInt(line.substring(start, end));
00078                 start = 1 + line.indexOf('=', end + 1);
00079                 end = line.indexOf('>', start + 1);
00080                 int pid = Integer.parseInt(line.substring(start, end));
00081                 Node node = addNode(id, pid);
00082                 start = end + 1;
00083                 end = line.lastIndexOf('<');
00084                 node.data = strings.intern(line.substring(start, end));
00085                 return node;
00086             }
00087         } catch (NumberFormatException nfe) {
00088         }
00089         return null;
00090        }
00091        
00092        public Node addNode(int id, int pid) {
00093            Node parent = (Node) nodes.elementAt(pid);
00094            Node node = new Node(id, parent);
00095            nodes.addElement(node);
00096            if (nodes.size() != (id + 1))
00097                throw new Error("inconsistent node id");
00098            return node;
00099        }
00100        
00101        public Node getNode(int id) {
00102            return (Node) nodes.elementAt(id);
00103        }
00104 }