|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jjoost.collections.maps.wrappers.DefaultFunctionMap<K,V>
public class DefaultFunctionMap<K,V>
| Constructor Summary | |
|---|---|
DefaultFunctionMap(Map<K,V> delegate,
Function<K,V> defaultFunction)
|
|
| Method Summary | |
|---|---|
boolean |
add(K key,
V val)
Attempt to add the pair to the map, returning false if it could not be added, and true otherwise. |
V |
apply(K v)
Returns the result of applying the function to the parameter |
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. |
boolean |
contains(K key)
Returns true iff a key occurs in the map which is equal to the parameter, as determined by the map's definition of equality. |
boolean |
contains(K key,
V val)
Returns true iff a (key,value) pair occurs in the map that is equal to those provided, as determined by the map's definition(s) of equality. |
Map<K,V> |
copy()
Returns a copy of the map. |
int |
count(K key)
Returns the number of occurrences of keys present in the map that are equal to the one provided, as determined by the map's definition of equality. |
int |
count(K key,
V val)
Returns the number of occurrences of (key, value) pairs present in the map that are equal to the one provided, as determined by the map's definition(s) of equality. |
V |
ensureAndGet(K key,
Factory<? extends V> putIfNotPresent)
Equivalent to putIfAbsent(key, putIfNotPresent), except that instead of returning the value previously associated with the key, returns the value associated with the key as the method is exiting; i.e. |
V |
ensureAndGet(K key,
Function<? super K,? extends V> putIfNotPresent)
Equivalent to putIfAbsent(key, putIfNotPresent.create(key)), except that putIfNotPresent.create() is only executed if there is no
key associated with the value. |
Set<java.util.Map.Entry<K,V>> |
entries()
Returns a set representing all the key->value pairs in this map. |
java.lang.Iterable<java.util.Map.Entry<K,V>> |
entries(K key)
Returns an Iterable over all key->value maplets in the map
whose key is equal to the one provided, as determined by the map's
definition of equality. |
V |
first(K key)
Returns the value associated with the first key that is equal to the one provided, as determined by the map's definition of equality. |
V |
get(K key)
A convenience method, equivalent to first(key) |
AnyMap<V,K> |
inverse()
Returns a map representing the inverse function of this map. |
boolean |
isEmpty()
Returns true iff the map is empty |
Set<K> |
keys()
Returns a set representing all the keys in the domain of this map. |
java.util.List<V> |
list(K key)
Returns a List of all values in the map which are mapped to by
the provided key, as determined by the map's definition of equality. |
boolean |
permitsDuplicateKeys()
Returns true if a key can map to more than one value |
V |
put(K key,
V val)
Ensures that the provided key binds to the provided value, removing and returning the value currently associated with the key, or null if none. |
V |
putIfAbsent(K key,
Function<? super K,? extends V> putIfNotPresent)
Equivalent to putIfAbsent(key, putIfNotPresent.create()), except that
putIfNotPresent.create() is only executed if there is no key associated
with the value. |
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. |
int |
size()
A convenience method, equivalent to both totalCount() and uniqueKeyCount() |
int |
totalCount()
Return an integer representing the total number of maplets (i.e. |
int |
uniqueKeyCount()
Return an integer representing the number of unique keys in the domain of the map |
AnySet<V> |
values()
Returns a set representing the range of the map. |
UnitarySet<V> |
values(K key)
Returns a set representing the values associated with the provided key in this map. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultFunctionMap(Map<K,V> delegate,
Function<K,V> defaultFunction)
| Method Detail |
|---|
public V apply(K v)
Function
apply in interface Function<K,V>v - something of type domain
public int clear()
AnyMap
clear in interface AnyMap<K,V>public java.util.Iterator<java.util.Map.Entry<K,V>> clearAndReturn()
AnyMapIterator 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.
clearAndReturn in interface AnyMap<K,V>
public boolean contains(K key,
V val)
AnyReadMap
contains in interface AnyReadMap<K,V>key - the keyval - the val
public boolean contains(K key)
AnyReadMap
contains in interface AnyReadMap<K,V>key - find
public Map<K,V> copy()
AnyMap
copy in interface AnyMap<K,V>copy in interface Map<K,V>
public int count(K key,
V val)
AnyReadMap
count in interface AnyReadMap<K,V>key - the keyval - the val
public int count(K key)
AnyReadMap
count in interface AnyReadMap<K,V>key - the key
public V ensureAndGet(K key,
Factory<? extends V> putIfNotPresent)
Map
ensureAndGet in interface Map<K,V>key - the keyputIfNotPresent - the put if not present
public V ensureAndGet(K key,
Function<? super K,? extends V> putIfNotPresent)
MapputIfNotPresent.create() is only executed if there is no
key associated with the value. In concurrent maps this is not a
guarantee, but a best effort, as it is possible for another thread to set
a value for the key after this has executed but before the record can be
inserted
ensureAndGet in interface Map<K,V>key - the keyputIfNotPresent - put if not present
public Set<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 AnyMap<K,V>entries in interface AnyReadMap<K,V>entries in interface Map<K,V>public java.lang.Iterable<java.util.Map.Entry<K,V>> entries(K key)
AnyReadMapIterable over all key->value maplets in the map
whose key is equal to the one provided, as determined by the map's
definition of equality.
entries in interface AnyReadMap<K,V>key - find
public V get(K key)
Map
get in interface Map<K,V>key - the key
public AnyMap<V,K> inverse()
AnyMap
inverse in interface AnyMap<K,V>public boolean isEmpty()
AnyReadMap
isEmpty in interface AnyReadMap<K,V>public Set<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 AnyMap<K,V>keys in interface AnyReadMap<K,V>keys in interface Map<K,V>public java.util.List<V> list(K key)
AnyReadMapList of all values in the map which are mapped to by
the provided key, as determined by the map's definition of equality. This list
should be constructed "eagerly" and should be a consistent snapshot of
the values valid at some point between the method being called and it returning.
list in interface AnyReadMap<K,V>key - the key
public boolean permitsDuplicateKeys()
AnyReadMap
permitsDuplicateKeys in interface AnyReadMap<K,V>
public boolean add(K key,
V val)
AnyMapfalse 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
add in interface AnyMap<K,V>key - key to insertval - value to insert
true if the map was modified, false otherwise
public V put(K key,
V val)
Map
put in interface AnyMap<K,V>put in interface Map<K,V>key - the keyval - the val
public V putIfAbsent(K key,
Function<? super K,? extends V> putIfNotPresent)
MapputIfAbsent(key, putIfNotPresent.create()), except that
putIfNotPresent.create() is only executed if there is no key associated
with the value. In concurrent maps this is not a guarantee, but a best effort,
as it is possible for another thread to set a value for the key after this has executed
but before the record can be inserted.
putIfAbsent in interface Map<K,V>key - the keyputIfNotPresent - the put if not present
public V putIfAbsent(K key,
V val)
Map
putIfAbsent in interface AnyMap<K,V>putIfAbsent in interface Map<K,V>key - the keyval - the val
public int remove(K key,
V val)
AnyMap
remove in interface AnyMap<K,V>key - the keyval - the val
public int remove(K key)
AnyMap
remove in interface AnyMap<K,V>key - remove
public java.lang.Iterable<java.util.Map.Entry<K,V>> removeAndReturn(K key,
V val)
AnyMap
removeAndReturn in interface AnyMap<K,V>key - key to removeval - value to remove
public java.lang.Iterable<java.util.Map.Entry<K,V>> removeAndReturn(K key)
AnyMap
removeAndReturn in interface AnyMap<K,V>key - key to remove
public V removeAndReturnFirst(K key)
AnyMap
removeAndReturnFirst in interface AnyMap<K,V>key - the key to remove
public void shrink()
AnyMap
shrink in interface AnyMap<K,V>public int size()
MaptotalCount() and uniqueKeyCount()
size in interface Map<K,V>public int totalCount()
AnyReadMap
totalCount in interface AnyReadMap<K,V>public int uniqueKeyCount()
AnyReadMap
uniqueKeyCount in interface AnyReadMap<K,V>public AnySet<V> values()
AnyMap
values in interface AnyMap<K,V>values in interface AnyReadMap<K,V>public UnitarySet<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 AnyMap<K,V>values in interface AnyReadMap<K,V>values in interface Map<K,V>public V first(K key)
AnyReadMapnull if no matching key
is found.
first in interface AnyReadMap<K,V>key - the key
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||