|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ObjObjMap<K,V>
The library's extension of the classic Map
interface.
ObjObjMapFactory
,
@KolobokeMap
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface Map |
---|
Map.Entry<K,V> |
Method Summary | |
---|---|
V |
compute(K key,
BiFunction<? super K,? super V,? extends V> remappingFunction)
Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). |
V |
computeIfAbsent(K key,
Function<? super K,? extends V> mappingFunction)
If the specified key is not already associated with a value (or is mapped to null ), attempts
to compute its value using the given mapping function and enters it into this map
unless null . |
V |
computeIfPresent(K key,
BiFunction<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value. |
ObjObjCursor<K,V> |
cursor()
Returns a new cursor over the entries of this map. |
ObjSet<Map.Entry<K,V>> |
entrySet()
Returns a Set view of the mappings contained in this map. |
void |
forEach(BiConsumer<? super K,? super V> action)
Performs the given action on each entry in this map until all entries
have been processed or the action throws an Exception . |
boolean |
forEachWhile(BiPredicate<? super K,? super V> predicate)
Checks the given predicate on each entry in this map until all entries
have been processed or the predicate returns false for some entry,
or throws an Exception . |
V |
getOrDefault(Object key,
V defaultValue)
Returns the value to which the specified key is mapped, or defaultValue if this map
contains no mapping for the key. |
Equivalence<K> |
keyEquivalence()
Returns the equivalence strategy for keys in this map. |
ObjSet<K> |
keySet()
Returns a Set view of the keys contained in this map. |
V |
merge(K key,
V value,
BiFunction<? super V,? super V,? extends V> remappingFunction)
If the specified key is not already associated with a value (or is mapped to null ), associates
it with the given value, otherwise, replaces the value with the results of the given
remapping function. |
V |
putIfAbsent(K key,
V value)
If the specified key is not already associated with a value (or is mapped to null ), associates
it with the given value and returns null , else returns the current value. |
boolean |
remove(Object key,
Object value)
Removes the entry for the specified key only if it is currently mapped to the specified value. |
boolean |
removeIf(BiPredicate<? super K,? super V> filter)
Removes all of the entries of this collection that satisfy the given predicate. |
V |
replace(K key,
V value)
Replaces the entry for the specified key only if it is currently mapped to some value. |
boolean |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for the specified key only if currently mapped to the specified value. |
void |
replaceAll(BiFunction<? super K,? super V,? extends V> function)
Replaces each entry's value with the result of invoking the given function on that entry, in the order entries are returned by an entry set iterator, until all entries have been processed or the function throws an exception. |
Equivalence<V> |
valueEquivalence()
Returns the equivalence strategy for values in this map. |
ObjCollection<V> |
values()
Returns a Collection view of the values contained in this map. |
Methods inherited from interface Map |
---|
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size |
Methods inherited from interface com.koloboke.collect.Container |
---|
clear, ensureCapacity, isEmpty, shrink, size, sizeAsLong |
Method Detail |
---|
@Nonnull Equivalence<K> keyEquivalence()
Map
interface which defined in terms of Object.equals(Object)
equality of key objects
(almost all methods, actually), are supposed to use this equivalence instead.
HashObjObjMapFactory.withKeyEquivalence(com.koloboke.collect.Equivalence super K>)
@Nonnull Equivalence<V> valueEquivalence()
Map
interface which defined in terms of Object.equals(Object)
equality of value objects,
for example, Map.containsValue(Object)
and remove(Object, Object)
,
are supposed to use this equivalence instead.
ObjObjMapFactory.withValueEquivalence(com.koloboke.collect.Equivalence super V>)
V getOrDefault(Object key, V defaultValue)
defaultValue
if this map
contains no mapping for the key.
key
- the key whose associated value is to be returneddefaultValue
- the value to return if the specified key
is absent in the map
defaultValue
if this map contains no mapping for the key
ClassCastException
- if the key is of an inappropriate type for
this map (optional restriction)
NullPointerException
- if the specified key is null and this map
does not permit null keys (optional restriction)void forEach(@Nonnull BiConsumer<? super K,? super V> action)
action
on each entry in this map until all entries
have been processed or the action throws an Exception
.
Exceptions thrown by the action are relayed to the caller. The entries
will be processed in the same order as the entry set iterator unless that
order is unspecified in which case implementations may use an order which
differs from the entry set iterator.
action
- The action to be performed for each entryboolean forEachWhile(@Nonnull BiPredicate<? super K,? super V> predicate)
predicate
on each entry in this map until all entries
have been processed or the predicate returns false
for some entry,
or throws an Exception
. Exceptions thrown by the predicate are relayed to the caller.
The entries will be processed in the same order as the entry set iterator unless that order is unspecified in which case implementations may use an order which differs from the entry set iterator.
If the map is empty, this method returns true
immediately.
predicate
- the predicate to be checked for each entry
true
if the predicate returned true
for all entries of the map,
false
if it returned false
for the entry@Nonnull ObjObjCursor<K,V> cursor()
Basic cursor usage idiom is:
for (ObjObjCursor<K, V> cur = map.cursor(); cur.moveNext();) {
// Work with cur.key() and cur.value()
// Call cur.remove() to remove the current entry
}
@Nonnull ObjSet<K> keySet()
java.util.Map
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 (except through
the iterator's own remove operation), 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.
keySet
in interface Map<K,V>
@Nonnull ObjCollection<V> values()
java.util.Map
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
(except through the iterator's own remove operation),
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.
values
in interface Map<K,V>
@Nonnull ObjSet<Map.Entry<K,V>> entrySet()
java.util.Map
Set
view of the mappings 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 (except through
the iterator's own remove operation, or through the
setValue operation on a map entry returned by the
iterator) 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.
entrySet
in interface Map<K,V>
@Nullable V putIfAbsent(K key, V value)
null
), associates
it with the given value and returns null
, else returns the current value.
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key
null
if there was no mapping for the key. (A null
return
can also indicate that the map previously associated null
with the key, if the implementation supports such values.)
UnsupportedOperationException
- if the put
operation
is not supported by this map
ClassCastException
- if the class of the specified key or value
prevents it from being stored in this map
NullPointerException
- if the specified key or value is null,
and this map does not permit null keys or values * @throws IllegalArgumentException if some property of a specified key
or value prevents it from being stored in this mapV compute(K key, @Nonnull BiFunction<? super K,? super V,? extends V> remappingFunction)
null
if there is no current mapping).
If the function returns null
, the mapping is removed (or
remains absent if initially absent).
If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.
key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a value
ClassCastException
- if the class of the
specified key or computed value
prevents it from being stored in this map (optional restriction)
UnsupportedOperationException
- if the put
operation
is not supported by this mapV computeIfAbsent(K key, @Nonnull Function<? super K,? extends V> mappingFunction)
null
), attempts
to compute its value using the given mapping function and enters it into this map
unless null
. The most common usage is to construct
a new object serving as an initial mapped value or memoized result.
If the function returns null
no mapping is recorded.
If the function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded.
key
- key with which the specified value is to be associatedmappingFunction
- the function to compute a value
ClassCastException
- if the class of the
specified key or computed value
prevents it from being stored in this map (optional restriction)
UnsupportedOperationException
- if the put
operation
is not supported by this mapV computeIfPresent(K key, @Nonnull BiFunction<? super K,? super V,? extends V> remappingFunction)
If the function returns null
, the mapping is removed.
If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.
key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a value
ClassCastException
- if the class of the
specified key or computed value
prevents it from being stored in this map (optional restriction)
UnsupportedOperationException
- if the put
operation
is not supported by this mapV merge(K key, V value, @Nonnull BiFunction<? super V,? super V,? extends V> remappingFunction)
null
), associates
it with the given value, otherwise, replaces the value with the results of the given
remapping function.
This method may be of use when combining multiple mapped values for a key.
If the function returns null
, the mapping is removed.
If the remappingFunction itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.
key
- key with which the specified value is to be associatedvalue
- the value to use if absentremappingFunction
- the function to recompute a value if present
NullPointerException
- if the remappingFunction
is null
or if the specified key is null and this map does not support null keys
or if the specified value is null and this map does not support null values
ClassCastException
- if the class of the
specified key or computed value
prevents it from being stored in this map (optional restriction)
UnsupportedOperationException
- if the put
operation
is not supported by this map@Nullable V replace(K key, V value)
key
- key with which the specified value is associatedvalue
- value to be associated with the specified key
null
if there was no mapping for the key.
(A null
return can also indicate that the map
previously associated null
with the key,
if the implementation supports such values.)
ClassCastException
- if the class of the specified key or value
prevents it from being stored in this map
NullPointerException
- if the specified key or value is null,
and this map does not permit null keys or values * @throws IllegalArgumentException if some property of a specified key
or value prevents it from being stored in this map
UnsupportedOperationException
- if the put
operation
is not supported by this mapboolean replace(K key, V oldValue, V newValue)
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified key
true
if the value was replaced
ClassCastException
- if the class of the specified key or value
prevents it from being stored in this map
NullPointerException
- if the specified key or value is null,
and this map does not permit null keys or values * @throws IllegalArgumentException if some property of a specified key
or value prevents it from being stored in this map
UnsupportedOperationException
- if the put
operation
is not supported by this mapvoid replaceAll(@Nonnull BiFunction<? super K,? super V,? extends V> function)
function
- the function to apply to each entry
UnsupportedOperationException
- if the set
operation
is not supported by this map's entry set iterator
or the specified replacement value is null, and this map does not permit
null values (optional restriction)
ClassCastException
- if the class of a replacement value
prevents it from being stored in this map
IllegalArgumentException
- if some property of a replacement value
prevents it from being stored in this map (optional restriction)boolean remove(Object key, Object value)
key
- key with which the specified value is associatedvalue
- value expected to be associated with the specified key
true
if the value was removed
ClassCastException
- if the class of the specified key or value
prevents it from being stored in this map (optional restriction)
NullPointerException
- if the specified key or value is null,
and this map does not permit null key or values (optional restriction)
UnsupportedOperationException
- if the remove
operation
is not supported by this mapboolean removeIf(@Nonnull BiPredicate<? super K,? super V> filter)
filter
- a predicate which returns true
for elements to be removed
true
if any elements were removed
NullPointerException
- if the specified filter is null
UnsupportedOperationException
- if elements cannot be removed from this collection.
Implementations may throw this exception if a matching element cannot be removed
or if, in general, removal is not supported.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |