Class WeakValueMap<K,V>

java.lang.Object
com.pnfsoftware.jeb.util.collect.WeakValueMap<K,V>
Type Parameters:
K - key type
V - value type

@Ser public class WeakValueMap<K,V> extends Object
A pseudo-map whose values do not prevent garbage collection of entries. (The "opposite" of WeakHashMap.) Key-value pairs with a null value should not be inserted to this map; no guarantee on retrieval and persistence is provided for null values. The null key is allowed.

This map object supports serializability, on the condition that its key and value types are also serializable.

  • Constructor Details

    • WeakValueMap

      public WeakValueMap(int initialCapacity, float loadFactor)
      Create a weak-value map.
      Parameters:
      initialCapacity - initial capacity
      loadFactor - load factor
    • WeakValueMap

      public WeakValueMap(int initialCapacity)
      Create a weak-value map.
      Parameters:
      initialCapacity - initial capacity
    • WeakValueMap

      public WeakValueMap()
      Create a weak-value map.
    • WeakValueMap

      public WeakValueMap(Map<K,V> t)
      Create a weak-value map initialized from another map.
      Parameters:
      t - source map
  • Method Details

    • clear

      public void clear()
      Remove all mappings.
    • containsKey

      public boolean containsKey(Object key)
      Parameters:
      key - key
      Returns:
      true if the key is present
    • containsValue

      public boolean containsValue(Object value)
      Parameters:
      value - value
      Returns:
      true if a live value is equal to the provided value
    • get

      public V get(Object key)
      Retrieve a value.
      Parameters:
      key - key
      Returns:
      live value, or null
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if no mapping exists
    • keySet

      public Set<K> keySet()
      Returns:
      key set view
    • put

      public V put(K key, V value)
      Add or replace a mapping.
      Parameters:
      key - key
      value - value to weakly reference
      Returns:
      previous live value, or null
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Add all mappings from a map.
      Parameters:
      m - source map
    • remove

      public V remove(Object key)
      Remove a mapping.
      Parameters:
      key - key
      Returns:
      removed live value, or null
    • size

      public int size()
      Returns:
      number of mappings
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object