de.tomshut.util
Class LatinTrie<T>

java.lang.Object
  extended by de.tomshut.util.LatinTrie<T>
All Implemented Interfaces:
java.util.Map<java.lang.CharSequence,T>

public class LatinTrie<T>
extends java.lang.Object
implements java.util.Map<java.lang.CharSequence,T>


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
LatinTrie()
           
 
Method Summary
 void clear()
          Removes all of the nodes from this trie.
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains a node for the specified key.
 boolean containsValue(java.lang.Object value)
          Returns true if this trie contains one or more nodes with the specified value.
 java.util.Set<java.util.Map.Entry<java.lang.CharSequence,T>> entrySet()
          Returns a Set view of the nodes contained in this trie.
 T get(java.lang.Object key)
          Returns the value to which the specified key is associated, or null if this trie does not contain the key.
 LatinTrieNode<T> getBestLatinTrieNode(java.lang.Object key)
          Traverse the Trie and get the Trie node which may have our key.
 int getNodeEstimate()
          Returns the estimated number of nodes in the trie
 LatinTrieNode<T> getRoot()
          Returns the root node of the trie
 boolean isEmpty()
          Returns true if this trie contains no keys.
 boolean isMutable()
          Check if the trie is mutable
 java.util.Set<java.lang.CharSequence> keySet()
          Returns a Set view of the keys contained in this map.
 T put(java.lang.CharSequence key, T value)
          Associates the specified value with the specified key in this trie.
 void putAll(java.util.Map<? extends java.lang.CharSequence,? extends T> map)
          Copies all of the mappings from the specified map to this trie.
 T remove(java.lang.Object key)
          Removes the specified key and the value associated to it from this trie if present.
 int size()
          Returns the number of nodes with keys in this trie.
 java.util.Collection<T> values()
          Returns a Collection view of the values contained in this trie.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LatinTrie

public LatinTrie()
Method Detail

clear

public final void clear()
Removes all of the nodes from this trie.

Specified by:
clear in interface java.util.Map<java.lang.CharSequence,T>

containsKey

public final boolean containsKey(java.lang.Object key)
Returns true if this map contains a node for the specified key.

Specified by:
containsKey in interface java.util.Map<java.lang.CharSequence,T>
Parameters:
key - The key whose presence in this trie is to be tested
Returns:
if this trie contains a node for the specified key.

containsValue

public final boolean containsValue(java.lang.Object value)
Returns true if this trie contains one or more nodes with the specified value.

Specified by:
containsValue in interface java.util.Map<java.lang.CharSequence,T>
Parameters:
value - value whose presence in this trie is to be tested
Returns:
if this trie contains one or more nodes with the specified value

entrySet

public final java.util.Set<java.util.Map.Entry<java.lang.CharSequence,T>> entrySet()
Returns a Set view of the nodes contained in this trie. Only nodes that represent keys are returned. A new HashSet is created, so changes to the trie are not reflected in the set, and vice-versa.

Specified by:
entrySet in interface java.util.Map<java.lang.CharSequence,T>
Returns:
a set view of the nodes contained in this trie

get

public final T get(java.lang.Object key)
Returns the value to which the specified key is associated, or null if this trie does not contain the key.

If the given key is null, it returns null.

A return value of null does not necessarily indicate that the trie does not contain the key; it's also possible that the trie explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Specified by:
get in interface java.util.Map<java.lang.CharSequence,T>
Parameters:
key - the key whose associated value is to be returned
Returns:
the value associated to the specified, or null if this trie does not contain the key or the key is associated to null

isEmpty

public final boolean isEmpty()
Returns true if this trie contains no keys.

Specified by:
isEmpty in interface java.util.Map<java.lang.CharSequence,T>
Returns:
true if this trie contains no keys.

keySet

public final java.util.Set<java.lang.CharSequence> keySet()
Returns a Set view of the keys contained in this map. A new HashSet is created, so changes to the trie are not reflected in the set, and vice-versa.

Specified by:
keySet in interface java.util.Map<java.lang.CharSequence,T>
Returns:
a set view of the keys contained in this trie

put

public final T put(java.lang.CharSequence key,
                   T value)
Associates the specified value with the specified key in this trie. If the trie previously contained a value associated with the key, the old value is replaced.

Specified by:
put in interface java.util.Map<java.lang.CharSequence,T>
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)

putAll

public final void putAll(java.util.Map<? extends java.lang.CharSequence,? extends T> map)
Copies all of the mappings from the specified map to this trie. These mappings will replace any mappings that this trie had for any of the keys currently in the specified trie.

Specified by:
putAll in interface java.util.Map<java.lang.CharSequence,T>
Parameters:
map - mappings to be stored in this trie

remove

public final T remove(java.lang.Object key)
Removes the specified key and the value associated to it from this trie if present.

Specified by:
remove in interface java.util.Map<java.lang.CharSequence,T>
Parameters:
key - the key of the object to remove
Returns:
the removed object

size

public final int size()
Returns the number of nodes with keys in this trie.

Specified by:
size in interface java.util.Map<java.lang.CharSequence,T>
Returns:
the number of nodes with keys in this trie.

getNodeEstimate

public final int getNodeEstimate()
Returns the estimated number of nodes in the trie

Returns:
the estimated number of nodes in the trie

values

public final java.util.Collection<T> values()
Returns a Collection view of the values contained in this trie. A new ArrayList is created, so changes to the trie are not reflected in the collection, and vice-versa.

Specified by:
values in interface java.util.Map<java.lang.CharSequence,T>

getRoot

public LatinTrieNode<T> getRoot()
Returns the root node of the trie

Returns:
the root node of the trie

isMutable

public boolean isMutable()
Check if the trie is mutable

Returns:
true if the trie is mutable

getBestLatinTrieNode

public final LatinTrieNode<T> getBestLatinTrieNode(java.lang.Object key)
Traverse the Trie and get the Trie node which may have our key. Return only valid nodes (i.e nodes that either contain other nodes or a key)

Parameters:
key - the key to look for
Returns:
the node that may contain the key.