public class CharMap<V> extends AbstractMap<Character,V> implements Serializable
char
keys with values.
This class makes a trade off for reduced space usage at the cost of decreased
performace. The put
, get
, containsKey
and get
operations are all logarithmic when the map is unmodified. If a new
mapping is added, or one is removed, the operation is linear in the number of
mappings. Both size
and isEmpty
are still constant time.
The get
operation runs in logarithmic time. The set
operation runs in consant time if setting an existing non-zero value to a
non-zero value. However, if the set
invocation sets a zero value to
non-zero, the operation is linear with the size of the array.
This map allows null values
.
Iteration ordering follows the natural ordering of char
values, with
the lowest char
key value being returned first.
Implementation Note: the Iterator.remove()
method is currently
unsupported and will throw an exception when called. However, a future
implementation will fix this.
TrieMap
,
IntegerMap
,
Map
,
Serialized FormAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
CharMap()
Creates a new map.
|
CharMap(Map<Character,? extends V> m)
Creates a new map with the mappings contained in
m . |
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. |
boolean |
containsValue(Object value) |
Set<Map.Entry<Character,V>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
V |
get(char key)
Returns the value to which the specified key is mapped, or
null
if this map contains no mapping for the key. |
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<Character> |
keySet()
Returns a
Set view of the keys contained in this map. |
V |
put(Character key,
V value)
Adds the mapping from the provided key to the value.
|
V |
put(char key,
V value)
Adds the mapping from the provided key to the value.
|
V |
remove(char 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. |
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. |
public void clear()
public boolean containsKey(Object key)
true
if this map contains a mapping for the specified key.containsKey
in interface Map<Character,V>
containsKey
in class AbstractMap<Character,V>
public boolean containsValue(Object value)
containsValue
in interface Map<Character,V>
containsValue
in class AbstractMap<Character,V>
public Set<Map.Entry<Character,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 get(char key)
null
if this map contains no mapping for the key.public V put(Character key, V value)
put
in interface Map<Character,V>
put
in class AbstractMap<Character,V>
key
- value
- NullPointerException
- if the key is null
IllegalArgumentException
- if the key is not an instance of Integer
public V put(char key, V value)
key
- value
- NullPointerException
- if the key is null
IllegalArgumentException
- if the key is not an instance of Integer
public V remove(Object key)
null
if the map contained no mapping for the key.public V remove(char key)
null
if the map contained no mapping for the key.key
- key whose mapping is to be removed from the mapnull
if there
was no mapping for key.public int size()
public Collection<V> values()
Collection
view of the values contained in this map.Copyright © 2012. All Rights Reserved.