Class AbstractInt2IntMap

java.lang.Object
it.unimi.dsi.fastutil.ints.AbstractInt2IntFunction
it.unimi.dsi.fastutil.ints.AbstractInt2IntMap
All Implemented Interfaces:
Function<Integer,Integer>, Int2IntFunction, Int2IntMap, Serializable, Function<Integer,Integer>, IntUnaryOperator, Map<Integer,Integer>
Direct Known Subclasses:
AbstractInt2IntSortedMap, Int2IntArrayMap, Int2IntOpenCustomHashMap, Int2IntOpenHashMap

public abstract class AbstractInt2IntMap extends AbstractInt2IntFunction implements Int2IntMap, Serializable
An abstract class providing basic methods for maps implementing a type-specific interface.

Optional operations just throw an UnsupportedOperationException. Generic versions of accessors delegate to the corresponding type-specific counterparts following the interface rules (they take care of returning null on a missing key).

As a further help, this class provides a BasicEntry inner class that implements a type-specific version of Map.Entry; it is particularly useful for those classes that do not implement their own entries (e.g., most immutable maps).

See Also:
  • Method Details

    • containsKey

      public boolean containsKey(int k)
      Returns true if this function contains a mapping for the specified key.
      Specified by:
      containsKey in interface Int2IntFunction
      Specified by:
      containsKey in interface Int2IntMap
      Parameters:
      k - the key.
      Returns:
      true if this function associates a value to key.
      See Also:
      Implementation Specification:
      This implementation does a linear search over the entry set, finding an entry that has the key specified.

      If you override keySet(), you should probably override this method too to take advantage of the (presumably) faster key membership test your keySet() provides.

      If you override this method but not keySet(), then the returned key set will take advantage of this method.

    • containsValue

      public boolean containsValue(int v)
      Returns true if this map maps one or more keys to the specified value.
      Specified by:
      containsValue in interface Int2IntMap
      See Also:
      Implementation Specification:
      This implementation does a linear search over the entry set, finding an entry that has the value specified.

      If you override values(), you should probably override this method too to take advantage of the (presumably) faster value membership test your values() provides.

      If you override this method but not values(), then the returned values collection will take advantage of this method.

    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<Integer,Integer>
    • mergeInt

      public final int mergeInt(int 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 associated value with the results of the given remapping function.
      Specified by:
      mergeInt in interface Int2IntMap
      Parameters:
      key - key with which the resulting value is to be associated.
      value - the value to be merged with the existing value associated with the key or, if no existing value is associated with the key, to be associated with the key.
      remappingFunction - the function to recompute a value if present.
      See Also:
      Implementation Specification:
      This method just delegates to the interface default method, as the default method, but it is final, so it cannot be overridden.
    • keySet

      public IntSet keySet()
      Returns a type-specific-set view of the keys of this map.

      The view is backed by the set returned by Map.entrySet(). Note that no attempt is made at caching the result of this method, as this would require adding some attributes that lightweight implementations would not need. Subclasses may easily override this policy by calling this method and caching the result, but implementors are encouraged to write more efficient ad-hoc implementations.

      Specified by:
      keySet in interface Int2IntMap
      Specified by:
      keySet in interface Map<Integer,Integer>
      Returns:
      a set view of the keys of this map; it may be safely cast to a type-specific interface.
      See Also:
    • values

      public IntCollection values()
      Returns a type-specific-set view of the values of this map.

      The view is backed by the set returned by Map.entrySet(). Note that no attempt is made at caching the result of this method, as this would require adding some attributes that lightweight implementations would not need. Subclasses may easily override this policy by calling this method and caching the result, but implementors are encouraged to write more efficient ad-hoc implementations.

      Specified by:
      values in interface Int2IntMap
      Specified by:
      values in interface Map<Integer,Integer>
      Returns:
      a set view of the values of this map; it may be safely cast to a type-specific interface.
      See Also:
    • putAll

      public void putAll(Map<? extends Integer,? extends Integer> m)
      Specified by:
      putAll in interface Map<Integer,Integer>
    • hashCode

      public int hashCode()
      Returns a hash code for this map. The hash code of a map is computed by summing the hash codes of its entries.
      Specified by:
      hashCode in interface Map<Integer,Integer>
      Overrides:
      hashCode in class Object
      Returns:
      a hash code for this map.
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<Integer,Integer>
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object