com.myjavatools.lib.foundation
Class KeyValuePairsMap<X,Y>
java.lang.Object
java.util.AbstractMap<X,Y>
com.myjavatools.lib.foundation.KeyValuePairsMap<X,Y>
- All Implemented Interfaces:
- java.util.Map<X,Y>
public class KeyValuePairsMap<X,Y>
- extends java.util.AbstractMap<X,Y>
KeyValuePairsMap is a helper class that implements Map which is based on a key/value array
Note that this class does not take any additional memory; lazy evaluation uses
only the array provided. It is very inefficient; to improve
performance, you will have to create a copy of the Map using
a concrete Map implementation from Collections framework.
Another important caveat. It takes a vararg array of Map.Entry instances.
It is up to the user to make sure that keys in the entries are all distinct -
consider this as a contract that must be stipulated, or else. What else?
First, it won't be a map in its regular sense. Second, size() will
return the number of entries, not the number of distinct entries.
But you can always addAll()
this instance to a new Map,
and in that other Map all duplications will disappear.
- Since:
- 5.0
- Version:
- 6.0 05/04/06
- See Also:
Maps
,
Map
Nested classes/interfaces inherited from interface java.util.Map |
java.util.Map.Entry<K,V> |
Method Summary |
boolean |
containsKey(java.lang.Object x)
Returns true if this map contains a mapping for the specified key. |
java.util.Set<java.util.Map.Entry<X,Y>> |
entrySet()
Returns a set view of the mappings contained in this map. |
Methods inherited from class java.util.AbstractMap |
clear, clone, containsValue, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
KeyValuePairsMap
public KeyValuePairsMap(java.util.Map.Entry<X,Y>... pairs)
- constructor
- Parameters:
pairs
- Map.Entry<X,Y>... even elements contains keys, odd elements contain values
containsKey
public boolean containsKey(java.lang.Object x)
- Returns true if this map contains a mapping for the specified key.
- Specified by:
containsKey
in interface java.util.Map<X,Y>
- Overrides:
containsKey
in class java.util.AbstractMap<X,Y>
- Parameters:
x
- key whose presence in this map is to be tested.
- Returns:
- true if this map contains a mapping for the specified
key.
entrySet
public java.util.Set<java.util.Map.Entry<X,Y>> entrySet()
- Returns a set view of the mappings contained in this map.
- Specified by:
entrySet
in interface java.util.Map<X,Y>
- Specified by:
entrySet
in class java.util.AbstractMap<X,Y>
- Returns:
- a set view of the mappings contained in this map.
Implementation note. Actually no large object is created;
the returned set is a lazy evaluation implementation of Set.