public interface ObjIntMap<K> extends Map<K,Integer>, Container
ObjIntMapFactory
Modifier and Type | Method and Description |
---|---|
int |
addValue(K key,
int addition)
Adds the given
addition value to the value associated with the specified key,
or default
value if this map contains no mapping for the key, and associates the resulting
value with the key. |
int |
addValue(K key,
int addition,
int defaultValue)
Adds the given
addition value to the value associated with the specified key,
or defaultValue if this map contains no mapping for the key, and associates
the resulting value with the key. |
int |
compute(K key,
ObjIntToIntFunction<? super K> remappingFunction)
Attempts to compute a mapping for the specified key and its current mapped value
(or default
value if there is no current mapping).
|
int |
computeIfAbsent(K key,
ToIntFunction<? super K> mappingFunction)
If the specified key is not already associated with a value, attempts
to compute its value using the given mapping function and enters it into this map
.
|
int |
computeIfPresent(K key,
ObjIntToIntFunction<? super K> remappingFunction)
If the value for the specified key is present,
attempts to compute a new mapping given the key and its current mapped value.
|
boolean |
containsValue(int value)
Returns
true if this map maps one or more keys to the specified value. |
boolean |
containsValue(Object value)
Deprecated.
Use specialization
containsValue(int) instead |
ObjIntCursor<K> |
cursor()
Returns a new cursor over the entries of this map.
|
int |
defaultValue()
Returns the default value of this map, which is used instead of
null
in primitive specialization methods, when the key is absent in the map. |
ObjSet<Map.Entry<K,Integer>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
void |
forEach(ObjIntConsumer<? super K> 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(ObjIntPredicate<? super K> 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 . |
Integer |
get(Object key)
Deprecated.
Use specialization
getInt(Object) instead |
int |
getInt(Object key)
Returns the value to which the specified key is mapped, or default
value if this map
contains no mapping for the key.
|
int |
getOrDefault(Object key,
int defaultValue)
Returns the value to which the specified key is mapped, or
defaultValue if this map
contains no mapping for the key. |
Integer |
getOrDefault(Object key,
Integer defaultValue)
Deprecated.
Use specialization
getOrDefault(Object, int) instead |
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. |
int |
merge(K key,
int value,
IntBinaryOperator remappingFunction)
If the specified key is not already associated with a value, associates
it with the given value, otherwise, replaces the value with the results of the given
remapping function.
|
int |
put(K key,
int value)
Associates the specified value with the specified key in this map (optional operation).
|
Integer |
put(K key,
Integer value)
Deprecated.
Use specialization
put(Object, int) instead |
int |
putIfAbsent(K key,
int value)
If the specified key is not already associated with a value, associates
it with the given value and returns default
value, else returns the current value.
|
Integer |
putIfAbsent(K key,
Integer value)
Deprecated.
Use specialization
putIfAbsent(Object, int) instead |
Integer |
remove(Object key)
Deprecated.
Use specialization
removeAsInt(Object) instead |
boolean |
remove(Object key,
int value)
Removes the entry for the specified key only if it is currently mapped to the specified
value.
|
boolean |
remove(Object key,
Object value)
Deprecated.
Use specialization
remove(Object, int) instead |
int |
removeAsInt(Object key)
Removes the mapping for a key from this map if it is present (optional operation).
|
boolean |
removeIf(ObjIntPredicate<? super K> filter)
Removes all of the entries of this collection that satisfy the given predicate.
|
int |
replace(K key,
int value)
Replaces the entry for the specified key only if it is currently mapped to some value.
|
Integer |
replace(K key,
Integer value)
Deprecated.
Use specialization
replace(Object, int) instead |
boolean |
replace(K key,
Integer oldValue,
Integer newValue)
Deprecated.
Use specialization
replace(Object, int, int) instead |
boolean |
replace(K key,
int oldValue,
int newValue)
Replaces the entry for the specified key only if currently mapped to the specified value.
|
void |
replaceAll(ObjIntToIntFunction<? super K> 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.
|
IntCollection |
values()
Returns a
Collection view of the values contained in this map. |
clear, ensureCapacity, isEmpty, shrink, size, sizeAsLong
@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.HashObjIntMapFactory.withKeyEquivalence(net.openhft.koloboke.collect.Equivalence<? super K>)
int defaultValue()
null
in primitive specialization methods, when the key is absent in the map.ObjIntMapFactory.withDefaultValue(int)
@Deprecated boolean containsValue(Object value)
containsValue(int)
insteadcontainsValue
in interface Map<K,Integer>
value
- value whose presence in this map is to be testedboolean containsValue(int value)
true
if this map maps one or more keys to the specified value. This operation
will probably require time linear in the map size for most implementations
of the ObjIntMap
interface.value
- the int
value whose presence in this map is to be testedtrue
if this map maps one or more keys to the specified value@Nullable @Deprecated Integer get(Object key)
getInt(Object)
insteadnull
if this map contains no mapping for the key.
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.)
If this map permits null values, then a return value of
null
does not necessarily indicate that the map
contains no mapping for the key; it's also possible that the map
explicitly maps the key to null
. The containsKey
operation may be used to distinguish these two cases.
int getInt(Object key)
More formally, if this map contains a mapping from a key k
to a value v
such that keyEquivalence() == null ? (key==null ? k==null : key.equals(k)) :
keyEquivalence().nullableEquivalent(k, key)
, then this method returns v
; otherwise
it returns default
value. (There can be at most one such mapping.)
key
- the key whose associated value is to be returnedClassCastException
- 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)@Deprecated Integer getOrDefault(Object key, Integer defaultValue)
getOrDefault(Object, int)
insteaddefaultValue
if this map contains no mapping for the key.key
- the key whose associated value is to be returneddefaultValue
- the default mapping of the keydefaultValue
if this map contains no mapping for the keyClassCastException
- 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)int getOrDefault(Object key, int 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 mapdefaultValue
if this map contains no mapping for the keyClassCastException
- 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 ObjIntConsumer<? super K> 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 ObjIntPredicate<? super K> 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 entrytrue
if the predicate returned true
for all entries of the map,
false
if it returned false
for the entry@Nonnull ObjIntCursor<K> cursor()
@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.@Nonnull IntCollection 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.@Nonnull ObjSet<Map.Entry<K,Integer>> 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.@Deprecated Integer put(K key, Integer value)
put(Object, int)
insteadm.containsKey(k)
would return
true.)put
in interface Map<K,Integer>
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyint put(K key, int value)
m
is said to contain a mapping for a key k
if and only if m.containsKey(k)
would return true
.)key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keykey
, or default
value if there was
no mapping for key
. (A default
value return can also indicate that the map
previously associated default
value with key
.)UnsupportedOperationException
- if the put
operation
is not supported by this mapClassCastException
- if the class of the specified key
prevents it from being stored in this mapNullPointerException
- if the specified key is null,
and this map does not permit null keysIllegalArgumentException
- if some property of a specified key
or value prevents it from being stored in this map@Nullable @Deprecated Integer putIfAbsent(K key, Integer value)
putIfAbsent(Object, int)
insteadnull
, else returns the current value.key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keynull
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 null values.)UnsupportedOperationException
- if the put
operation
is not supported by this mapClassCastException
- if the key or value is of an inappropriate type for this mapNullPointerException
- if the specified value is nullIllegalArgumentException
- if some property of the specified key
or value prevents it from being stored in this mapint putIfAbsent(K key, int value)
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyUnsupportedOperationException
- if the put
operation
is not supported by this mapClassCastException
- if the class of the specified key
prevents it from being stored in this mapNullPointerException
- if the specified key is null,
and this map does not permit null keysIllegalArgumentException
- if some property of a specified key
or value prevents it from being stored in this mapint compute(K key, @Nonnull ObjIntToIntFunction<? super K> remappingFunction)
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 valueClassCastException
- if the class of the
specified key
prevents it from being stored in this map (optional restriction)UnsupportedOperationException
- if the put
operation
is not supported by this mapint computeIfAbsent(K key, @Nonnull ToIntFunction<? super K> mappingFunction)
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 valueClassCastException
- if the class of the
specified key
prevents it from being stored in this map (optional restriction)UnsupportedOperationException
- if the put
operation
is not supported by this mapint computeIfPresent(K key, @Nonnull ObjIntToIntFunction<? super K> remappingFunction)
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 valueClassCastException
- if the class of the
specified key
prevents it from being stored in this map (optional restriction)UnsupportedOperationException
- if the put
operation
is not supported by this mapint merge(K key, int value, @Nonnull IntBinaryOperator remappingFunction)
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 presentNullPointerException
- 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 valuesClassCastException
- if the class of the
specified key
prevents it from being stored in this map (optional restriction)UnsupportedOperationException
- if the put
operation
is not supported by this mapint addValue(K key, int addition)
addition
value to the value associated with the specified key,
or default
value if this map contains no mapping for the key, and associates the resulting
value with the key.key
- the key to which value add the given valueaddition
- the value to addClassCastException
- if the class of the
specified key
prevents it from being stored in this map (optional restriction)UnsupportedOperationException
- if the put
operation
is not supported by this mapint addValue(K key, int addition, int defaultValue)
addition
value to the value associated with the specified key,
or defaultValue
if this map contains no mapping for the key, and associates
the resulting value with the key.
This version of addValue(Object, int)
is useful if you want to count
values from the different initial value, than the default value
of this map.
key
- the key to which value add the given valueaddition
- the value to adddefaultValue
- the value to be used if the map contains no mapping for the given keyClassCastException
- if the class of the
specified key
prevents it from being stored in this map (optional restriction)UnsupportedOperationException
- if the put
operation
is not supported by this map@Nullable @Deprecated Integer replace(K key, Integer value)
replace(Object, int)
insteadkey
- key with which the specified value is associatedvalue
- value to be associated with the specified keynull
if there was
no mapping for the key.UnsupportedOperationException
- if the put
operation
is not supported by this mapNullPointerException
- if the specified value is nullIllegalArgumentException
- if some property of the specified value
prevents it from being stored in this mapint replace(K key, int value)
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keyClassCastException
- if the class of the specified key
prevents it from being stored in this mapNullPointerException
- if the specified key is null,
and this map does not permit null keysIllegalArgumentException
- if some property of a specified key
or value prevents it from being stored in this mapUnsupportedOperationException
- if the put
operation
is not supported by this map@Deprecated boolean replace(K key, Integer oldValue, Integer newValue)
replace(Object, int, int)
insteadkey
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified keytrue
if the value was replacedUnsupportedOperationException
- if the put
operation
is not supported by this mapNullPointerException
- if the specified value is nullIllegalArgumentException
- if some property of the specified value
prevents it from being stored in this mapboolean replace(K key, int oldValue, int 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 keytrue
if the value was replacedClassCastException
- if the class of the specified key
prevents it from being stored in this mapNullPointerException
- if the specified key is null,
and this map does not permit null keysIllegalArgumentException
- if some property of a specified key
or value prevents it from being stored in this mapUnsupportedOperationException
- if the put
operation
is not supported by this mapvoid replaceAll(@Nonnull ObjIntToIntFunction<? super K> function)
function
- the function to apply to each entryUnsupportedOperationException
- if the set
operation
is not supported by this map's entry set iteratorIllegalArgumentException
- if some property of a replacement value
prevents it from being stored in this map (optional restriction)@Nullable @Deprecated Integer remove(Object key)
removeAsInt(Object)
instead(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 this map previously associated the key, or null if the map contained no mapping for the key.
If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.
The map will not contain a mapping for the specified key once the call returns.
int removeAsInt(Object key)
More formally, if this map contains a mapping from a key k
to a value v
such that keyEquivalence() == null ? (key==null ? k==null : key.equals(k)) :
keyEquivalence().nullableEquivalent(k, key)
, that mapping is removed.
(The map can contain at most one such mapping.)
Returns the value to which this map previously associated the key, or default value if the map contained no mapping for the key.
A return value of default value does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to default value.
The map will not contain a mapping for the specified key once the call returns.
key
- key whose mapping is to be removed from the mapkey
, or default
value if there was
no mapping for key
ClassCastException
- if the class of the specified key
prevents it from being stored in this map (optional restriction)NullPointerException
- if the specified key is null,
and this map does not permit null keys (optional restriction)UnsupportedOperationException
- if the remove
operation
is not supported by this map@Deprecated boolean remove(Object key, Object value)
remove(Object, int)
insteadkey
- key with which the specified value is associatedvalue
- value expected to be associated with the specified keytrue
if the value was removedNullPointerException
- if the specified value is null
, or if the specified key is null,
and this map does not permit null keys (optional restriction)ClassCastException
- if the class of the specified key
prevents it from being stored in this map (optional restriction)UnsupportedOperationException
- if the remove
operation
is not supported by this mapboolean remove(Object key, int value)
key
- key with which the specified value is associatedvalue
- value expected to be associated with the specified keytrue
if the value was removedClassCastException
- if the class of the specified key
prevents it from being stored in this map (optional restriction)NullPointerException
- if the specified key is null,
and this map does not permit null keys (optional restriction)UnsupportedOperationException
- if the remove
operation
is not supported by this mapboolean removeIf(@Nonnull ObjIntPredicate<? super K> filter)
filter
- a predicate which returns true
for elements to be removedtrue
if any elements were removedNullPointerException
- if the specified filter is nullUnsupportedOperationException
- 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.