net.sourceforge.cilib.type.types.container
Class AbstractTree<E extends Cloneable & Comparable<? super E>>

java.lang.Object
  extended by net.sourceforge.cilib.type.types.container.AbstractTree<E>
Type Parameters:
E - The Cloneable type.
All Implemented Interfaces:
Serializable, Iterable<E>, StructuredType<E>, Tree<E>, Randomizable, Type, Cloneable
Direct Known Subclasses:
BinaryTree, GeneralTree, NaryTree

public abstract class AbstractTree<E extends Cloneable & Comparable<? super E>>
extends Object
implements Tree<E>

Base class for all Tree objects. Contains the methods common to all Tree objects.

See Also:
Serialized Form

Nested Class Summary
protected  class AbstractTree.TreeIterator
          Provides a simple Iterator for trees.
 
Field Summary
protected  E key
           
 
Constructor Summary
AbstractTree()
           
 
Method Summary
 void accept(Visitor<E> visitor)
          Accept the Visitor instance and perform the actions within the Visitor on the objects contained within this Structure.
 boolean addAll(StructuredType<? extends E> structure)
          Add add the objects of type E, within structureto the current Structure.
 void breadthFirstTraversal(Visitor<Tree<E>> visitor)
          Perform a breadth first traversal of the current Tree node, executing the operation stored within the provided Visitor instance.
 void depthFirstTraversal(PrePostVisitor<E> visitor)
          Perform a depth first traversal of the current Tree node, executing the operation stored within the provided Visitor instance.
abstract  boolean equals(Object obj)
          Compare the specified object with this type for equality.
abstract  AbstractTree<E> getClone()
          Create a cloned copy of the current object and return it.
 E getKey()
          Get the key value maintained by this Tree.
 String getRepresentation()
          
abstract  int hashCode()
          Returns the hash code value for this list.
 boolean isEmpty()
          Determine if the current Tree is empty.
 Iterator<E> iterator()
          
 void randomize(Random random)
          Apply a randomization using the provided Random.
 boolean removeAll(StructuredType<E> structure)
          Remove all instances contained within structure, if contained.
 void setKey(E element)
          Set the current key for the Tree.
 int size()
          Defines the size of the structure.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.cilib.type.types.container.Tree
addSubTree, getDegree, getSubTree, getSubTree, isLeaf, removeSubTree, removeSubTree
 
Methods inherited from interface net.sourceforge.cilib.type.types.container.StructuredType
add, clear, contains, remove, remove
 

Field Detail

key

protected E extends Cloneable & Comparable<? super E> key
Constructor Detail

AbstractTree

public AbstractTree()
Method Detail

getClone

public abstract AbstractTree<E> getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface StructuredType<E extends Cloneable & Comparable<? super E>>
Specified by:
getClone in interface Tree<E extends Cloneable & Comparable<? super E>>
Specified by:
getClone in interface Type
Specified by:
getClone in interface Cloneable
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

equals

public abstract boolean equals(Object obj)
Compare the specified object with this type for equality. Returns true if and only if the specified object is also an instance of the same type.

Specified by:
equals in interface Type
Overrides:
equals in class Object
Parameters:
obj - The object to compare.
Returns:
true if equality exists, false otherwise.
See Also:
Object.equals(Object)

hashCode

public abstract int hashCode()
Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:
  int hashCode = 7;
  Iterator<E> i = list.iterator();
  while (i.hasNext()) {
      E obj = i.next();
      hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
  }
 
This ensures that type1.equals(type2) implies that type1.hashCode()==type2.hashCode() for any two types, type1 and type2, as required by the general contract of Object.hashCode().

Specified by:
hashCode in interface Type
Overrides:
hashCode in class Object
Returns:
the hash code value for this list
See Also:
Object.equals(Object), Type.equals(Object)

breadthFirstTraversal

public void breadthFirstTraversal(Visitor<Tree<E>> visitor)
Perform a breadth first traversal of the current Tree node, executing the operation stored within the provided Visitor instance.

Specified by:
breadthFirstTraversal in interface Tree<E extends Cloneable & Comparable<? super E>>
Parameters:
visitor - The visitor operation to execute at each node.

depthFirstTraversal

public void depthFirstTraversal(PrePostVisitor<E> visitor)
Perform a depth first traversal of the current Tree node, executing the operation stored within the provided Visitor instance.

Specified by:
depthFirstTraversal in interface Tree<E extends Cloneable & Comparable<? super E>>
Parameters:
visitor - The visitor operation to execute at each node.

accept

public void accept(Visitor<E> visitor)
Accept the Visitor instance and perform the actions within the Visitor on the objects contained within this Structure.

Specified by:
accept in interface StructuredType<E extends Cloneable & Comparable<? super E>>
Parameters:
visitor - The Visitor instance to execute.

getKey

public E getKey()
Get the key value maintained by this Tree.

Specified by:
getKey in interface Tree<E extends Cloneable & Comparable<? super E>>
Returns:
The key of the current Tree.

setKey

public void setKey(E element)
Set the current key for the Tree.

Specified by:
setKey in interface Tree<E extends Cloneable & Comparable<? super E>>
Parameters:
element - The E to be used as the key.

isEmpty

public boolean isEmpty()
Determine if the current Tree is empty. A Tree is only defined to be empty if the key value is null. ie: getKey() == null.

Specified by:
isEmpty in interface StructuredType<E extends Cloneable & Comparable<? super E>>
Returns:
true if the Tree is empty, else false.

addAll

public boolean addAll(StructuredType<? extends E> structure)
Add add the objects of type E, within structureto the current Structure.

Specified by:
addAll in interface StructuredType<E extends Cloneable & Comparable<? super E>>
Parameters:
structure - The containing object of elements to add.
Returns:
true if successful, false otherwise.

removeAll

public boolean removeAll(StructuredType<E> structure)
Remove all instances contained within structure, if contained.

Specified by:
removeAll in interface StructuredType<E extends Cloneable & Comparable<? super E>>
Parameters:
structure - The listing of instances to be removed.
Returns:
true if successful, false otherwise.

iterator

public Iterator<E> iterator()

Specified by:
iterator in interface Iterable<E extends Cloneable & Comparable<? super E>>
Specified by:
iterator in interface StructuredType<E extends Cloneable & Comparable<? super E>>

size

public int size()
Defines the size of the structure. This could be the length of a vector (the vector dimensionality) or the number of elements within a tree.

Specified by:
size in interface StructuredType<E extends Cloneable & Comparable<? super E>>
Returns:
The size of the represented structure.

getRepresentation

public String getRepresentation()


randomize

public void randomize(Random random)
Description copied from interface: Randomizable
Apply a randomization using the provided Random.

Specified by:
randomize in interface Randomizable
Parameters:
random - The Random to use for the randomization.


Copyright © 2009 CIRG. All Rights Reserved.