public class TrieMap<V> extends AbstractMap<String,V> implements Serializable
Map
implementation that uses String
instances as
keys. Keys are returned in alphabetical order. This class is optimized for
space efficiency. For a string of length n
, operations are at worst
case n * log(k)
, where k
is the number of unique characters.
In most cases, the cost will be much closer to linear in the number of
characters in the string.
This class does not permit null
keys or values. However, this class
does permit the use of the empty string (a String
of length
0
).
This class is not synchronized. If concurrent updating behavior is required,
the map should be wrapped using Collections.synchronizedMap(Map)
. This map will never throw a
ConcurrentModificationException
during iteration. The
behavior is unspecified if the map is modified while an iterator is being
used.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
TrieMap()
Constructs an empty trie
|
TrieMap(Map<String,? extends V> m)
Constructs this trie, adding all of the provided mappings
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the mappings from this map.
|
boolean |
containsKey(Object key)
Returns
true if this map contains a mapping for the specified key. |
Set<Map.Entry<String,V>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
V |
get(Object key)
Returns the value to which the specified key is mapped, or
null
if this map contains no mapping for the key. |
Set<String> |
keySet()
Returns a
Set view of the keys contained in this map. |
V |
put(String key,
V value)
Adds the mapping from the provided key to the value.
|
V |
remove(Object key)
Removes the mapping for a key from this map if it is present and returns
the value to which this map previously associated the key, or
null if the map contained no mapping for the key. |
int |
size()
Returns the number of key-value mappings in this trie.
|
Collection<V> |
values()
Returns a
Collection view of the values contained in this map. |
clone, containsValue, equals, hashCode, isEmpty, putAll, toString
public void clear()
public boolean containsKey(Object key)
true
if this map contains a mapping for the specified key.containsKey
in interface Map<String,V>
containsKey
in class AbstractMap<String,V>
NullPointerException
- if key is null
ClassCastException
- if key is not an instance of String
public Set<Map.Entry<String,V>> entrySet()
Set
view of the mappings contained in this map.public V get(Object key)
null
if this map contains no mapping for the key.public V put(String key, V value)
put
in interface Map<String,V>
put
in class AbstractMap<String,V>
key
- value
- NullPointerException
IllegalArgumentException
public V remove(Object key)
null
if the map contained no mapping for the key.public int size()
public Collection<V> values()
Collection
view of the values contained in this map.Copyright © 2012. All Rights Reserved.