public final class LocalMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>
This class represents a map which can be temporarily modified without
impacting other threads (scoped
changes).
Operation on instances of this class are thread-safe.
For example:
public class XMLFormat {
static LocalMap
Note: Because key-value mappings are inherited, the semantic of
remove(java.lang.Object)
and clear()
is slightly modified (association with
null
values instead of removing the entries).
Constructor and Description |
---|
LocalMap()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all mappings from this map (sets the local values to
null ). |
boolean |
containsKey(java.lang.Object key)
Indicates if this map contains a mapping for the specified key.
|
boolean |
containsValue(java.lang.Object value)
Indicates if this map associates one or more keys to the
specified value.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a
FastCollection view of the mappings contained in this
map. |
V |
get(java.lang.Object key)
Returns the value to which this map associates the specified key.
|
V |
getDefault(K key)
Returns the default value for the specified key.
|
boolean |
isEmpty()
Indicates if this map contains no key-value mappings.
|
java.util.Set<K> |
keySet()
Returns a
FastCollection view of the keys contained in this map. |
V |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
void |
putAll(java.util.Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this map.
|
V |
putDefault(K key,
V defaultValue)
Sets the default value for the specified key (typically done at
initialization).
|
V |
remove(java.lang.Object key)
Removes the mapping for this key from this map if present
(sets the local value to
null ). |
LocalMap<K,V> |
setKeyComparator(FastComparator<? super K> keyComparator)
Sets the key comparator for this local map.
|
LocalMap<K,V> |
setValueComparator(FastComparator<? super V> valueComparator)
Sets the value comparator for this local map.
|
int |
size()
Returns the number of key-value mappings in this map.
|
java.util.Collection<V> |
values()
Returns a
FastCollection view of the values contained in this
map. |
public LocalMap<K,V> setKeyComparator(FastComparator<? super K> keyComparator)
keyComparator
- the key comparator.this
public LocalMap<K,V> setValueComparator(FastComparator<? super V> valueComparator)
valueComparator
- the value comparator.this
public V putDefault(K key, V defaultValue)
key
- the key with which the specified value is to be associated.defaultValue
- the default value to be associated with the
specified key.null
if there was no mapping for key. A
null
return can also indicate that the map
previously associated null
with the specified key.java.lang.NullPointerException
- if the key is null
.public V getDefault(K key)
key
- the key with which the default value is associated.null
if there was no mapping for the key.java.lang.NullPointerException
- if the key is null
.public int size()
public boolean isEmpty()
public boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public V get(java.lang.Object key)
public V put(K key, V value)
put
in interface java.util.Map<K,V>
key
- the key with which the specified value is to be associated.value
- the value to be associated with the specified key.null
if there was no mapping for key. A
null
return can also indicate that the map
previously associated null
with the specified key.java.lang.NullPointerException
- if the key is null
.public void putAll(java.util.Map<? extends K,? extends V> map)
public V remove(java.lang.Object key)
null
).public void clear()
null
).public java.util.Set<K> keySet()
FastCollection
view of the keys contained in this map.keySet
in interface java.util.Map<K,V>
FastCollection
).public java.util.Collection<V> values()
FastCollection
view of the values contained in this
map.values
in interface java.util.Map<K,V>
FastCollection
).public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
FastCollection
view of the mappings contained in this
map.entrySet
in interface java.util.Map<K,V>
FastCollection
).Copyright © 2005 - 2007 Javolution.