|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--util.StringTreeTable
A data structure which allows prefix and wildcard lookup. The table is indexed by strings, and a divider substring ("." by default) is used to create a tree structure. Performing a lookup then gives the matching entry and/or any parents in the tree. The empty string "" is always the root key. For example, a StringTreeTable with `apple', `apple.pie' and `apple.juice' as keys has the following internal structure:
[empty string] ---> apple +--> apple.juice | +--> apple.piePerforming a lookup on "apple.pie" will yield the objects for "apple.pie", "apple", and the empty string "". A get("anteater") will yield a match for just the empty string key.
You can also add a wildcard character ("*" by default) to store "*.pie" in the table and get anything that matches the wildcard. Note that this works on the path components, not on part of the path component. (i.e., you'll match "apple.pie" if you store "*.pie" in the table, but not if you stored "*le.pie")
StringTreeTable allows there to be more than one value for a given key; it will return all such values with the get() method.
Serializable
, Serialized FormField Summary | |
static String |
DEFAULT_WHITE
|
static String |
DEFAULT_WILDCARD
|
Constructor Summary | |
StringTreeTable()
Creates a StringTreeTable using the default divider string (".") and default wildcard ("*"). |
|
StringTreeTable(String divider,
String wildcard)
Creates a StringTreeTable with the given parameters as the divider and wildcard. |
Method Summary | |
void |
add(String nm,
Object o)
Adds a new key,object pair into the tree. |
Set |
get(String nm)
Gets the set of matching objects in the tree structure. |
Set |
getChildren(String nm)
|
static void |
main(String[] args)
|
Iterator |
nodes()
Returns all the keys in the tree. |
int |
nuke(Object o)
Removes an object from all keys in the tree. |
boolean |
remove(String nm,
Object o)
Removes a given key,value pair. |
String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final String DEFAULT_WHITE
public static final String DEFAULT_WILDCARD
Constructor Detail |
public StringTreeTable()
public StringTreeTable(String divider, String wildcard)
divider
- The divider string.wildcard
- The wildcard string.Method Detail |
public Set get(String nm)
This works through a depth-first search, looking for either the current string token or the wildcard character.
nm
- The value to search for.public void add(String nm, Object o)
nm
- The key value to be inserted into the table.o
- The object value for the given key.public boolean remove(String nm, Object o)
nm
- The key to be removed, if present.o
- The object to be removed, if present.public int nuke(Object o)
o
- The object to be removed, if present.public Iterator nodes()
public Set getChildren(String nm)
public String toString()
toString
in class Object
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |