public class HashTree extends java.lang.Object implements java.io.Serializable, java.util.Map<java.lang.Object,HashTree>, java.lang.Cloneable
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 FormModifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.Object,HashTree> |
data |
Modifier | Constructor and Description |
---|---|
|
HashTree()
Creates an empty new HashTree.
|
|
HashTree(java.util.Collection<?> keys)
Creates a new HashTree and adds all the objects in the given collection
as top-level nodes in the tree.
|
protected |
HashTree(java.util.Map<java.lang.Object,HashTree> _map)
Allow subclasses to provide their own Map.
|
|
HashTree(java.lang.Object key)
Creates a new HashTree and adds the given object as a top-level node.
|
|
HashTree(java.lang.Object[] keys)
Creates a new HashTree and adds all the objects in the given array as
top-level nodes in the tree.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.util.Collection<?> keys)
Adds a bunch of keys into the HashTree at the current level.
|
void |
add(java.util.Collection<?> treePath,
java.util.Collection<?> values)
Adds a series of nodes into the HashTree using the given path.
|
HashTree |
add(java.util.Collection<?> treePath,
java.lang.Object value)
Adds a series of nodes into the HashTree using the given path.
|
void |
add(java.util.Collection<?> treePath,
java.lang.Object[] values)
Adds a series of nodes into the HashTree using the given path.
|
void |
add(HashTree newTree)
Adds all the nodes and branches of the given tree to this tree.
|
HashTree |
add(java.lang.Object key)
Adds an key into the HashTree at the current level.
|
void |
add(java.lang.Object[] keys)
Adds all the given objects as nodes at the current level.
|
void |
add(java.lang.Object[] treePath,
java.util.Collection<?> values)
Adds a series of nodes into the HashTree using the given path.
|
HashTree |
add(java.lang.Object[] treePath,
java.lang.Object value) |
void |
add(java.lang.Object[] treePath,
java.lang.Object[] values)
Adds a series of nodes into the HashTree using the given path.
|
void |
add(java.lang.Object key,
java.util.Collection<?> 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(java.lang.Object key,
HashTree subTree)
Adds a key as a node at the current level and then adds the given
HashTree to that new node.
|
HashTree |
add(java.lang.Object key,
java.lang.Object value)
Adds a key and it's value in the HashTree.
|
void |
add(java.lang.Object key,
java.lang.Object[] values)
Adds a key and it's values in the HashTree.
|
protected HashTree |
addTreePath(java.util.Collection<?> treePath) |
void |
clear()
Clears the HashTree of all contents.
|
java.lang.Object |
clone()
Create a clone of this HashTree.
|
protected void |
cloneTree(HashTree newTree) |
boolean |
containsKey(java.lang.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(java.lang.Object value)
Implemented as required by the Map interface, but is not very useful
here.
|
protected HashTree |
createNewTree()
Creates a new tree.
|
protected HashTree |
createNewTree(java.util.Collection<?> values)
Creates a new tree.
|
protected HashTree |
createNewTree(java.lang.Object key)
Creates a new tree.
|
java.util.Set<java.util.Map.Entry<java.lang.Object,HashTree>> |
entrySet()
Exists to satisfy the Map interface.
|
boolean |
equals(java.lang.Object o)
Compares all objects in the tree and verifies that the two trees contain
the same objects at the same tree levels.
|
HashTree |
get(java.lang.Object key)
Returns the HashTree object associated with the given key.
|
java.lang.Object[] |
getArray()
Gets an array of all keys in the current HashTree node.
|
java.lang.Object[] |
getArray(java.util.Collection<?> treePath)
Recurses down into the HashTree structure using each subsequent key in the
treePath argument, and returns an array of keys of the HashTree object at
the end of the recursion.
|
java.lang.Object[] |
getArray(java.lang.Object key)
Gets an array of all keys in the HashTree mapped to the given key of the
current HashTree object (in other words, one level down).
|
java.lang.Object[] |
getArray(java.lang.Object[] treePath)
Recurses down into the HashTree stucture using each subsequent key in the
array of keys, and returns an array of keys of the HashTree object at the
end of the recursion.
|
HashTree |
getTree(java.util.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 |
getTree(java.lang.Object key)
Gets the HashTree mapped to the given key.
|
HashTree |
getTree(java.lang.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 |
getTreePath(java.util.Collection<?> treePath) |
int |
hashCode()
Returns a hashcode for this HashTree.
|
boolean |
isEmpty()
If the HashTree is empty, true is returned, false otherwise.
|
java.util.Set<java.lang.Object> |
keySet()
Returns a Set of all the keys in the top-level of this HashTree.
|
java.util.Collection<java.lang.Object> |
list()
Gets a Collection of all keys in the current HashTree node.
|
java.util.Collection<?> |
list(java.util.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.
|
java.util.Collection<?> |
list(java.lang.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.
|
java.util.Collection<?> |
list(java.lang.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 |
put(java.lang.Object key,
HashTree value)
This is the same as calling HashTree.add(key,value).
|
void |
putAll(java.util.Map<?,? extends HashTree> map)
The Map given must also be a HashTree, otherwise an
UnsupportedOperationException is thrown.
|
HashTree |
remove(java.lang.Object key)
Removes the entire branch specified by the given key.
|
void |
replaceKey(java.lang.Object currentKey,
java.lang.Object newKey)
Finds the given current key, and replaces it with the given new key.
|
HashTree |
search(java.lang.Object key)
Searches the HashTree structure for the given key.
|
void |
set(java.util.Collection<?> values)
Sets the nodes of the current tree to be the objects of the given
collection.
|
void |
set(java.util.Collection<?> treePath,
java.util.Collection<?> values)
Sets a series of keys into the HashTree.
|
void |
set(java.util.Collection<?> treePath,
java.lang.Object[] values)
Sets a series of keys into the HashTree.
|
void |
set(java.lang.Object[] treePath,
java.util.Collection<?> values)
Sets a series of keys into the HashTree.
|
void |
set(java.lang.Object[] treePath,
java.lang.Object[] values)
Sets a series of keys into the HashTree.
|
void |
set(java.lang.Object key,
java.util.Collection<?> values)
Sets a key and its values in the HashTree.
|
void |
set(java.lang.Object key,
HashTree t)
Sets a key into the current tree and assigns it a HashTree as its
subtree.
|
void |
set(java.lang.Object key,
java.lang.Object value)
Sets a key and it's value in the HashTree.
|
void |
set(java.lang.Object key,
java.lang.Object[] values)
Sets a key and its values in the HashTree.
|
int |
size()
Returns the number of top-level entries in the HashTree.
|
java.lang.String |
toString()
Generate a printable representation of the tree.
|
void |
traverse(HashTreeTraverser visitor)
Allows any implementation of the HashTreeTraverser interface to easily
traverse (depth-first) all the nodes of the HashTree.
|
java.util.Collection<HashTree> |
values()
Returns a collection of all the sub-trees of the current tree.
|
protected final java.util.Map<java.lang.Object,HashTree> data
public HashTree()
protected HashTree(java.util.Map<java.lang.Object,HashTree> _map)
_map
- Map
to usepublic HashTree(java.lang.Object key)
key
- name of the new top-level nodepublic HashTree(java.util.Collection<?> keys)
keys
- a collection of objects to be added to the created HashTree.public HashTree(java.lang.Object[] keys)
keys
- array with names for the new top-level nodespublic void putAll(java.util.Map<?,? extends HashTree> map)
putAll
in interface java.util.Map<java.lang.Object,HashTree>
add(HashTree)
,
Map.putAll(Map)
public java.util.Set<java.util.Map.Entry<java.lang.Object,HashTree>> entrySet()
entrySet
in interface java.util.Map<java.lang.Object,HashTree>
Map.entrySet()
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<java.lang.Object,HashTree>
value
- Object to be tested as a value.Map.containsValue(Object)
public HashTree put(java.lang.Object key, HashTree value)
put
in interface java.util.Map<java.lang.Object,HashTree>
key
- to usevalue
- to store against keyMap.put(Object, Object)
public void clear()
clear
in interface java.util.Map<java.lang.Object,HashTree>
Map.clear()
public java.util.Collection<HashTree> values()
values
in interface java.util.Map<java.lang.Object,HashTree>
Map.values()
public void add(java.lang.Object key, HashTree subTree)
key
- key to create in this treesubTree
- sub tree to add to the node created for the first argument.public void add(HashTree newTree)
newTree
- the tree to be addedpublic boolean containsKey(java.lang.Object o)
containsKey
in interface java.util.Map<java.lang.Object,HashTree>
o
- Object to be tested as a key.Map.containsKey(Object)
public boolean isEmpty()
isEmpty
in interface java.util.Map<java.lang.Object,HashTree>
public void set(java.lang.Object key, java.lang.Object value)
key
- key to be set upvalue
- value to be set up as a key in the secondary nodepublic void set(java.lang.Object key, HashTree t)
key
- key to be set upt
- HashTree that the key maps topublic void set(java.lang.Object key, java.lang.Object[] values)
key
- Key to be set upvalues
- Array of objects to be added as keys in the secondary nodepublic void set(java.lang.Object key, java.util.Collection<?> values)
key
- key to be set upvalues
- Collection of objects to be added as keys in the secondary
nodepublic void set(java.lang.Object[] treePath, java.lang.Object[] values)
treePath
- array of keys to put into HashTreevalues
- array of values to be added as keys to bottom-most nodepublic void set(java.lang.Object[] treePath, java.util.Collection<?> values)
treePath
- array of keys to put into HashTreevalues
- Collection of values to be added as keys to bottom-most nodepublic void set(java.util.Collection<?> treePath, java.lang.Object[] values)
treePath
- collection of keys to put into HashTreevalues
- array of values to be added as keys to bottom-most nodepublic void set(java.util.Collection<?> values)
values
- Collection of objects to set as nodes.public void set(java.util.Collection<?> treePath, java.util.Collection<?> values)
treePath
- list of keys to put into HashTreevalues
- collection of values to be added as keys to bottom-most nodepublic HashTree add(java.lang.Object key)
key
- key to be added to HashTreepublic void add(java.lang.Object[] keys)
keys
- Array of Keys to be added to HashTree.public void add(java.util.Collection<?> keys)
keys
- Collection of Keys to be added to HashTree.public HashTree add(java.lang.Object key, java.lang.Object value)
key
- key to be addedvalue
- value to be added as a key in the secondary nodevalue
is the keypublic void add(java.lang.Object key, java.lang.Object[] values)
key
- key to be addedvalues
- array of objects to be added as keys in the secondary nodepublic void add(java.lang.Object key, java.util.Collection<?> values)
key
- key to be addedvalues
- Collection of objects to be added as keys in the secondary
nodepublic void add(java.lang.Object[] treePath, java.lang.Object[] values)
treePath
- an array of objects representing a pathvalues
- array of values to be added as keys to bottom-most nodepublic void add(java.lang.Object[] treePath, java.util.Collection<?> values)
treePath
- an array of objects representing a pathvalues
- collection of values to be added as keys to bottom-most nodepublic HashTree add(java.lang.Object[] treePath, java.lang.Object value)
public void add(java.util.Collection<?> treePath, java.lang.Object[] values)
treePath
- a list of objects representing a pathvalues
- array of values to be added as keys to bottom-most nodepublic HashTree add(java.util.Collection<?> treePath, java.lang.Object value)
treePath
- a list of objects representing a pathvalue
- Object to add as a node to bottom-most nodevalue
is the keypublic void add(java.util.Collection<?> treePath, java.util.Collection<?> values)
treePath
- a SortedSet of objects representing a pathvalues
- Collection of values to be added as keys to bottom-most nodeprotected HashTree addTreePath(java.util.Collection<?> treePath)
public HashTree getTree(java.lang.Object key)
key
- Key used to find appropriate HashTree()key
public HashTree get(java.lang.Object key)
getTree(Object)
.get
in interface java.util.Map<java.lang.Object,HashTree>
Map.get(Object)
public HashTree getTree(java.lang.Object[] treePath)
treePath
- array of keys.public java.lang.Object clone()
clone
in class java.lang.Object
protected void cloneTree(HashTree newTree)
protected HashTree createNewTree()
protected HashTree createNewTree(java.lang.Object key)
key
- object to use as the key for the top levelHashTree
protected HashTree createNewTree(java.util.Collection<?> values)
public HashTree getTree(java.util.Collection<?> treePath)
treePath
- Collection of keyspublic java.util.Collection<java.lang.Object> list()
public java.util.Collection<?> list(java.lang.Object key)
key
- key used to find HashTree to get list ofpublic HashTree remove(java.lang.Object key)
remove
in interface java.util.Map<java.lang.Object,HashTree>
Map.remove(Object)
public java.util.Collection<?> list(java.lang.Object[] treePath)
treePath
- Array of keys used to recurse into HashTree structurepublic java.util.Collection<?> list(java.util.Collection<?> treePath)
treePath
- List of keys used to recurse into HashTree structurepublic void replaceKey(java.lang.Object currentKey, java.lang.Object newKey)
currentKey
- name of the key to be replacednewKey
- name of the new keypublic java.lang.Object[] getArray()
public java.lang.Object[] getArray(java.lang.Object key)
key
- key used to find HashTree to get list ofpublic java.lang.Object[] getArray(java.lang.Object[] treePath)
treePath
- array of keys used to recurse into HashTree structurepublic java.lang.Object[] getArray(java.util.Collection<?> treePath)
treePath
- list of keys used to recurse into HashTree structureprotected HashTree getTreePath(java.util.Collection<?> treePath)
public int hashCode()
hashCode
in interface java.util.Map<java.lang.Object,HashTree>
hashCode
in class java.lang.Object
Object.hashCode()
public boolean equals(java.lang.Object o)
equals
in interface java.util.Map<java.lang.Object,HashTree>
equals
in class java.lang.Object
o
- Object to be compared againstObject.equals(Object)
public java.util.Set<java.lang.Object> keySet()
keySet
in interface java.util.Map<java.lang.Object,HashTree>
Map.keySet()
public HashTree search(java.lang.Object key)
key
- Key to search fornull
public int size()
size
in interface java.util.Map<java.lang.Object,HashTree>
Map.size()
public void traverse(HashTreeTraverser visitor)
visitor
- the visitor that wants to traverse the treeHashTreeTraverser
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 1998-2019 Apache Software Foundation. All Rights Reserved.