|
|||||||||
| Home >> All >> com >> go >> trove >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.go.trove.util
Class NullKeyMap

java.lang.Objectjava.util.AbstractMap
com.go.trove.util.NullKeyMap
- All Implemented Interfaces:
- java.util.Map, java.io.Serializable
- public class NullKeyMap
- extends java.util.AbstractMap
- implements java.io.Serializable
- extends java.util.AbstractMap
A Map supporting null keys that wraps a Map that doesn't support null keys. NullKeyMap substitutes null keys with a special placeholder object. This technique does not work when the wrapped Map is a TreeMap because it cannot be compared against other objects. In order for TreeMaps to support null keys, use any of the null ordering comparators found in the Utils class.
- Version:
- 9 , 9/07/00
| Nested Class Summary |
| Nested classes inherited from class java.util.AbstractMap |
|
| Nested classes inherited from class java.util.Map |
java.util.Map.Entry |
| Field Summary | |
private java.util.Set |
mEntrySet
|
private java.util.Set |
mKeySet
|
private java.util.Map |
mMap
|
private static java.lang.Object |
NULL
|
| Fields inherited from class java.util.AbstractMap |
|
| Constructor Summary | |
NullKeyMap(java.util.Map map)
|
|
| Method Summary | |
void |
clear()
Remove all entries from this Map (optional operation). |
boolean |
containsKey(java.lang.Object key)
Returns true if this contains a mapping for the given key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this contains at least one mapping with the given value. |
java.util.Set |
entrySet()
Returns a set view of the mappings in this Map. |
java.lang.Object |
get(java.lang.Object key)
Returns the value mapped by the given key. |
boolean |
isEmpty()
Returns true if the map contains no mappings. |
java.util.Set |
keySet()
Returns a set view of this map's keys. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the given key to the given value (optional operation). |
void |
putAll(java.util.Map map)
Copies all entries of the given map to this one (optional operation). |
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key if present (optional operation). |
int |
size()
Returns the number of key-value mappings in the map. |
java.util.Collection |
values()
Returns a collection or bag view of this map's values. |
| Methods inherited from class java.util.AbstractMap |
clone, equals, hashCode, toString |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
NULL
private static final java.lang.Object NULL
mMap
private java.util.Map mMap
mKeySet
private transient java.util.Set mKeySet
mEntrySet
private transient java.util.Set mEntrySet
| Constructor Detail |
NullKeyMap
public NullKeyMap(java.util.Map map)
| Method Detail |
size
public int size()
- Description copied from class:
java.util.AbstractMap - Returns the number of key-value mappings in the map. If there are more
than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is
implemented as
entrySet().size().- Specified by:
sizein interfacejava.util.Map
isEmpty
public boolean isEmpty()
- Description copied from class:
java.util.AbstractMap - Returns true if the map contains no mappings. This is implemented by
size() == 0.- Specified by:
isEmptyin interfacejava.util.Map
containsKey
public boolean containsKey(java.lang.Object key)
- Description copied from class:
java.util.AbstractMap - Returns true if this contains a mapping for the given key. This
implementation does a linear search, O(n), over the
entrySet(), returningtrueif a match is found,falseif the iteration ends. Many subclasses can implement this more efficiently.- Specified by:
containsKeyin interfacejava.util.Map
containsValue
public boolean containsValue(java.lang.Object value)
- Description copied from class:
java.util.AbstractMap - Returns true if this contains at least one mapping with the given value.
This implementation does a linear search, O(n), over the
entrySet(), returningtrueif a match is found,falseif the iteration ends. A match is defined as a value, v, where(value == null ? v == null : value.equals(v)). Subclasses are unlikely to implement this more efficiently.- Specified by:
containsValuein interfacejava.util.Map
get
public java.lang.Object get(java.lang.Object key)
- Description copied from class:
java.util.AbstractMap - Returns the value mapped by the given key. Returns
nullif there is no mapping. However, in Maps that accept null values, you must rely oncontainsKeyto determine if a mapping exists. This iteration takes linear time, searching entrySet().iterator() of the key. Many implementations override this method.- Specified by:
getin interfacejava.util.Map
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
- Description copied from class:
java.util.AbstractMap - Associates the given key to the given value (optional operation). If the
map already contains the key, its value is replaced. This implementation
simply throws an UnsupportedOperationException. Be aware that in a map
that permits
nullvalues, a null return does not always imply that the mapping was created.- Specified by:
putin interfacejava.util.Map
remove
public java.lang.Object remove(java.lang.Object key)
- Description copied from class:
java.util.AbstractMap - Removes the mapping for this key if present (optional operation). This
implementation iterates over the entrySet searching for a matching
key, at which point it calls the iterator's
removemethod. It returns the result ofgetValue()on the entry, if found, or null if no entry is found. Note that maps which permit null values may also return null if the key was removed. If the entrySet does not support removal, this will also fail. This is O(n), so many implementations override it for efficiency.- Specified by:
removein interfacejava.util.Map
putAll
public void putAll(java.util.Map map)
- Description copied from class:
java.util.AbstractMap - Copies all entries of the given map to this one (optional operation). If
the map already contains a key, its value is replaced. This implementation
simply iterates over the map's entrySet(), calling
put, so it is not supported if puts are not.- Specified by:
putAllin interfacejava.util.Map
clear
public void clear()
- Description copied from class:
java.util.AbstractMap - Remove all entries from this Map (optional operation). This default
implementation calls entrySet().clear(). NOTE: If the entry set does
not permit clearing, then this will fail, too. Subclasses often
override this for efficiency. Your implementation of entrySet() should
not call
AbstractMap.clearunless you want an infinite loop.- Specified by:
clearin interfacejava.util.Map
keySet
public java.util.Set keySet()
- Description copied from class:
java.util.AbstractMap - Returns a set view of this map's keys. The set is backed by the map,
so changes in one show up in the other. Modifications while an iteration
is in progress produce undefined behavior. The set supports removal
if entrySet() does, but does not support element addition.
This implementation creates an AbstractSet, where the iterator wraps the entrySet iterator, size defers to the Map's size, and contains defers to the Map's containsKey. The set is created on first use, and returned on subsequent uses, although since no synchronization occurs, there is a slight possibility of creating two sets.
- Specified by:
keySetin interfacejava.util.Map
values
public java.util.Collection values()
- Description copied from class:
java.util.AbstractMap - Returns a collection or bag view of this map's values. The collection
is backed by the map, so changes in one show up in the other.
Modifications while an iteration is in progress produce undefined
behavior. The collection supports removal if entrySet() does, but
does not support element addition.
This implementation creates an AbstractCollection, where the iterator wraps the entrySet iterator, size defers to the Map's size, and contains defers to the Map's containsValue. The collection is created on first use, and returned on subsequent uses, although since no synchronization occurs, there is a slight possibility of creating two collections.
- Specified by:
valuesin interfacejava.util.Map
entrySet
public java.util.Set entrySet()
- Description copied from class:
java.util.AbstractMap - Returns a set view of the mappings in this Map. Each element in the
set must be an implementation of Map.Entry. The set is backed by
the map, so that changes in one show up in the other. Modifications
made while an iterator is in progress cause undefined behavior. If
the set supports removal, these methods must be valid:
Iterator.remove,Set.remove,removeAll,retainAll, andclear. Element addition is not supported via this set.- Specified by:
entrySetin interfacejava.util.Map
|
|||||||||
| Home >> All >> com >> go >> trove >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC