|
Coinjema 1.7 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.coinjema.collections.HashTree<T>
public class HashTree<T>
This class is used to create a tree structure of objects. Each element in the tree is also a key to the next node down in the tree. It provides many ways to add objects and branches, as well as many ways to retrieve.
HashTree implements the Map interface for convenience reasons. The main difference between a Map and a HashTree is that the HashTree organizes the data into a recursive tree structure, and provides the means to manipulate that structure.
Of special interest is the traverse(HashTreeTraverser)
method,
which provides an expedient way to traverse any HashTree by implementing the
HashTreeTraverser
interface in order to perform some operation on
the tree, or to extract information from the tree.
HashTreeTraverser
,
SearchByClass
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
protected Map<T,HashTree<T>> |
data
|
Constructor Summary | |
---|---|
HashTree()
Creates an empty new HashTree. |
|
HashTree(Collection<? extends T> keys)
Creates a new HashTree and adds all the objects in the given collection as top-level nodes in the tree. |
|
HashTree(T key)
Creates a new HashTree and adds the given object as a top-level node. |
|
HashTree(T[] keys)
Creates a new HashTree and adds all the objects in the given array as top-level nodes in the tree. |
Method Summary | |
---|---|
void |
add(Collection<? extends T> keys)
Adds a bunch of keys into the HashTree at the current level. |
void |
add(Collection<? extends T> treePath,
Collection<? extends T> values)
Adds a series of nodes into the HashTree using the given path. |
HashTree<T> |
add(Collection<? extends T> treePath,
T value)
Adds a series of nodes into the HashTree using the given path. |
void |
add(Collection<? extends T> treePath,
T[] values)
Adds a series of nodes into the HashTree using the given path. |
void |
add(HashTree<? extends T> newTree)
Adds all the nodes and branches of the given tree to this tree. |
HashTree<T> |
add(T key)
Adds an key into the HashTree at the current level. |
void |
add(T[] keys)
Adds all the given objects as nodes at the current level. |
void |
add(T[] treePath,
Collection<? extends T> values)
Adds a series of nodes into the HashTree using the given path. |
void |
add(T[] treePath,
HashTree<? extends T> subTree)
|
HashTree<T> |
add(T[] treePath,
T value)
|
void |
add(T[] treePath,
T[] values)
Adds a series of nodes into the HashTree using the given path. |
void |
add(T key,
Collection<? extends T> values)
Adds a key as a node at the current level and then adds all the objects in the second argument as nodes of the new node. |
void |
add(T key,
HashTree<? extends T> subTree)
Adds a key as a node at the current level and then adds the given HashTree to that new node. |
HashTree<T> |
add(T key,
T value)
Adds a key and it's value in the HashTree. |
void |
add(T key,
T[] values)
Adds a key and it's values in the HashTree. |
protected HashTree<T> |
addTreePath(Collection<? extends T> treePath)
|
void |
clear()
Clears the HashTree of all contents. |
HashTree<T> |
clone()
Create a clone of this HashTree. |
protected void |
cloneTree(HashTree<T> newTree)
|
boolean |
containsKey(Object o)
If the HashTree contains the given object as a key at the top level, then a true result is returned, otherwise false. |
boolean |
containsValue(Object value)
Implemented as required by the Map interface, but is not very useful here. |
protected HashTree<T> |
createNewTree()
Creates a new tree. |
protected HashTree<T> |
createNewTree(Collection<? extends T> values)
Creates a new tree. |
protected HashTree<T> |
createNewTree(T key)
Creates a new tree. |
Set<Map.Entry<T,HashTree<T>>> |
entrySet()
|
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. |
HashTree<T> |
get(Object key)
|
T |
getObject()
|
T |
getObject(Collection<?> keys)
|
T |
getObject(T... keys)
|
T |
getObject(T key)
Returns the first object of the tree associated with the given key. |
HashTree<T> |
getTree(Collection<?> treePath)
Gets the HashTree object mapped to the last key in the SortedSet by recursing through the HashTree structure one key at a time. |
HashTree<T> |
getTree(Object key)
Gets the HashTree mapped to the given key. |
HashTree<T> |
getTree(Object[] treePath)
Gets the HashTree object mapped to the last key in the array by recursing through the HashTree structure one key at a time. |
protected HashTree<T> |
getTreePath(Collection<?> treePath)
|
int |
hashCode()
Returns a hashcode for this HashTree. |
boolean |
isEmpty()
If the HashTree is empty, true is returned, false otherwise. |
Set<T> |
keySet()
|
Collection<T> |
list()
Gets a Collection of all keys in the current HashTree node. |
Collection<T> |
list(Collection<?> treePath)
Recurses down into the HashTree stucture using each subsequent key in the List of keys, and returns the Set of keys of the HashTree object at the end of the recursion. |
Collection<T> |
list(Object key)
Gets a Set of all keys in the HashTree mapped to the given key of the current HashTree object (in other words, one level down. |
Collection<T> |
list(Object[] treePath)
Recurses down into the HashTree stucture using each subsequent key in the array of keys, and returns the Set of keys of the HashTree object at the end of the recursion. |
HashTree<T> |
put(T key,
HashTree<T> val)
|
void |
putAll(Map<? extends T,? extends HashTree<T>> input)
|
HashTree<T> |
remove(Object key)
Removes the entire branch specified by the given key. |
HashTree<T> |
remove(Object[] path)
|
void |
replace(Object currentKey,
T newKey)
Finds the given current key, and replaces it with the given new key. |
HashTree<T> |
search(Object key)
Searches the HashTree structure for the given key. |
void |
set(Collection<? extends T> values)
Sets the nodes of the current tree to be the objects of the given collection. |
void |
set(Collection<? extends T> treePath,
Collection<? extends T> values)
Sets a series of keys into the HashTree. |
void |
set(Collection<? extends T> treePath,
HashTree<T> t)
|
void |
set(Collection<? extends T> treePath,
T[] values)
Sets a series of keys into the HashTree. |
void |
set(HashTree<T> t)
|
void |
set(T[] treePath,
Collection<? extends T> values)
Sets a series of keys into the HashTree. |
void |
set(T[] path,
HashTree<T> t)
|
void |
set(T[] treePath,
T[] values)
Sets a series of keys into the HashTree. |
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. |
String |
toString()
|
void |
traverse(HashTreeTraverser<T> visitor)
Allows any implementation of the HashTreeTraverser interface to easily traverse (depth-first) all the nodes of the HashTree. |
Collection<HashTree<T>> |
values()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Map<T,HashTree<T>> data
Constructor Detail |
---|
public HashTree()
public HashTree(T key)
key
- public HashTree(Collection<? extends T> keys)
keys
- a collection of objects to be added to the created HashTree.public HashTree(T[] keys)
Method Detail |
---|
public boolean containsValue(Object value)
containsValue
in interface Map<T,HashTree<T>>
value
- Object to be tested as a value.
Map.containsValue(Object)
public void clear()
clear
in interface Map<T,HashTree<T>>
Map.clear()
public void add(T key, HashTree<? extends T> subTree)
key
- key to create in this treesubTree
- sub tree to add to the node created for the first
argument.public void add(HashTree<? extends T> newTree)
newTree
- public boolean containsKey(Object o)
containsKey
in interface Map<T,HashTree<T>>
o
- Object to be tested as a key.
Map.containsKey(Object)
public boolean isEmpty()
isEmpty
in interface Map<T,HashTree<T>>
public void set(T key, T value)
key
- key to be set upvalue
- value to be set up as a key in the secondary nodepublic void set(T key, HashTree<T> t)
key
- key to be set upt
- HashTree that the key maps topublic void set(T[] path, HashTree<T> t)
public void set(T key, T[] values)
key
- Key to be set upvalues
- Array of objects to be added as keys in the secondary nodepublic void set(T key, Collection<? extends T> values)
key
- key to be set upvalues
- Collection of objects to be added as keys in the secondary
nodepublic void set(T[] treePath, T[] values)
treePath
- array of keys to put into HashTreevalues
- array of values to be added as keys to bottom-most nodepublic void set(T[] treePath, Collection<? extends T> values)
treePath
- array of keys to put into HashTreevalues
- Collection of values to be added as keys to bottom-most
nodepublic void set(Collection<? extends T> treePath, T[] values)
treePath
- collection of keys to put into HashTreevalues
- array of values to be added as keys to bottom-most nodepublic void set(Collection<? extends T> values)
values
- Collection of objects to set as nodes.public void set(Collection<? extends T> treePath, Collection<? extends T> values)
treePath
- list of keys to put into HashTreevalues
- collection of values to be added as keys to bottom-most
nodepublic void set(Collection<? extends T> treePath, HashTree<T> t)
public void set(HashTree<T> t)
public HashTree<T> add(T key)
key
- key to be added to HashTreepublic void add(T[] keys)
keys
- Array of Keys to be added to HashTree.public void add(Collection<? extends T> keys)
keys
- Collection of Keys to be added to HashTree.public HashTree<T> add(T key, T value)
key
- key to be addedvalue
- value to be added as a key in the secondary nodepublic void add(T key, T[] values)
key
- key to be addedvalues
- array of objects to be added as keys in the secondary nodepublic void add(T key, Collection<? extends T> values)
key
- key to be addedvalues
- Collection of objects to be added as keys in the secondary
nodepublic void add(T[] treePath, T[] values)
treePath
- an array of objects representing a pathvalues
- array of values to be added as keys to bottom-most nodepublic void add(T[] treePath, Collection<? extends T> values)
treePath
- an array of objects representing a pathvalues
- collection of values to be added as keys to bottom-most
nodepublic HashTree<T> add(T[] treePath, T value)
public void add(Collection<? extends T> treePath, T[] values)
treePath
- a list of objects representing a pathvalues
- array of values to be added as keys to bottom-most nodepublic HashTree<T> add(Collection<? extends T> treePath, T value)
treePath
- a list of objects representing a pathvalue
- Object to add as a node to bottom-most nodepublic void add(T[] treePath, HashTree<? extends T> subTree)
public void add(Collection<? extends T> treePath, Collection<? extends T> values)
treePath
- a SortedSet of objects representing a pathvalues
- Collection of values to be added as keys to bottom-most
nodeprotected HashTree<T> addTreePath(Collection<? extends T> treePath)
public HashTree<T> getTree(Object key)
key
- Key used to find appropriate HashTree()public T getObject(T key)
key
-
public T getObject()
public T getObject(T... keys)
public T getObject(Collection<?> keys)
public HashTree<T> getTree(Object[] treePath)
treePath
- array of keys.
public HashTree<T> clone()
clone
in class Object
Object.clone()
protected void cloneTree(HashTree<T> newTree)
protected HashTree<T> createNewTree()
protected HashTree<T> createNewTree(T key)
protected HashTree<T> createNewTree(Collection<? extends T> values)
public HashTree<T> getTree(Collection<?> treePath)
treePath
- Collection of keys
public Collection<T> list()
public Collection<T> list(Object key)
key
- key used to find HashTree to get list of
public HashTree<T> remove(Object key)
remove
in interface Map<T,HashTree<T>>
Map.remove(Object)
public HashTree<T> remove(Object[] path)
public Collection<T> list(Object[] treePath)
treePath
- Array of keys used to recurse into HashTree structure
public Collection<T> list(Collection<?> treePath)
treePath
- List of keys used to recurse into HashTree structure
public void replace(Object currentKey, T newKey)
protected HashTree<T> getTreePath(Collection<?> treePath)
public int hashCode()
hashCode
in interface Map<T,HashTree<T>>
hashCode
in class Object
Object.hashCode()
public boolean equals(Object o)
equals
in interface Map<T,HashTree<T>>
equals
in class Object
o
- Object to be compared againstObject.equals(Object)
public HashTree<T> search(Object key)
key
- Key to search for
null
public int size()
size
in interface Map<T,HashTree<T>>
Map.size()
public void traverse(HashTreeTraverser<T> visitor)
HashTreeTraverser
public String toString()
toString
in class Object
public HashTree<T> get(Object key)
get
in interface Map<T,HashTree<T>>
public HashTree<T> put(T key, HashTree<T> val)
put
in interface Map<T,HashTree<T>>
public Set<Map.Entry<T,HashTree<T>>> entrySet()
entrySet
in interface Map<T,HashTree<T>>
public Set<T> keySet()
keySet
in interface Map<T,HashTree<T>>
public Collection<HashTree<T>> values()
values
in interface Map<T,HashTree<T>>
public void putAll(Map<? extends T,? extends HashTree<T>> input)
putAll
in interface Map<T,HashTree<T>>
|
Coinjema 1.7 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |