jasi.sim.basic.table
Class ConditionMap<K,V>
java.lang.Object
jasi.sim.basic.table.ConditionMap<K,V>
- Type Parameters:
K
- Key type.V
- Value type.
- All Implemented Interfaces:
- java.io.Serializable, java.util.Map<K,V>
public final class ConditionMap<K,V>
- extends java.lang.Object
- implements java.util.Map<K,V>, java.io.Serializable
Map of conditions, which provides access to an if-then-else structure. If a
key is not contained in this condition map, it will return a value of the
else-key (null), if this is contained in this map, otherwise null.
- See Also:
- Serialized Form
Constructor Summary |
ConditionMap()
Constructor for ConditionMap. |
Method Summary |
void |
clear()
Removes all mappings from this map. |
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value. |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this map. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this map for equality. |
V |
get(java.lang.Object key)
Returns the value to which the specified key is mapped in this identity
hash map, or null if the map contains no mapping for this key. |
V |
getElse(java.lang.Object key)
Returns the value to which this map maps the specified key. |
int |
hashCode()
Returns the hash code value for this map. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
java.util.Set<K> |
keySet()
Returns a set 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> t)
Copies all of the mappings from the specified map to this map. |
V |
putElse(V value)
n this map. |
V |
remove(java.lang.Object key)
Removes the mapping for this key from this map if it is present. |
int |
size()
Returns the number of key-value mappings in this map. |
java.lang.String |
toString()
Returns a string representation of this object. |
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this map. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
ConditionMap
public ConditionMap()
- Constructor for ConditionMap.
putElse
public V putElse(V value)
- n this map. Put a value for the else-key of this condition map. It will
be stored with a null key in the internal map.
- Parameters:
value
- The value for the else-condition.
- Returns:
- The previous value associated with specified key, or null if
there was no mapping for key.
size
public int size()
- Returns the number of key-value mappings in this map. If the map contains
more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
- Specified by:
size
in interface java.util.Map<K,V>
- Returns:
- The number of key-value mappings in this map.
- See Also:
Map.size()
isEmpty
public boolean isEmpty()
- Returns true if this map contains no key-value mappings.
- Specified by:
isEmpty
in interface java.util.Map<K,V>
- Returns:
- True if this map contains no key-value mappings.
- See Also:
Map.isEmpty()
containsKey
public boolean containsKey(java.lang.Object key)
- Returns true if this map contains a mapping for the specified key. More
formally, returns true if and only if this map contains at a mapping for
a key k such that (key==null ? k==null : key.equals(k)). (There can be at
most one such mapping.
- Specified by:
containsKey
in interface java.util.Map<K,V>
- Parameters:
key
- The key whose presence in this map is to be tested.
- Returns:
- True if this map contains a mapping for the specified key.
- See Also:
Map.containsKey(Object)
containsValue
public boolean containsValue(java.lang.Object value)
- Returns true if this map maps one or more keys to the specified value.
More formally, returns true if and only if this map contains at least one
mapping to a value v such that (value==null ? v==null : value.equals(v)).
- Specified by:
containsValue
in interface java.util.Map<K,V>
- Parameters:
value
- The value whose presence in this map is to be tested.
- Returns:
- True if this map maps one or more keys to the specified value.
- See Also:
Map.containsValue(Object)
get
public V get(java.lang.Object key)
- Returns the value to which the specified key is mapped in this identity
hash map, or null if the map contains no mapping for this key. A return
value of null does not necessarily indicate that the map contains no
mapping for the key; it is also possible that the map explicitly maps the
key to null. The containsKey method may be used to distinguish these two
cases.
More formally, if this map contains a mapping from a key k to a value v
such that (key==null ? k==null : key.equals(k)), then this method returns
v; otherwise it returns null. (There can be at most one such mapping.)
- Specified by:
get
in interface java.util.Map<K,V>
- Parameters:
key
- The key whose associated value is to be returned.
- Returns:
- The value to which this map maps the specified key, or null if
the map contains no mapping for this key.
- See Also:
Map.get(Object)
getElse
public V getElse(java.lang.Object key)
- Returns the value to which this map maps the specified key. If a key is
not contained in this condition map, it will return a value of the
else-key, if the else-key entry is contained in this map, otherwise null.
More formally, if this map contains a mapping from a key k to a value v
such that (key==null ? k==null : key.equals(k)), then this method returns
v; otherwise it returns null. (There can be at most one such mapping.)
- Parameters:
key
- The key whose associated value is to be returned.
- Returns:
- The value to which this map maps the specified key, or null if
the map contains no mapping for this key.
- See Also:
Map.get(Object)
put
public V put(K key,
V value)
- Associates the specified value with the specified key in this map. If the
map previously contained a mapping for this key, the old value is
replaced by the specified value. (A map m is said to contain a mapping
for a key k if and only if m.containsKey(k) would return true.)
- Specified by:
put
in interface java.util.Map<K,V>
- Parameters:
key
- The key with which the specified value is to be associated. If
null, then value will be else condition.value
- The value to be associated with the specified key.
- Returns:
- The previous value associated with specified key, or null if
there was no mapping for key.
- See Also:
Map.put(Object, Object)
remove
public V remove(java.lang.Object key)
- Removes the mapping for this key from this map if it is present. More
formally, if this map contains a mapping from key k to value v such that
(key==null ? k==null : key.equals(k)), that mapping is removed. (The map
can contain at most one such mapping.)
Returns the value to which the map previously associated the key, or null
if the map contained no mapping for this key. (A null return can also
indicate that the map previously associated null with the specified key
if the implementation supports null values.) The map will not contain a
mapping for the specified key once the call returns.
- Specified by:
remove
in interface java.util.Map<K,V>
- Parameters:
key
- The key whose mapping is to be removed from the map.
- Returns:
- Previous value associated with specified key, or null if there
was no mapping for key.
- See Also:
Map.remove(Object)
putAll
public void putAll(java.util.Map<? extends K,? extends V> t)
- Copies all of the mappings from the specified map to this map.
- Specified by:
putAll
in interface java.util.Map<K,V>
- Parameters:
t
- Mappings to be stored in this map.- See Also:
Map.putAll(Map)
clear
public void clear()
- Removes all mappings from this map.
- Specified by:
clear
in interface java.util.Map<K,V>
- See Also:
Map.clear()
keySet
public java.util.Set<K> keySet()
- Returns a set view of the keys contained in this map. The set is backed
by the map, so changes to the map are reflected in the set, and
vice-versa. If the map is modified while an iteration over the set is in
progress, the results of the iteration are undefined. The set supports
element removal, which removes the corresponding mapping from the map,
via the Iterator.remove, Set.remove, removeAll, retainAll, and clear
operations. It does not support the add or addAll operations.
- Specified by:
keySet
in interface java.util.Map<K,V>
- Returns:
- A set view of the keys contained in this map.
- See Also:
Map.keySet()
values
public java.util.Collection<V> values()
- Returns a collection view of the values contained in this map. The
collection is backed by the map, so changes to the map are reflected in
the collection, and vice-versa. If the map is modified while an iteration
over the collection is in progress, the results of the iteration are
undefined. The collection supports element removal, which removes the
corresponding mapping from the map, via the Iterator.remove,
Collection.remove, removeAll, retainAll and clear operations. It does not
support the add or addAll operations.
- Specified by:
values
in interface java.util.Map<K,V>
- Returns:
- A collection view of the values contained in this map.
- See Also:
Map.values()
entrySet
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
- Returns a set view of the mappings contained in this map. Each element in
the returned set is a Map.Entry. The set is backed by the map, so changes
to the map are reflected in the set, and vice-versa. If the map is
modified while an iteration over the set is in progress, the results of
the iteration are undefined. The set supports element removal, which
removes the corresponding mapping from the map, via the Iterator.remove,
Set.remove, removeAll, retainAll and clear operations. It does not
support the add or addAll operations.
- Specified by:
entrySet
in interface java.util.Map<K,V>
- Returns:
- A set view of the mappings contained in this map.
- See Also:
Map.entrySet()
equals
public boolean equals(java.lang.Object o)
- Compares the specified object with this map for equality. Returns true if
the given object is also a map and the two Maps represent the same
mappings. More formally, two maps t1 and t2 represent the same mappings
if t1.entrySet().equals(t2.entrySet()). This ensures that the equals
method works properly across different implementations of the Map
interface.
- Specified by:
equals
in interface java.util.Map<K,V>
- Overrides:
equals
in class java.lang.Object
- Parameters:
o
- The object to be compared for equality with this map.
- Returns:
- True if the specified object is equal to this map.
hashCode
public int hashCode()
- Returns the hash code value for this map. The hash code of a map is
defined to be the sum of the hashCodes of each entry in the map's
entrySet view. This ensures that t1.equals(t2) implies that
t1.hashCode()==t2.hashCode() for any two maps t1 and t2, as required by
the general contract of Object.hashCode.
- Specified by:
hashCode
in interface java.util.Map<K,V>
- Overrides:
hashCode
in class java.lang.Object
- Returns:
- The hash code value for this map.
toString
public java.lang.String toString()
- Returns a string representation of this object.
- Overrides:
toString
in class java.lang.Object
- Returns:
- The string.