com.koloboke.collect.map
Interface ShortObjMap<V>

All Superinterfaces:
Container, Map<Short,V>
All Known Subinterfaces:
HashShortObjMap<V>

public interface ShortObjMap<V>
extends Map<Short,V>, Container

A Map specialization with short keys and Object values.

See Also:
ShortObjMapFactory, @KolobokeMap

Nested Class Summary
 
Nested classes/interfaces inherited from interface Map
Map.Entry<K,V>
 
Method Summary
 V compute(short key, ShortObjFunction<? 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(short key, ShortFunction<? 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(short key, ShortObjFunction<? 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.
 boolean containsKey(Object key)
          Deprecated. Use specialization containsKey(short) instead
 boolean containsKey(short key)
          Returns true if this map contains a mapping for the specified key.
 ShortObjCursor<V> cursor()
          Returns a new cursor over the entries of this map.
 ObjSet<Map.Entry<Short,V>> entrySet()
          Returns a Set view of the mappings contained in this map.
 void forEach(ShortObjConsumer<? 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(ShortObjPredicate<? 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 get(Object key)
          Deprecated. Use specialization get(short) instead
 V get(short key)
          Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
 V getOrDefault(Object key, V defaultValue)
          Deprecated. Use specialization getOrDefault(short, Object) instead
 V getOrDefault(short key, V defaultValue)
          Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
 ShortSet keySet()
          Returns a Set view of the keys contained in this map.
 V merge(short 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 put(short key, V value)
          Associates the specified value with the specified key in this map (optional operation).
 V put(Short key, V value)
          Deprecated. Use specialization put(short, Object) instead
 V putIfAbsent(short 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.
 V putIfAbsent(Short key, V value)
          Deprecated. Use specialization putIfAbsent(short, Object) instead
 V remove(Object key)
          Deprecated. Use specialization remove(short) instead
 boolean remove(Object key, Object value)
          Deprecated. Use specialization remove(short, Object) instead
 V remove(short key)
          Removes the mapping for a key from this map if it is present (optional operation).
 boolean remove(short key, Object value)
          Removes the entry for the specified key only if it is currently mapped to the specified value.
 boolean removeIf(ShortObjPredicate<? super V> filter)
          Removes all of the entries of this collection that satisfy the given predicate.
 V replace(short key, V value)
          Replaces the entry for the specified key only if it is currently mapped to some value.
 V replace(Short key, V value)
          Deprecated. Use specialization replace(short, Object) instead
 boolean replace(short key, V oldValue, V newValue)
          Replaces the entry for the specified key only if currently mapped to the specified value.
 boolean replace(Short key, V oldValue, V newValue)
          Deprecated. Use specialization replace(short, Object, Object) instead
 void replaceAll(ShortObjFunction<? 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, containsValue, equals, hashCode, isEmpty, putAll, size
 
Methods inherited from interface com.koloboke.collect.Container
clear, ensureCapacity, isEmpty, shrink, size, sizeAsLong
 

Method Detail

valueEquivalence

@Nonnull
Equivalence<V> valueEquivalence()
Returns the equivalence strategy for values in this map. All methods in the Map interface which defined in terms of Object.equals(Object) equality of value objects, for example, Map.containsValue(Object) and remove(short, Object), are supposed to use this equivalence instead.

Returns:
the equivalence strategy for values in this map
See Also:
ShortObjMapFactory.withValueEquivalence(com.koloboke.collect.Equivalence)

containsKey

@Deprecated
boolean containsKey(Object key)
Deprecated. Use specialization containsKey(short) instead

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)

Specified by:
containsKey in interface Map<Short,V>
Parameters:
key - key whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key

containsKey

boolean containsKey(short key)
Returns true if this map contains a mapping for the specified key.

Parameters:
key - the short key whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key

get

@Nullable
@Deprecated
V get(Object key)
Deprecated. Use specialization get(short) instead

Returns the value to which the specified key is mapped, or null 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.

Specified by:
get in interface Map<Short,V>
Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the specified key is mapped, or null if this map contains no mapping for the key

get

@Nullable
V get(short key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

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(java.lang.Object) operation may be used to distinguish these two cases.

Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the specified key is mapped, or null if this map contains no mapping for the key

getOrDefault

@Deprecated
V getOrDefault(Object key,
                          V defaultValue)
Deprecated. Use specialization getOrDefault(short, Object) instead

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

Parameters:
key - the key whose associated value is to be returned
defaultValue - the default mapping of the key
Returns:
the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key

getOrDefault

V getOrDefault(short key,
               V defaultValue)
Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

Parameters:
key - the key whose associated value is to be returned
defaultValue - the value to return if the specified key is absent in the map
Returns:
the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key

forEach

void forEach(@Nonnull
             ShortObjConsumer<? 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. 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.

Parameters:
action - The action to be performed for each entry
See Also:
Comparison of iteration options in the library

forEachWhile

boolean forEachWhile(@Nonnull
                     ShortObjPredicate<? 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. 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.

Parameters:
predicate - the predicate to be checked for each entry
Returns:
true if the predicate returned true for all entries of the map, false if it returned false for the entry
See Also:
Comparison of iteration options in the library

cursor

@Nonnull
ShortObjCursor<V> cursor()
Returns a new cursor over the entries of this map. It's order is always correspond to the entry set iterator order.

Basic cursor usage idiom is:

for (ShortObjCursor<V> cur = map.cursor(); cur.moveNext();) {
     // Work with cur.key() and cur.value()
     // Call cur.remove() to remove the current entry
 }

Returns:
a new cursor over the entries of this map
See Also:
Comparison of iteration options in the library

keySet

@Nonnull
ShortSet keySet()
Description copied from interface: java.util.Map
Returns a 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.

Specified by:
keySet in interface Map<Short,V>
Returns:
a set view of the keys contained in this map

values

@Nonnull
ObjCollection<V> values()
Description copied from interface: java.util.Map
Returns a 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.

Specified by:
values in interface Map<Short,V>
Returns:
a collection view of the values contained in this map

entrySet

@Nonnull
ObjSet<Map.Entry<Short,V>> entrySet()
Description copied from interface: java.util.Map
Returns a 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.

Specified by:
entrySet in interface Map<Short,V>
Returns:
a set view of the mappings contained in this map

put

@Deprecated
V put(Short key,
                 V value)
Deprecated. Use specialization put(short, Object) instead

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Specified by:
put in interface Map<Short,V>
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

put

V put(short key,
      V value)
Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
Throws:
UnsupportedOperationException - if the put operation is not supported by this map
ClassCastException - if the class of the specified value prevents it from being stored in this map
NullPointerException - if the specified value is null, and this map does not permit null values * @throws IllegalArgumentException if some property of a specified key or value prevents it from being stored in this map

putIfAbsent

@Nullable
@Deprecated
V putIfAbsent(Short key,
                                  V value)
Deprecated. Use specialization putIfAbsent(short, Object) instead

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.

Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or 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 null values.)
Throws:
UnsupportedOperationException - if the put operation is not supported by this map
ClassCastException - if the key or value is of an inappropriate type for this map
NullPointerException - if the specified key is null
IllegalArgumentException - if some property of the specified key or value prevents it from being stored in this map

putIfAbsent

@Nullable
V putIfAbsent(short 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.

Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or 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.)
Throws:
UnsupportedOperationException - if the put operation is not supported by this map
ClassCastException - if the class of the specified value prevents it from being stored in this map
NullPointerException - if the specified value is null, and this map does not permit null values * @throws IllegalArgumentException if some property of a specified key or value prevents it from being stored in this map

compute

V compute(short key,
          @Nonnull
          ShortObjFunction<? 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).

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.

Parameters:
key - key with which the specified value is to be associated
remappingFunction - the function to compute a value
Returns:
the new value associated with the specified key
Throws:
ClassCastException - if the class of the computed value prevents it from being stored in this map (optional restriction)
UnsupportedOperationException - if the put operation is not supported by this map

computeIfAbsent

V computeIfAbsent(short key,
                  @Nonnull
                  ShortFunction<? 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. 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.

Parameters:
key - key with which the specified value is to be associated
mappingFunction - the function to compute a value
Returns:
the current (existing or computed) value associated with the specified key
Throws:
ClassCastException - if the class of the computed value prevents it from being stored in this map (optional restriction)
UnsupportedOperationException - if the put operation is not supported by this map

computeIfPresent

V computeIfPresent(short key,
                   @Nonnull
                   ShortObjFunction<? 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.

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.

Parameters:
key - key with which the specified value is to be associated
remappingFunction - the function to compute a value
Returns:
the new value associated with the specified key, or "no entry" value
Throws:
ClassCastException - if the class of the computed value prevents it from being stored in this map (optional restriction)
UnsupportedOperationException - if the put operation is not supported by this map

merge

V merge(short key,
        V value,
        @Nonnull
        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. 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.

Parameters:
key - key with which the specified value is to be associated
value - the value to use if absent
remappingFunction - the function to recompute a value if present
Returns:
the new value associated with the specified key
Throws:
NullPointerException - if the remappingFunction is null
ClassCastException - if the class of the computed value prevents it from being stored in this map (optional restriction)
UnsupportedOperationException - if the put operation is not supported by this map

replace

@Nullable
@Deprecated
V replace(Short key,
                              V value)
Deprecated. Use specialization replace(short, Object) instead

Replaces the entry for the specified key only if it is currently mapped to some value.

Parameters:
key - key with which the specified value is associated
value - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or 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 null values.)
Throws:
UnsupportedOperationException - if the put operation is not supported by this map
NullPointerException - if the specified key is null
IllegalArgumentException - if some property of the specified value prevents it from being stored in this map

replace

@Nullable
V replace(short key,
                   V value)
Replaces the entry for the specified key only if it is currently mapped to some value.

Parameters:
key - key with which the specified value is associated
value - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or 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.)
Throws:
ClassCastException - if the class of the specified value prevents it from being stored in this map
NullPointerException - if the specified value is null, and this map does not permit null 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 map

replace

@Deprecated
boolean replace(Short key,
                           V oldValue,
                           V newValue)
Deprecated. Use specialization replace(short, Object, Object) instead

Replaces the entry for the specified key only if currently mapped to the specified value.

Parameters:
key - key with which the specified value is associated
oldValue - value expected to be associated with the specified key
newValue - value to be associated with the specified key
Returns:
true if the value was replaced
Throws:
UnsupportedOperationException - if the put operation is not supported by this map
NullPointerException - if the specified key is null
IllegalArgumentException - if some property of the specified value prevents it from being stored in this map

replace

boolean replace(short key,
                V oldValue,
                V newValue)
Replaces the entry for the specified key only if currently mapped to the specified value.

Parameters:
key - key with which the specified value is associated
oldValue - value expected to be associated with the specified key
newValue - value to be associated with the specified key
Returns:
true if the value was replaced
Throws:
ClassCastException - if the class of the specified value prevents it from being stored in this map
NullPointerException - if the specified value is null, and this map does not permit null 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 map

replaceAll

void replaceAll(@Nonnull
                ShortObjFunction<? 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.

Parameters:
function - the function to apply to each entry
Throws:
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)

remove

@Nullable
@Deprecated
V remove(Object key)
Deprecated. Use specialization remove(short) instead

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that (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.

Specified by:
remove in interface Map<Short,V>
Parameters:
key - key whose mapping is to be removed from the map
Returns:
the previous value associated with key, or null if there was no mapping for key.

remove

@Nullable
V remove(short key)
Removes the mapping for a key from this map if it is present (optional operation).

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

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.

Parameters:
key - key whose mapping is to be removed from the map
Returns:
the previous value associated with key, or null if there was no mapping for key
Throws:
ClassCastException - if the class of the specified value prevents it from being stored in this map (optional restriction)
NullPointerException - if the specified value is null, and this map does not permit null values (optional restriction)
UnsupportedOperationException - if the remove operation is not supported by this map

remove

@Deprecated
boolean remove(Object key,
                          Object value)
Deprecated. Use specialization remove(short, Object) instead

Removes the entry for the specified key only if it is currently mapped to the specified value.

Parameters:
key - key with which the specified value is associated
value - value expected to be associated with the specified key
Returns:
true if the value was removed
Throws:
NullPointerException - if the specified key is null , or if the specified value is null, and this map does not permit null values (optional restriction)
ClassCastException - if the class of the specified value prevents it from being stored in this map (optional restriction)
UnsupportedOperationException - if the remove operation is not supported by this map

remove

boolean remove(short key,
               Object value)
Removes the entry for the specified key only if it is currently mapped to the specified value.

Parameters:
key - key with which the specified value is associated
value - value expected to be associated with the specified key
Returns:
true if the value was removed
Throws:
ClassCastException - if the class of the specified value prevents it from being stored in this map (optional restriction)
NullPointerException - if the specified value is null, and this map does not permit null values (optional restriction)
UnsupportedOperationException - if the remove operation is not supported by this map

removeIf

boolean removeIf(@Nonnull
                 ShortObjPredicate<? super V> filter)
Removes all of the entries of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.

Parameters:
filter - a predicate which returns true for elements to be removed
Returns:
true if any elements were removed
Throws:
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.
See Also:
Comparison of iteration options in the library