Class WeakObject2LongHashMap<K>

java.lang.Object
one.pkg.tinyutils.map.WeakObject2LongHashMap<K>
Type Parameters:
K - the type of keys maintained by this map

public class WeakObject2LongHashMap<K> extends Object
A Map-like data structure that uses weakly referenced Object keys and primitive long values. Similar to WeakHashMap, an entry is automatically removed when its key is no longer ordinarily reachable.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    WeakObject2LongHashMap(int expected)
     
    WeakObject2LongHashMap(int expected, float f)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all of the mappings from this map.
    boolean
    Returns true if this map contains a mapping for the specified key.
    long
    Gets the default return value for this map.
    void
    Sets the default return value for this map.
    long
    getLong(K key)
    Returns the value to which the specified key is mapped.
    long
    getOrDefault(K key, long defaultValue)
    Returns the value to which the specified key is mapped, or the given default value if this map contains no mapping for the key.
    boolean
    Returns true if this map contains no key-value mappings.
    long
    put(K key, long value)
    Associates the specified value with the specified key in this map.
    long
    remove(K key)
    Removes the mapping for a key from this map if it is present.
    int
    Returns the number of key-value mappings in this map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WeakObject2LongHashMap

      public WeakObject2LongHashMap()
    • WeakObject2LongHashMap

      public WeakObject2LongHashMap(int expected)
    • WeakObject2LongHashMap

      public WeakObject2LongHashMap(int expected, float f)
  • Method Details

    • size

      public int size()
      Returns the number of key-value mappings in this map.
    • isEmpty

      public boolean isEmpty()
      Returns true if this map contains no key-value mappings.
    • getLong

      public long getLong(K key)
      Returns the value to which the specified key is mapped. Returns the map's default return value (usually 0) if this map contains no mapping for the key.
    • getOrDefault

      public long getOrDefault(K key, long defaultValue)
      Returns the value to which the specified key is mapped, or the given default value if this map contains no mapping for the key.
    • put

      public long put(K key, long value)
      Associates the specified value with the specified key in this map.
      Returns:
      the previous value associated with key, or the default value (usually 0) if there was no mapping for key.
    • remove

      public long remove(K key)
      Removes the mapping for a key from this map if it is present.
      Returns:
      the previous value associated with key, or the default value (usually 0) if there was no mapping for key.
    • containsKey

      public boolean containsKey(K key)
      Returns true if this map contains a mapping for the specified key.
    • clear

      public void clear()
      Removes all of the mappings from this map.
    • defaultReturnValue

      public void defaultReturnValue(long rv)
      Sets the default return value for this map.
    • defaultReturnValue

      public long defaultReturnValue()
      Gets the default return value for this map.