DoubleLinkedTreeNode.java
Go to the documentation of this file.
00001 /*
00002  * (c) copyright 2008, Technische Universitaet Graz and Technische Universitaet Wien
00003  *
00004  * This file is part of jdiagengine.
00005  *
00006  * jdiagengine is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * jdiagengine is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * You should have received a copy of the GNU General Public License
00016  * along with jdiagengine. If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * Authors: Joerg Weber, Franz Wotawa
00019  * Contact: jweber@ist.tugraz.at (preferred), or fwotawa@ist.tugraz.at
00020  *
00021  */
00022 
00023 
00024 package utils;
00025 
00026 import java.util.*;
00027 
00028 
00029 public class DoubleLinkedTreeNode {
00030     
00031     protected Long id = null;
00032 
00033     protected DoubleLinkedTreeNode parent;
00034 
00035     protected ArrayList children;
00036 
00037     /*
00038      * Creates a new node which has a unique id.
00039      *
00040      * No space is reserved for children.
00041      */
00042     public DoubleLinkedTreeNode() {
00043         children = new ArrayList(0);
00044     }
00045 
00046     /*
00047      * Chreates a new node and reserves capacity for the passed number of children.
00048      */
00049     public DoubleLinkedTreeNode(int childrenCapacity) {
00050         this.children = new ArrayList(childrenCapacity);
00051     }
00052 
00053     /*
00054      * Should be called by DoubleLinkedTree only.
00055      */
00056     protected void setId(long id) {
00057         this.id = new Long(id);
00058     }
00059 
00060     /*
00061      * Should be called by DoubleLinkedTree only.
00062      */
00063     protected void setParent(DoubleLinkedTreeNode parent) {
00064         this.parent = parent;
00065     }
00066 
00067     public long getId() {
00068         return id.longValue();
00069     }
00070 
00071     /*
00072      * Should be called by DoubleLinkedTree only.
00073      */
00074     protected void addChild(DoubleLinkedTreeNode child) {
00075         children.add(child);
00076     }
00077 
00078     /*
00079      * Trims the capacity for children to the current number of children (ensures that no memory is wasted).
00080      */
00081     public void trimChildren() {
00082         children.trimToSize();
00083     }
00084 
00085     public boolean hasParent() {
00086         return (parent != null);
00087     }
00088 
00089     /*
00090      * Returns the parent of the node or null if the node has no parent.
00091      */
00092     public DoubleLinkedTreeNode getParent() {
00093         return parent;
00094     }
00095 
00096     public Iterator getChildrenIterator() {
00097         return children.iterator();
00098     }
00099 
00100     public List getChildren() {
00101         return children;
00102     }
00103 
00104     public boolean hasChildren() {
00105         return (children.size() > 0);
00106     }    
00107 
00108     public boolean isLeafNode() {
00109         return (children.size() == 0);
00110     }
00111 
00112     public void removeChild(DoubleLinkedTreeNode childNode) {
00113         Iterator itChildren = children.iterator();
00114         while (itChildren.hasNext()) {
00115             Object o = itChildren.next();
00116             if (childNode == o) {
00117                 itChildren.remove();
00118                 return;
00119             }
00120         }
00121 
00122         assert(false);  // if childNode is not among the children of this node
00123     }
00124 
00125 }


tug_ist_diagnosis_engine
Author(s): Safdar Zaman, Gerald Steinbauer
autogenerated on Mon Jan 6 2014 11:51:16