|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<K,V>
bcds.tools.MapToConst<K,V>
public class MapToConst<K,V>
Maps each and every key to a (single) constant value. The map itself is not constant, and keys can be added and removed. Although put and putAll cannot be called through the map, they can be called through the key set passed to the constructor, which is shared with the map object.
MapToConst extends AbstractMap to avoid reimplementing hashCode and equals.
Several methods are overriden (for example size) because otherwise their implementation in AbstractMap produce calls to entrySet, quite unnecessarily in this case.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.util.AbstractMap |
|---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
MapToConst(java.util.Set<K> keys,
V const_value)
Creates an instance in which the values in keys map to const_value, and any
other value maps to null. |
|
| Method Summary | ||
|---|---|---|
void |
clear()
Clears the key set. |
|
boolean |
containsKey(java.lang.Object key)
Returns true if key is mapped by this object. |
|
boolean |
containsValue(java.lang.Object value)
Returns true if value is equal to the constant
value to which all elements in this object map. |
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a set of immutable entries. |
|
V |
get(java.lang.Object key)
Returns the constant value associated to this map if key
exists. |
|
boolean |
isEmpty()
Returns true if the key set is empty. |
|
java.util.Set<K> |
keySet()
Returns a reference to the key set. |
|
static
|
make(java.util.Set<K> keys,
V const_value)
A convenience "factory" method. |
|
V |
remove(java.lang.Object key)
Removes key from the map and returns the constant value. |
|
int |
size()
Returns the number of elements of the key set. |
|
java.lang.String |
toString()
Returns a string the list of keys, an arrow and the constant value. |
|
java.util.Collection<V> |
values()
Returns the same constant value repeated |keys| times so that the number of keys and the number of values match. |
|
| Methods inherited from class java.util.AbstractMap |
|---|
clone, equals, hashCode, put, putAll |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MapToConst(java.util.Set<K> keys,
V const_value)
keys map to const_value, and any
other value maps to null.
The set keys is not copied by this object, so that
any change in that set performed by the caller will affect
this map. This is a deliberate decision, so that the user can
insert or remove keys if so is desired.
const_value - may be null.keys - must not be null.| Method Detail |
|---|
public static <K,V> MapToConst<K,V> make(java.util.Set<K> keys,
V const_value)
public void clear()
clear in interface java.util.Map<K,V>clear in class java.util.AbstractMap<K,V>public boolean containsKey(java.lang.Object key)
key is mapped by this object.
containsKey in interface java.util.Map<K,V>containsKey in class java.util.AbstractMap<K,V>public boolean containsValue(java.lang.Object value)
value is equal to the constant
value to which all elements in this object map.
containsValue in interface java.util.Map<K,V>containsValue in class java.util.AbstractMap<K,V>public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
AbstractMap.SimpleImmutableEntry.
entrySet in interface java.util.Map<K,V>entrySet in class java.util.AbstractMap<K,V>public V get(java.lang.Object key)
key
exists. Otherwise, it returns null. Note that if the
constant value itself is null, the value returned cannot be
used as an indication of the existance of a key.
get in interface java.util.Map<K,V>get in class java.util.AbstractMap<K,V>public boolean isEmpty()
isEmpty in interface java.util.Map<K,V>isEmpty in class java.util.AbstractMap<K,V>public java.util.Set<K> keySet()
keySet in interface java.util.Map<K,V>keySet in class java.util.AbstractMap<K,V>public V remove(java.lang.Object key)
key from the map and returns the constant value.
If the key does not exist, null is returned.
remove in interface java.util.Map<K,V>remove in class java.util.AbstractMap<K,V>public int size()
size in interface java.util.Map<K,V>size in class java.util.AbstractMap<K,V>public java.lang.String toString()
toString in class java.util.AbstractMap<K,V>public java.util.Collection<V> values()
values in interface java.util.Map<K,V>values in class java.util.AbstractMap<K,V>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||