|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcds.util.TreeHashMap
TreeHashMap: a special HashMap managing hierarchical entries.
A normal HashMap contains pairs of key/value entries. If a value can itself be a HashMap, the it constitutes a node from which a new set of key/values can be defined. Keys in different branches can be identicals.
A TreeHashMap is a tree where every node can have many nodes an the next
level. Every node, including leaves have a path. Only leaves contain an
actual value.
Keys are considered to be only Strings.
From the root, a key can be defined by its path "A.B.C" : A and B have
HashMaps as values, C is a normal key, which returns its value.
If C is still a hashmap, it returns a subtree, also of type TreeHashMap.
It is possible to specify a current node, and add items by specifying the
key from this node on (relative path) or specify an absolute path for a node.
Extending keys to other objects would require an array of objects to specify
a path, instead of the simple syntax A.B.C
Special iterators allow to browse the whole tree, or only one branch.
Nested Class Summary | |
protected class |
TreeHashMap.TreeIterator
Leaf Iterator: returns only the leaf elements from a given node |
Field Summary | |
private static char |
defaultPathSeparator
|
private java.util.HashMap |
hm
|
private java.lang.String |
nodeName
|
private static char |
pathSeparator
|
Constructor Summary | |
|
TreeHashMap()
Constructor. |
private |
TreeHashMap(java.lang.String name)
Constructor. |
Method Summary | |
boolean |
createNode(java.lang.String key)
Create a node. |
java.lang.Object |
get(java.lang.String key)
returns the object corresponding to the key |
java.util.HashMap |
getHashMap()
Returns the internal HashMap used for this node |
private java.lang.String |
getKey(java.lang.String path,
int pos)
Returns the key item defined by a former splitKey method |
java.lang.String |
getName()
Returns the name of a node. |
private java.lang.String |
getPath(java.lang.String path,
int pos)
Returns the remainder path defined by a former splitKey method |
char |
getPathSeparator()
Returns the current path separator |
static void |
main(java.lang.String[] args)
|
boolean |
put(java.lang.String key,
java.lang.Object value)
Add an item to the tree. |
boolean |
put(java.lang.String key,
java.lang.Object value,
boolean create)
Add an item to the tree. |
char |
setPathSeparator(char sep)
Defines a new path separator |
private int |
splitKey(java.lang.String path)
Split a key. |
TreeHashMap.TreeIterator |
treeIterator()
Accessor to a Leaf Iterator |
TreeHashMap.TreeIterator |
treeIterator(int type)
|
TreeHashMap.TreeIterator |
treeIterator(int type,
int level)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final char defaultPathSeparator
private static char pathSeparator
private java.util.HashMap hm
private java.lang.String nodeName
Constructor Detail |
public TreeHashMap()
private TreeHashMap(java.lang.String name)
name
- name for this non root node.Method Detail |
public java.util.HashMap getHashMap()
public char setPathSeparator(char sep)
sep
- new path separator. If it is null, resets the default separator.
The default separator is defined as '/'.
public char getPathSeparator()
public java.lang.String getName()
public boolean createNode(java.lang.String key)
key
- path which is created after this call. Intermediate level
may exist or not. They will be created.
public boolean put(java.lang.String key, java.lang.Object value) throws ExistenceException
key
- key pathvalue
- value to add
ExistenceException
public boolean put(java.lang.String key, java.lang.Object value, boolean create) throws ExistenceException
key
- path defining the key.It can be relative or absolutevalue
- object to write as value at the given key. It can be
any kind of object including a TreeHashMap, which will then be
considered as a new node in the tree.
ExistenceException
public java.lang.Object get(java.lang.String key)
key
- path to the value
private int splitKey(java.lang.String path)
path
- key path to split
private java.lang.String getKey(java.lang.String path, int pos)
path
- key path fromwhich the first key name must be extractedpos
- value returned by splitKey applied on the same path
private java.lang.String getPath(java.lang.String path, int pos)
path
- key path fromwhich the first key name must be extractedpos
- value returned by splitKey applied on the same path
public TreeHashMap.TreeIterator treeIterator()
public TreeHashMap.TreeIterator treeIterator(int type)
public TreeHashMap.TreeIterator treeIterator(int type, int level)
public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |