Back to index

wims  3.65+svn20090927
Public Member Functions | Private Member Functions | Private Attributes
fr.ove.openmath.jome.model.Node Class Reference

Definition of a N-ary tree structure. More...

Inheritance diagram for fr.ove.openmath.jome.model.Node:
Inheritance graph
[legend]
Collaboration diagram for fr.ove.openmath.jome.model.Node:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Node ()
 The Constructor.
Node getFather ()
 Returns the father of the instance.
int getRank ()
 Returns the rank of the instance in the set of its father's children.
Node getChild (int rank)
 Returns the child of the instance at the specified rank.
int getNbChildren ()
 Returns the number of children of the instance.
Vector getChildren ()
 Returns the list of children of the instance.
void setFather (Node father)
 Sets a father to instance.
void addChild (Node child)
 Adds a child to the instance.
void addChild (Node child, int rank)
 Adds a child to the instance.
void removeChild (int rank)
 Removes the child of the current node at the specified rank.
void removeChild (Node node)
 Removes the specified child of the instance.
void removeAll ()
 Remove all the children of the instance.
void moveChildren (Vector list, int rank)
 Moves the specified list of the instance children to the specified rank.
boolean hasChild (Node node)
 Checks if the specified node is a child of the current instance.
synchronized Object clone ()
 Clones (copies) the instance.
synchronized Object duplicate ()
 Duplicates (copies) the instance.
int getDepth ()
 Returns the depth of the node.
void computeDepth ()
 Compute the depth of the node.
int getNbStrahler ()
 Returns the strahler number of the node.
void setNbStrahler (int nbStrahler)
 Sets the Strahler number of the instance.
void computeNbStrahler ()
 Computes the strahler number of the tree whose the instance is the root.

Private Member Functions

void adjustRank ()
 Sets the rank of the children of the instance.
void changeRank (int rank)
 Changes the rank of the instance.
void adjustChildrenDepth ()
 Adjusts the depth of the children of the node.
void computeNodeNbStrahler ()
 Computes the strahler number of the node.

Private Attributes

Node father
 The father of the instance in the tree structure.
Vector children
 The children of the instance in the tree structure.
int rank
 The rank of the instance in the set of its father's children.
int nbStrahler
 The strahler number of the node.
int depth
 The depth of the node in the tree structure.

Detailed Description

Definition of a N-ary tree structure.

Author:
© 1999 DIRAT Laurent
Version:
2.0 23/06/1999

Definition at line 41 of file Node.java.


Constructor & Destructor Documentation

The Constructor.

Definition at line 72 of file Node.java.

                  {
        father = null;
        rank = 0;
        nbStrahler = 1;
        depth = 0;
    }

Here is the caller graph for this function:


Member Function Documentation

Adds a child to the instance.


The child added is the last of the list.

Parameters:
childthe child to add.

