Coinjema
1.7

org.coinjema.collections
Class ListedHashTree<T>

java.lang.Object
  extended by org.coinjema.collections.HashTree<T>
      extended by org.coinjema.collections.ListedHashTree<T>
All Implemented Interfaces:
Serializable, Cloneable, Map<T,HashTree<T>>

public class ListedHashTree<T>
extends HashTree<T>
implements Serializable, Cloneable

ListedHashTree is a different implementation of the HashTree collection class. In the ListedHashTree, the order in which values are added is preserved (not to be confused with SortedHashTree, which sorts the order of the values using the compare() function). Any listing of nodes or iteration through the list of nodes of a ListedHashTree will be given in the order in which the nodes were added to the tree.

Version:
$Revision: 1.2 $
Author:
mstover1 at apache.org
See Also:
HashTree, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.coinjema.collections.HashTree
data
 
Constructor Summary
ListedHashTree()
           
ListedHashTree(Collection<? extends T> keys)
           
ListedHashTree(T key)
           
ListedHashTree(T[] keys)
           
 
Method Summary
 HashTree<T> add(T key)
          Adds an key into the HashTree at the current level.
 void clear()
          Clears the HashTree of all contents.
 HashTree<T> clone()
          Create a clone of this HashTree.
 HashTree<T> createNewTree()
          Creates a new tree.
 HashTree<T> createNewTree(Collection<? extends T> values)
          Creates a new tree.
 HashTree<T> createNewTree(T key)
          Creates a new tree.
 boolean equals(Object o)
          Compares all objects in the tree and verifies that the two trees contain the same objects at the same tree levels.
 int hashCode()
          Returns a hashcode for this HashTree.
 Collection<T> list()
          Gets a Collection of all keys in the current HashTree node.
 HashTree<T> remove(Object key)
          Removes the entire branch specified by the given key.
 void replace(Object currentKey, T newKey)
          Finds the given current key, and replaces it with the given new key.
 void set(HashTree<T> t)
           
 void set(T key, Collection<? extends T> values)
          Sets a key and its values in the HashTree.
 void set(T key, HashTree<T> t)
          Sets a key into the current tree and assigns it a HashTree as its subtree.
 void set(T key, T value)
          Sets a key and it's value in the HashTree.
 void set(T key, T[] values)
          Sets a key and it's values in the HashTree.
 int size()
          Returns the number of top-level entries in the HashTree.
 
Methods inherited from class org.coinjema.collections.HashTree
add, add, add, add, add, add, add, add, add, add, add, add, add, add, addTreePath, cloneTree, containsKey, containsValue, entrySet, get, getObject, getObject, getObject, getObject, getTree, getTree, getTree, getTreePath, isEmpty, keySet, list, list, list, put, putAll, remove, search, set, set, set, set, set, set, set, toString, traverse, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListedHashTree

public ListedHashTree()

ListedHashTree

public ListedHashTree(T key)

ListedHashTree

public ListedHashTree(Collection<? extends T> keys)

ListedHashTree

public ListedHashTree(T[] keys)
Method Detail

clone

public HashTree<T> clone()
Description copied from class: HashTree
Create a clone of this HashTree. This is not a deep clone (ie, the contents of the tree are not cloned).

Overrides:
clone in class HashTree<T>
See Also:
Object.clone()

set

public void set(T key,
                T value)
Description copied from class: HashTree
Sets a key and it's value in the HashTree. It actually sets up a key, and then creates a node for the key and sets the value to the new node, as a key. Any previous nodes that existed under the given key are lost.

Overrides:
set in class HashTree<T>
Parameters:
key - key to be set up
value - value to be set up as a key in the secondary node

set

public void set(T key,
                HashTree<T> t)
Description copied from class: HashTree
Sets a key into the current tree and assigns it a HashTree as its subtree. Any previous entries under the given key are removed.

Overrides:
set in class HashTree<T>
Parameters:
key - key to be set up
t - HashTree that the key maps to

set

public void set(T key,
                T[] values)
Description copied from class: HashTree
Sets a key and it's values in the HashTree. It sets up a key in the current node, and then creates a node for that key, and sets all the values in the array as keys in the new node. Any keys previously held under the given key are lost.

