it.unimi.dsi.fastutil.objects
Interface Reference2IntFunction<K>

All Superinterfaces:
Function<K,Integer>
All Known Subinterfaces:
Reference2IntMap<K>, Reference2IntSortedMap<K>
All Known Implementing Classes:
AbstractReference2IntFunction, AbstractReference2IntMap, AbstractReference2IntSortedMap, Reference2IntArrayMap, Reference2IntFunctions.EmptyFunction, Reference2IntFunctions.Singleton, Reference2IntFunctions.SynchronizedFunction, Reference2IntFunctions.UnmodifiableFunction, Reference2IntLinkedOpenHashMap, Reference2IntMaps.EmptyMap, Reference2IntMaps.Singleton, Reference2IntMaps.SynchronizedMap, Reference2IntMaps.UnmodifiableMap, Reference2IntOpenHashMap, Reference2IntSortedMaps.EmptySortedMap, Reference2IntSortedMaps.Singleton, Reference2IntSortedMaps.SynchronizedSortedMap, Reference2IntSortedMaps.UnmodifiableSortedMap

public interface Reference2IntFunction<K>
extends Function<K,Integer>

A type-specific Function; provides some additional methods that use polymorphism to avoid (un)boxing.

Type-specific versions of get(), put() and remove() cannot rely on null to denote absence of a key. Rather, they return a default return value, which is set to 0 cast to the return type (false for booleans) at creation, but can be changed using the defaultReturnValue() method.

For uniformity reasons, even maps returning objects implement the default return value (of course, in this case the default return value is initialized to null).

Warning: to fall in line as much as possible with the standard map interface, it is strongly suggested that standard versions of get(), put() and remove() for maps with primitive-type values return null to denote missing keys rather than wrap the default return value in an object (of course, for maps with object keys and values this is not possible, as there is no type-specific version).

See Also:
Function

Method Summary
 int defaultReturnValue()
          Gets the default return value.
 void defaultReturnValue(int rv)
          Sets the default return value.
 int getInt(Object key)
          Returns the value to which the given key is mapped.
 int put(K key, int value)
          Adds a pair to the map.
 int removeInt(Object key)
          Removes the mapping with the given key.
 
Methods inherited from interface it.unimi.dsi.fastutil.Function
clear, containsKey, get, put, remove, size
 

Method Detail

put

int put(K key,
        int value)
Adds a pair to the map.

Parameters:
key - the key.
value - the value.
Returns:
the old value, or the default return value if no value was present for the given key.
See Also:
Function.put(Object,Object)

getInt

int getInt(Object key)
Returns the value to which the given key is mapped.

Parameters:
key - the key.
Returns:
the corresponding value, or the default return value if no value was present for the given key.
See Also:
Function.get(Object)

removeInt

int removeInt(Object key)
Removes the mapping with the given key.

Parameters:
key -
Returns:
the old value, or the default return value if no value was present for the given key.
See Also:
Function.remove(Object)

defaultReturnValue

void defaultReturnValue(int rv)
Sets the default return value. This value must be returned by type-specific versions of get(), put() and remove() to denote that the map does not contain the specified key. It must be 0/false/null by default.

Parameters:
rv - the new default return value.
See Also:
defaultReturnValue()

defaultReturnValue

int defaultReturnValue()
Gets the default return value.

Returns:
the current default return value.