T
- the type of mapped valuespublic interface IntKeyMap<T> extends java.lang.Iterable<IntObjectEntry<T>>
Map<Integer,T>
, but with an int
primitive value.Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the elements from this map.
|
default T |
compute(int key,
java.util.function.BiFunction<java.lang.Integer,? super T,? extends T> remappingFunction)
Attempts to compute a mapping for the specified key and its current
mapped value (or
null if there is no current mapping)
(Method merge() is often simpler to use for such
purposes.) |
default T |
computeIfAbsent(int key,
java.util.function.Function<java.lang.Integer,? extends T> 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 unless
null . |
default T |
computeIfPresent(int key,
java.util.function.BiFunction<java.lang.Integer,? super T,? extends T> remappingFunction)
If the value for the specified key is present, attempts to compute a new
mapping given the key and its current mapped value.
|
default boolean |
containsKey(int key)
Returns true if this map contains the specified element.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified
value.
|
java.util.Set<IntObjectEntry<T>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
void |
forEach(IntObjectConsumer<T> action)
Performs the given action for each pair of element of the map until all
elements have been processed or the action throws an exception.
|
void |
forEachKey(java.util.function.IntConsumer action)
Performs the given action to each int key element of the map until all
elements have been processed or the action throws an exception.
|
T |
get(int key)
Returns the value to which the specified key is mapped, or
null
if this map contains no mapping for the key. |
default T |
getOrDefault(int key,
T defaultValue)
Returns the value to which the specified key is mapped, or
defaultValue if this map contains no mapping for the key. |
default boolean |
isEmpty()
Returns true if this map contains no elements.
|
java.util.Set<java.lang.Integer> |
keySet()
Returns a
Set view of the keys contained in this map. |
default T |
merge(int key,
T value,
java.util.function.BiFunction<? super T,? super T,? extends T> remappingFunction)
If the specified key is not already associated with a value, associates
it with the given non-null value.
|
T |
put(int key,
T value)
Associates the specified value with the specified key in this int keyed
map If the map previously contained a mapping for the key, the old value
is replaced by the specified value.
|
default void |
putAll(IntKeyMap<? extends T> m)
Copies all of the mappings from the specified map to this map.
|
default T |
putIfAbsent(int key,
T value)
If the specified key is not already associated with a value associates it
with the given value and returns
null , else returns the current
value. |
T |
remove(int key)
Removes the specified element from this map if it is present.
|
default boolean |
remove(int key,
java.lang.Object value)
Removes the entry for the specified key only if it is currently mapped to
the specified value.
|
default T |
replace(int key,
T value)
Replaces the entry for the specified key only if it is currently mapped
to some value.
|
default boolean |
replace(int key,
T oldValue,
T newValue)
Replaces the entry for the specified key only if currently mapped to the
specified value.
|
int |
size()
Returns the number of elements in this map (its cardinality).
|
default java.util.Spliterator<IntObjectEntry<T>> |
spliterator() |
default java.util.stream.Stream<IntObjectEntry<T>> |
stream()
Returns a sequential
Stream with this collection of key and value
pairs as its source. |
java.util.Collection<T> |
values()
Returns a
Collection view of the values contained in this map. |
T put(int key, T value)
m.containsKey(k)
would return true.)key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyjava.lang.NullPointerException
- if the specified value is null.default void putAll(IntKeyMap<? extends T> m)
put(key, value)
on
this map once for each mapping from key key
to value
value
in the specified map. The behavior of this operation is
undefined if the specified map is modified while the operation is in
progress.m
- mappings to be stored in this mapjava.lang.NullPointerException
- if the specified map is null, or if the specified map
contains null keys or valuesjava.lang.IllegalArgumentException
- if some property of a key or value in the specified map
prevents it from being stored in this mapT get(int key)
null
if this map contains no mapping for the key.key
- the key whose associated value is to be returnednull
if this map contains no mapping for the keyT remove(int key)
key
- the key to removejava.lang.NullPointerException
- if one of the specified elements are nulldefault boolean containsKey(int key)
key
- key whose presence in this map is to be testedint size()
void clear()
void forEach(IntObjectConsumer<T> action)
action
- The action to be performed for each pair of elementsjava.lang.NullPointerException
- if the specified action is nullvoid forEachKey(java.util.function.IntConsumer action)
action
- The action to be performed for each int key elementjava.lang.NullPointerException
- if the specified action is nullboolean containsValue(java.lang.Object value)
value
- value whose presence in this map is to be testedjava.util.Collection<T> values()
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. If the map is modified while an iteration over the
collection is in progress, the results of the iteration are undefined.
The collection doesn't support element removal.java.util.Set<java.lang.Integer> keySet()
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. If the
map is modified while an iteration over the set is in progress the
results of the iteration are undefined. The set doesn't support element
removal.java.util.Set<IntObjectEntry<T>> entrySet()
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. If
the map is modified while an iteration over the set is in progress the
results of the iteration are undefined.default boolean isEmpty()
default java.util.stream.Stream<IntObjectEntry<T>> stream()
Stream
with this collection of key and value
pairs as its source.Stream
over the pairs of elements in this
collection as IntObjectEntrydefault java.util.Spliterator<IntObjectEntry<T>> spliterator()
spliterator
in interface java.lang.Iterable<IntObjectEntry<T>>
default T getOrDefault(int key, T defaultValue)
defaultValue
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 keyjava.lang.NullPointerException
- if the specified key is nulldefault T putIfAbsent(int key, T value)
null
, 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.java.lang.NullPointerException
- if the specified value is nulldefault boolean remove(int key, java.lang.Object value)
key
- key with which the specified value is associatedvalue
- value expected to be associated with the specified keytrue
if the value was removedjava.lang.NullPointerException
- if the specified value is nulldefault boolean replace(int key, T oldValue, T newValue)
The implementation makes no guarantees about synchronization or atomicity properties of this method.
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 replacedjava.lang.NullPointerException
- if a specified newValue is nulljava.lang.NullPointerException
- if oldValue is nulldefault T replace(int key, T value)
The implementation makes no guarantees about synchronization or atomicity properties of this method.
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keynull
if there was no mapping for the key.java.lang.NullPointerException
- if the specified value is nulldefault T computeIfAbsent(int key, java.util.function.Function<java.lang.Integer,? extends T> mappingFunction)
null
.
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. The most common usage is to
construct a new object serving as an initial mapped value or memoized
result.
The implementation makes no guarantees about synchronization or atomicity properties of this method.
key
- key with which the specified value is to be associatedmappingFunction
- the function to compute a valuejava.lang.NullPointerException
- if the mappingFunction is null or cumputed value is nulldefault T computeIfPresent(int key, java.util.function.BiFunction<java.lang.Integer,? super T,? extends T> 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.
The implementation makes no guarantees about synchronization or atomicity properties of this method.
key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a valuejava.lang.NullPointerException
- if the remappingFunction is nulldefault T compute(int key, java.util.function.BiFunction<java.lang.Integer,? super T,? extends T> remappingFunction)
null
if there is no current mapping)
(Method merge()
is often simpler to use for such
purposes.)
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.
The implementation makes no guarantees about synchronization or atomicity properties of this method.
key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a valuejava.lang.NullPointerException
- if the remappingFunction is nulldefault T merge(int key, T value, java.util.function.BiFunction<? super T,? super T,? extends T> remappingFunction)
null
. 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
function itself throws an (unchecked) exception, the exception is
rethrown, and the current mapping is left unchanged.
The implementation makes no guarantees about synchronization or atomicity properties of this method.
key
- key with which the resulting value is to be associatedvalue
- the non-null value to be merged with the existing value
associated with the key or, if no existing value to be
associated with the keyremappingFunction
- the function to recompute a value if present