|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface AnyMap<K,V>
This interface is the common ancestor of all modifiable Jjoost maps. The methods declared here make no assumptions about the number of occurrences of a given key or key->value pair.
WARNING: Note that in a MultiMap and ListMap the
keys() method returns a MultiSet and as such an
Iterator over this will yield each duplicate key the number of
times it occurs in the map. For unique keys, call
keys().unique()
Also note that an Iterator returned by concurrent implementors
of this class is permitted to return values more times than they actually
ever occurred if a valid sequence of deletes and inserts happens to
cause the Iterator to see the values multiple times. See the
javadoc of the implementing classes to determine their behaviour in this
case.
| Method Summary | |
|---|---|
boolean |
add(K key,
V value)
Attempt to add the pair to the map, returning false if it could not be added, and true otherwise. |
int |
clear()
Clears the map, returning the number of elements removed from it. |
java.util.Iterator<java.util.Map.Entry<K,V>> |
clearAndReturn()
Clears the map, returning the entries removed from it. |
AnyMap<K,V> |
copy()
Returns a copy of the map. |
AnySet<java.util.Map.Entry<K,V>> |
entries()
Returns a set representing all the key->value pairs in this map. |
AnyMap<V,K> |
inverse()
Returns a map representing the inverse function of this map. |
AnySet<K> |
keys()
Returns a set representing all the keys in the domain of this map. |
V |
put(K key,
V val)
Ensures that the provided key binds to the provided value at least once; depending on the underlying implementation this may remove any existing key->value pairs where the key is equal to the one provided ( Map),
the key and value are both equal (MultiMap), or simply append
this key to all existing maplets regardless of their equality (ListMap). |
V |
putIfAbsent(K key,
V val)
Attempts to bind the provided key to the provided value. |
int |
remove(K key)
Removes all occurrences of the provided key from domain of the map, returning an integer representing the total number of items removed |
int |
remove(K key,
V val)
Removes all occurrences of the provided key->value pair from the map, returning an integer representing the total number of items removed |
java.lang.Iterable<java.util.Map.Entry<K,V>> |
removeAndReturn(K key)
Removes all occurrences of the provided key from domain of the map, returning the entries removed |
java.lang.Iterable<java.util.Map.Entry<K,V>> |
removeAndReturn(K key,
V val)
Removes all occurrences of the provided key->value pair from the map, returning the entries removed |
V |
removeAndReturnFirst(K key)
Removes all occurrences of the provided key from domain of the map, returning the first such value removed, or null if none |
void |
shrink()
Attempts to make the map use less memory, if possible. |
AnySet<V> |
values()
Returns a set representing the range of the map. |
AnySet<V> |
values(K key)
Returns a set representing the values associated with the provided key in this map. |
| Methods inherited from interface org.jjoost.collections.AnyReadMap |
|---|
contains, contains, count, count, entries, first, isEmpty, list, permitsDuplicateKeys, totalCount, uniqueKeyCount |
| Method Detail |
|---|
boolean add(K key,
V value)
false if it could not be added, and true otherwise. In a
ListMap the return value will always be true; however in a MultiMap it will be
false, and hence the map remain unmodified, if a pair whose key and value are both equal to the ones provided (as
determined by the map's definitions of equality) is already present; and in a Map it will be false if a
pair whose key is equal to the one provided is already present. When the value of the pair is inequal to null, this is
equivalent to put(key, value) == null
key - key to insertvalue - value to insert
true if the map was modified, false otherwise
V put(K key,
V val)
Map),
the key and value are both equal (MultiMap), or simply append
this key to all existing maplets regardless of their equality (ListMap).
If any pair is removed as a result of this action, the value of that pair is returned.
key - the keyval - the val
V putIfAbsent(K key,
V val)
Map will return
this value, whereas both MultiMap and ListMap will insert the
new pair and return null. If the key->value pair is present in the map then all maps
will return a value already associated with the key (in both Map and
MultiMap there will be precisely one such value)
key - the keyval - the val
AnySet<V> values(K key)
AnyReadMap
Note that in a regular (scalar) map the set returned will be a
UnitarySet, which contains at most one value.
put() operations on such a set will override any existing
value regardless of if it is equal to the one already present.
values in interface AnyReadMap<K,V>int remove(K key)
key - remove
int remove(K key,
V val)
key - the keyval - the val
java.lang.Iterable<java.util.Map.Entry<K,V>> removeAndReturn(K key)
key - key to remove
java.lang.Iterable<java.util.Map.Entry<K,V>> removeAndReturn(K key,
V val)
key - key to removeval - value to remove
V removeAndReturnFirst(K key)
key - the key to remove
AnySet<K> keys()
AnyReadMapMultiMap or ListMap this will be a
MultiSet. This set should always reflect changes to the map,
and changes to the set should be reflected in the map also. Otherwise,
this set should behave exactly as a regular set does. The key equality used
by this map can be obtained from this set.
Depending on the implementation of map, this key set may contain every occurrence of equal keys provided to the map, or may contain a subset thereof with repetitions to bring the number of occurrences in line with the number provided.
Note that the put() methods on this set will always fail,
because no value can be provided to update the map with.
keys in interface AnyReadMap<K,V>AnySet<java.util.Map.Entry<K,V>> entries()
AnyReadMapListMap this will be a MultiSet. This set
should always reflect changes to the map, and changes to the set should
be reflected in the map also. Otherwise, this set should behave exactly
as a regular set does.
entries in interface AnyReadMap<K,V>int clear()
java.util.Iterator<java.util.Map.Entry<K,V>> clearAndReturn()
Iterator will accurately
represent the elements that are removed from the map; however the Iterator must be exhausted for
the clear operation to be guaranteed to have completed.
void shrink()
AnyMap<K,V> copy()
AnyMap<V,K> inverse()
AnySet<V> values()
values in interface AnyReadMap<K,V>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||