Tree (JEvolution)
Date: 2013-03-21

evSOLve.JEvolution.gp

## Class Tree

- java.lang.Object
- - evSOLve.JEvolution.gp.Tree

- All Implemented Interfaces:
    java.lang.Cloneable, javax.swing.tree.TreeModel

      public class Tree
      extends java.lang.Object
      implements javax.swing.tree.TreeModel, java.lang.Cloneable

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected javax.swing.tree.MutableTreeNode` | `root` The root of this tree.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Tree(javax.swing.tree.MutableTreeNode root)` Constructs the tree by defining the root.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addTreeModelListener(javax.swing.event.TreeModelListener l)` Adds a tree mode listener.
    `Tree` | `clone()` A deep clone of this tree.
    `boolean` | `equals(java.lang.Object otherTree)` Checks this tree for equality with another tree.
    `void` | `exchangeNodes(javax.swing.tree.MutableTreeNode own, javax.swing.tree.MutableTreeNode other, Tree otherTree)` Exchanges the subtree at node 'own' from this tree with another subtree given by 'other'.
    `javax.swing.tree.TreeNode` | `getChild(java.lang.Object parent, int index)` Returns the child of a parent node at the given index.
    `int` | `getChildCount(java.lang.Object parent)` Returns the number of children of the parent.
    `int` | `getIndexOfChild(java.lang.Object parent, java.lang.Object child)` Returns the index of a parent's child.
    `java.lang.Object` | `getRoot()` Returns the root node.
    `int` | `hashCode()` Returns a hash code for the tree by using the nodes' hashCode().
    `boolean` | `isLeaf(java.lang.Object node)` Returns if the given node is a leaf node.
    `TreeIterator` | `iterator()` Returns a tree iterator for this tree.
    `void` | `removeTreeModelListener(javax.swing.event.TreeModelListener l)` Removes a tree mode listener.
    `void` | `replaceNode(javax.swing.tree.MutableTreeNode own, javax.swing.tree.MutableTreeNode other)` Replaces the subtree at node 'own' from this tree with another subtree given by 'other'.
    `void` | `setRoot(javax.swing.tree.MutableTreeNode node)` Sets the root node.
    `int` | `size()` Returns the number of nodes in this tree.
    `java.lang.String` | `toString()` Returns the string representation of this tree in Polish notation.
    `void` | `valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)` Receives notification of a node change.

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### root

          protected javax.swing.tree.MutableTreeNode root

      The root of this tree.

  - ### Constructor Detail

    - #### Tree

          public Tree(javax.swing.tree.MutableTreeNode root)

      Constructs the tree by defining the root.
      Parameters:
        `root` - the root node

  - ### Method Detail

    - #### clone

          public Tree clone()

      A deep clone of this tree.
      Overrides:
        `clone` in class `java.lang.Object`
      Returns:
        a deep clone

    - #### equals

          public boolean equals(java.lang.Object otherTree)

      Checks this tree for equality with another tree. The trees are equal, if they have the same number of nodes, the same structure, and the same nodes.
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `otherTree` - another tree
      Returns:
        true, if the trees are equal (according to above definition)

    - #### hashCode

          public int hashCode()

      Returns a hash code for the tree by using the nodes' hashCode(). Additionally, the hash code of the nodes is multiplied by their iteration number in order to make a hash code for a tree more unique using (some) structural information.
      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        a hash code

    - #### getRoot

          public java.lang.Object getRoot()

      Returns the root node.
      Specified by:
        `getRoot` in interface `javax.swing.tree.TreeModel`
      Returns:
        the root node

    - #### setRoot

          public void setRoot(javax.swing.tree.MutableTreeNode node)

      Sets the root node.
      Parameters:
        `node` - a tree node

    - #### getChild

          public javax.swing.tree.TreeNode getChild(java.lang.Object parent,
                                           int index)

      Returns the child of a parent node at the given index.
      Specified by:
        `getChild` in interface `javax.swing.tree.TreeModel`
      Parameters:
        `parent` - a parent node
        `index` - the index of the child
      Returns:
        the child node

    - #### getChildCount

          public int getChildCount(java.lang.Object parent)

      Returns the number of children of the parent.
      Specified by:
        `getChildCount` in interface `javax.swing.tree.TreeModel`
      Parameters:
        `parent` - a parent node
      Returns:
        the number of children

    - #### getIndexOfChild

          public int getIndexOfChild(java.lang.Object parent,
                            java.lang.Object child)

      Returns the index of a parent's child.
      Specified by:
        `getIndexOfChild` in interface `javax.swing.tree.TreeModel`
      Parameters:
        `parent` - a parent node
        `child` - a child node of the parent
      Returns:
        the index, -1, if not found

    - #### isLeaf

          public boolean isLeaf(java.lang.Object node)

      Returns if the given node is a leaf node. In the program tree context, a leaf must always be a terminal, so we know all the time that a terminal is a leaf node and a function node is not.
      Specified by:
        `isLeaf` in interface `javax.swing.tree.TreeModel`
      Parameters:
        `node` - a tree node
      Returns:
        true, if leaf

    - #### valueForPathChanged

          public void valueForPathChanged(javax.swing.tree.TreePath path,
                                 java.lang.Object newValue)

      Receives notification of a node change. As our nodes do not change, this method is empty. This method is used by JTree to message a change made by a user.
      Specified by:
        `valueForPathChanged` in interface `javax.swing.tree.TreeModel`
      Parameters:
        `path` - a tree path to the changed node
        `newValue` - the new value for the changed node

    - #### addTreeModelListener

          public void addTreeModelListener(javax.swing.event.TreeModelListener l)

      Adds a tree mode listener. Empty implementation.
      Specified by:
        `addTreeModelListener` in interface `javax.swing.tree.TreeModel`
      Parameters:
        `l` - a tree model listener

    - #### removeTreeModelListener

          public void removeTreeModelListener(javax.swing.event.TreeModelListener l)

      Removes a tree mode listener. Empty implementation.
      Specified by:
        `removeTreeModelListener` in interface `javax.swing.tree.TreeModel`
      Parameters:
        `l` - a tree model listener

    - #### iterator

          public TreeIterator iterator()

      Returns a tree iterator for this tree.
      Returns:
        a tree iterator iterating over the TreeNodes of this tree in depth first mode

    - #### size

          public int size()

      Returns the number of nodes in this tree.
      Returns:
        the tree size

    - #### replaceNode

          public void replaceNode(javax.swing.tree.MutableTreeNode own,
                         javax.swing.tree.MutableTreeNode other)

      Replaces the subtree at node 'own' from this tree with another subtree given by 'other'. It is not checked, if 'own' is in this tree, and 'other' is not, but it is assumed.
      Parameters:
        `own` - a node in this tree to be replaced, may be root
        `other` - a node from another tree to replace 'own', may be root

    - #### exchangeNodes

          public void exchangeNodes(javax.swing.tree.MutableTreeNode own,
                           javax.swing.tree.MutableTreeNode other,
                           Tree otherTree)

      Exchanges the subtree at node 'own' from this tree with another subtree given by 'other'. It is not checked, if 'own' is in this tree, and if 'other' is really in 'otherTree', but it is assumed.
      Parameters:
        `own` - a node in this tree to be exchanged, may be root
        `other` - a node from another tree to be exchanged, may be root
        `otherTree` - the other tree

    - #### toString

          public java.lang.String toString()

      Returns the string representation of this tree in Polish notation.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the tree in Polish (prefix) notation