Overrides:
set in class HashTree<T>
Parameters:
key - Key to be set up
values - Array of objects to be added as keys in the secondary node

set

public void set(T key,
                Collection<? extends T> values)
Description copied from class: HashTree
Sets a key and its values in the HashTree. It sets up a key in the current node, and then creates a node for that key, and set all the values in the array as keys in the new node. Any keys previously held under the given key are removed.

Overrides:
set in class HashTree<T>
Parameters:
key - key to be set up
values - Collection of objects to be added as keys in the secondary node

replace

public void replace(Object currentKey,
                    T newKey)
Description copied from class: HashTree
Finds the given current key, and replaces it with the given new key. Any tree structure found under the original key is moved to the new key.

Overrides:
replace in class HashTree<T>

createNewTree

public HashTree<T> createNewTree()
Description copied from class: HashTree
Creates a new tree. This method exists to allow inheriting classes to generate the appropriate types of nodes. For instance, when a node is added, it's value is a HashTree. Rather than directly calling the HashTree() constructor, the createNewTree() method is called. Inheriting classes should override these methods and create the appropriate subclass of HashTree.

Overrides:
createNewTree in class HashTree<T>
Returns:
HashTree

createNewTree

public HashTree<T> createNewTree(T key)
Description copied from class: HashTree
Creates a new tree. This method exists to allow inheriting classes to generate the appropriate types of nodes. For instance, when a node is added, it's value is a HashTree. Rather than directly calling the HashTree() constructor, the createNewTree() method is called. Inheriting classes should override these methods and create the appropriate subclass of HashTree.

Overrides:
createNewTree in class HashTree<T>
Returns:
HashTree

createNewTree

public HashTree<T> createNewTree(Collection<? extends T> values)
Description copied from class: HashTree
Creates a new tree. This method exists to allow inheriting classes to generate the appropriate types of nodes. For instance, when a node is added, it's value is a HashTree. Rather than directly calling the HashTree() constructor, the createNewTree() method is called. Inheriting classes should override these methods and create the appropriate subclass of HashTree.

Overrides:
createNewTree in class HashTree<T>
Returns:
HashTree

add

public HashTree<T> add(T key)
Description copied from class: HashTree
Adds an key into the HashTree at the current level.

Overrides:
add in class HashTree<T>
Parameters:
key - key to be added to HashTree

list

public Collection<T> list()
Description copied from class: HashTree
Gets a Collection of all keys in the current HashTree node. If the HashTree represented a file system, this would be like getting a collection of all the files in the current folder.

Overrides:
list in class HashTree<T>
Returns:
Set of all keys in this HashTree

remove

public HashTree<T> remove(Object key)
Description copied from class: HashTree
Removes the entire branch specified by the given key.

Specified by:
remove in interface Map<T,HashTree<T>>
Overrides:
remove in class HashTree<T>
See Also:
Map.remove(Object)

hashCode

public int hashCode()
Description copied from class: HashTree
Returns a hashcode for this HashTree.

Specified by:
hashCode in interface Map<T,HashTree<T>>
Overrides:
hashCode in class HashTree<T>
See Also:
Object.hashCode()

equals

public boolean equals(Object o)
Description copied from class: HashTree
Compares all objects in the tree and verifies that the two trees contain the same objects at the same tree levels. Returns true if they do, false otherwise.

Specified by:
equals in interface Map<T,HashTree<T>>
Overrides:
equals in class HashTree<T>
Parameters:
o - Object to be compared against
See Also:
Object.equals(Object)

size

public int size()
Description copied from class: HashTree
Returns the number of top-level entries in the HashTree.

Specified by:
size in interface Map<T,HashTree<T>>
Overrides:
size in class HashTree<T>
See Also:
Map.size()

clear

public void clear()
Description copied from class: HashTree
Clears the HashTree of all contents.

Specified by:
clear in interface Map<T,HashTree<T>>
Overrides:
clear in class HashTree<T>
See Also:
Map.clear()

set

public void set(HashTree<T> t)
Overrides:
set in class HashTree<T>

Coinjema
1.7

Public Domain Software.