Definition at line 163 of file Node.java.

                                     {
        if (children == null)
            children = new Vector(0, 1);
            
        children.addElement(child);
        child.setFather(this);
        adjustRank();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void fr.ove.openmath.jome.model.Node.addChild ( Node  child,
int  rank 
) [inline]

Adds a child to the instance.


The child is added at the specified rank.

Parameters:
childthe child to add.
rankthe specified rank.

Definition at line 179 of file Node.java.

                                               {
        if (children == null)
            children = new Vector(0, 1);
            
        children.insertElementAt(child, rank);
        child.setFather(this);
        adjustRank();
    }

Here is the call graph for this function:

Adjusts the depth of the children of the node.

Definition at line 395 of file Node.java.

                                       {
        Node child = null;
        int count = children.size();
        for (int i = 0; i < count; i++) {
            child = (Node) children.elementAt(i);
            //child.depth++;
            child.depth = depth + 1;
            
            // On met à jour maintenant la profondeur des fils éventuels.
            if (child.children != null)
                child.adjustChildrenDepth();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void fr.ove.openmath.jome.model.Node.adjustRank ( ) [inline, private]

Sets the rank of the children of the instance.

Definition at line 229 of file Node.java.

                              {
        int i = 0;

        for (Enumeration e = children.elements(); e.hasMoreElements(); i++)
            ((Node) e.nextElement()).rank  = i;
    }

Here is the caller graph for this function:

void fr.ove.openmath.jome.model.Node.changeRank ( int  rank) [inline, private]

Changes the rank of the instance.

Parameters:
rankthe new rank.

Definition at line 241 of file Node.java.

                                      {
        int oldRank = this.rank;
        //Node father = this.father;

        if (rank > father.getNbChildren()) {
            rank = father.getNbChildren() + 1;
            father.addChild(this);  // On ajoute en dernier
        }
        else {
            if (rank < 0)
                rank = 0;
            father.addChild(this, rank);
        }

        // On élimine le noeud courant situé à l'ancienne position
        if (rank < oldRank)
            father.removeChild(oldRank + 1);  // l'insertion s'est faite avant, donc le fils courant est décalé de 1
        else
            father.removeChild(oldRank);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized Object fr.ove.openmath.jome.model.Node.clone ( ) [inline]

Clones (copies) the instance.


Make a deep clone, i.e. the children of the instance are also cloned.
Nevertheless, the father of the clone is set to null.

Definition at line 309 of file Node.java.

                                      {
        Node theClone = null;
        try {
            //return super.clone();
            
            // On clone l'instance.
            theClone = (Node) super.clone();
            // Le père du clone est null
            theClone.father = null;
            if (children != null) {
                // On clone les enfants
                Vector theChildren = new Vector();
                int count = children.size();
                for (int i = 0; i < count; i++)
                    theChildren.addElement(((Node) children.elementAt(i)).clone());
                theClone.children = theChildren;
            }
            
        } catch (CloneNotSupportedException e) {
            System.out.println("clone failed !!");
        }
        
        return theClone;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Compute the depth of the node.

Definition at line 376 of file Node.java.

                               {
        int theDepth = 0;
        Node theFather = father;
        
        while (theFather != null) {
            theDepth++;
            theFather = theFather.father;
        }
        
        depth = theDepth;
        
        // On met à jour maintenant la profondeur des fils éventuels.
        if (children != null)
            adjustChildrenDepth();
    }

Here is the call graph for this function:

Computes the strahler number of the tree whose the instance is the root.

Definition at line 491 of file Node.java.

                                    {
        if (children != null) {
            int count = children.size();
            for (int i = 0; i < count; i++)
                ((Node) children.elementAt(i)).computeNbStrahler();
                
            computeNodeNbStrahler();
        }
    }

Here is the call graph for this function:

Computes the strahler number of the node.

Prerequisite : the strahler number of the children of the instance are computed.

Definition at line 434 of file Node.java.

                                         {
        // Si children == null, alors ça veut dire que l'instance est une feuille, et donc le
        // Strahler est déjà initialisé à 1.
        if (children != null) {
            int count = children.size();
            if (count == 0)
                // ça c'est au cas où des manipulations sur l'arbre, mais normalement, pas de soucis.
                nbStrahler = 1;
            else if (count == 1)
                nbStrahler = ((Node) children.elementAt(0)).nbStrahler;
            else {
                int max = 0;
                int min = Integer.MAX_VALUE;
                
                int tmpStrahler;
                
                for (int i = 0; i < count; i++) {
                    tmpStrahler = ((Node) children.elementAt(i)).nbStrahler;
                    min = (min < tmpStrahler) ? min : tmpStrahler;
                    max = (max > tmpStrahler) ? max : tmpStrahler;
                }
                
                int tabLength = max - min + 1;
                int tabValue[] = new int[tabLength];
                
                for (int i = 0; i < tabLength; i++) 
                    tabValue[i] = 0;
                    
                for (int i = 0; i < count; i++)
                    tabValue[((Node) children.elementAt(i)).nbStrahler - min] += 1;
                    
                int free = max - 1;
                tmpStrahler = max + tabValue[tabLength - 1] - 1;
                
                int requiered;
                for (int i = tabLength - 2; i >= 0; i--) {
                    if (tabValue[i] == 0)
                        continue;
                        
                    requiered = i + min +  tabValue[i] - 1;
                    
                    if (free > requiered)
                        free -= tabValue[i];
                    else {
                        tmpStrahler += requiered - free;
                        free = i + min - 1;
                    }
                }
                
                nbStrahler = tmpStrahler;
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized Object fr.ove.openmath.jome.model.Node.duplicate ( ) [inline]

Duplicates (copies) the instance.


The difference with clone, is a deep copy is not performed.
The father of the duplicate is set to null.

Definition at line 339 of file Node.java.

                                          {
        Node theClone = null;
        try {
            // On clone l'instance.
            theClone = (Node) super.clone();
            // Le père du clone est null
            theClone.father = null;
            // Pas de fils
            theClone.children = new Vector();
        } catch (CloneNotSupportedException e) {
            System.out.println("duplicate failed !!");
        }
        
        return theClone;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the child of the instance at the specified rank.

Parameters:
rankthe specified rank.
Returns:
the child at the specified rank.

Definition at line 105 of file Node.java.

                                   {
        Node child = null;
        
        if (children != null) {
            try {
                child = (Node) children.elementAt(rank);
            }
            catch (ArrayIndexOutOfBoundsException e) {
                return null;
            }
        }
        
        return child;
    }

Here is the call graph for this function:

Returns the list of children of the instance.

Returns:
the list of children

Definition at line 137 of file Node.java.

                                {
        return children;
    }

Here is the caller graph for this function:

Returns the depth of the node.

Definition at line 369 of file Node.java.

                          {
        return depth;
    }

Here is the caller graph for this function:

Returns the father of the instance.

Returns:
the father of the node.

Definition at line 86 of file Node.java.

                            {
        return father;
    }

Returns the number of children of the instance.

Definition at line 123 of file Node.java.

                               {
        int size = 0;
        
        if (children != null)
            size = children.size();
            
        return size;
    }

Here is the caller graph for this function:

Returns the strahler number of the node.

Definition at line 416 of file Node.java.

                               {
        return nbStrahler;
    }

Returns the rank of the instance in the set of its father's children.

Returns:
the rank of the node.

Definition at line 95 of file Node.java.

                         {
        return rank;
    }

Here is the caller graph for this function:

Checks if the specified node is a child of the current instance.

Parameters:
nodethe specified node.
Returns:
true if the specified node is a child of the current instance. false otherwise.

Definition at line 295 of file Node.java.

                                       {
        boolean hasChild = false;
        
        if (children != null) 
            hasChild = children.contains(node);
            
        return hasChild;
    }

Here is the caller graph for this function:

void fr.ove.openmath.jome.model.Node.moveChildren ( Vector  list,
int  rank 
) [inline]

Moves the specified list of the instance children to the specified rank.

The first child in the list has its rank setted to the specified one, the second to the first+1, ...and so on.

Parameters:
listthe list of the instance children.
rankthe specified rank.

Definition at line 269 of file Node.java.

                                                    {
        // Puisque list contient des fils de l'instance, on peut partir du prérequis que
        // children est non null.
        int NbChildren = children.size();
        Node child = null;
        Node first = null;
        
        for (int i = 0; i < list.size(); i++) {
            child = (Node) list.elementAt(i);
            if (i == 0)
                first = child;
            if (rank > NbChildren)
                child.changeRank(rank + (i+1));
            else {
                child.changeRank(rank);
                rank = first.getRank() + (i+1);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Remove all the children of the instance.

Definition at line 215 of file Node.java.

                            {
        if (children != null) {
            int count = children.size();
            for (int i = 0; i < count; i++)
                ((Node) children.elementAt(rank)).father = null;
                
            children.setSize(0);
            children.trimToSize();
        }
    }

Here is the caller graph for this function:

void fr.ove.openmath.jome.model.Node.removeChild ( int  rank) [inline]

Removes the child of the current node at the specified rank.

Parameters:
rankthe rank of the child to remove.

Definition at line 193 of file Node.java.

                                      {
        if (children != null) {
            children.removeElementAt(rank);
            adjustRank();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Removes the specified child of the instance.

Parameters:
nodethe child to remove.

Definition at line 205 of file Node.java.

                                       {
        if (children != null) {
            children.removeElement(node);
            adjustRank();
        }
    }

Here is the call graph for this function:

Sets a father to instance.

Parameters:
fatherthe father to set

Definition at line 148 of file Node.java.

                                       {
        this.father = father;
        depth = father.depth + 1;
        
        // On met à jour maintenant la profondeur des fils éventuels.
        if (children != null)
            adjustChildrenDepth();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void fr.ove.openmath.jome.model.Node.setNbStrahler ( int  nbStrahler) [inline]

Sets the Strahler number of the instance.


!!! ATTENTION !!! : should not be called at any time. Just specific cases only, above all, when you know what you are doing.

Parameters:
nbStrahlerthe Strahler number value to set.

Definition at line 426 of file Node.java.

                                              {
        this.nbStrahler = nbStrahler;
    }

Member Data Documentation

The children of the instance in the tree structure.

Definition at line 50 of file Node.java.

The depth of the node in the tree structure.

It corresponds in fact at the number of its ancestors. (so root.depth == 0)

Definition at line 66 of file Node.java.

The father of the instance in the tree structure.

Definition at line 45 of file Node.java.

The strahler number of the node.

Definition at line 60 of file Node.java.

The rank of the instance in the set of its father's children.

Definition at line 55 of file Node.java.


The documentation for this class was generated from the following file: