Package fj.data

Class HashMap<K,V>

java.lang.Object
fj.data.HashMap<K,V>
All Implemented Interfaces:
Iterable<K>

public final class HashMap<K,V> extends Object implements Iterable<K>
A mutable hash map providing O(1) lookup.
Version:
%build.number%
See Also:
  • Field Details

  • Constructor Details

    • HashMap

      public HashMap(Equal<K> e, Hash<K> h)
      Construct a hash map with the given equality and hashing strategy.
      Parameters:
      e - The equality strategy.
      h - The hashing strategy.
    • HashMap

      public HashMap(Map<K,V> map, Equal<K> e, Hash<K> h)
    • HashMap

      public HashMap(Equal<K> e, Hash<K> h, int initialCapacity)
      Construct a hash map with the given equality and hashing strategy.
      Parameters:
      e - The equality strategy.
      h - The hashing strategy.
      initialCapacity - The initial capacity.
    • HashMap

      public HashMap(Map<K,V> map)
    • HashMap

      public HashMap(Equal<K> e, Hash<K> h, int initialCapacity, float loadFactor)
      Construct a hash map with the given equality and hashing strategy.
      Parameters:
      e - The equality strategy.
      h - The hashing strategy.
      initialCapacity - The initial capacity.
      loadFactor - The load factor.
  • Method Details

    • iterator

      public Iterator<K> iterator()
      Returns an iterator for this map's keys. This method exists to permit the use in a for-each loop.
      Specified by:
      iterator in interface Iterable<K>
      Returns:
      A iterator for this map's keys.
    • hashMap

      public static <K, V> HashMap<K,V> hashMap()
      Construct a hash map that uses Object.equals(java.lang.Object) and Object.hashCode().
      Returns:
      A new hash map that uses Object.equals(java.lang.Object) and Object.hashCode().
    • hashMap

      public static <K, V> HashMap<K,V> hashMap(Equal<K> e, Hash<K> h)
      Construct a hash map.
      Returns:
      A new hash map.
    • eq

      public boolean eq(K k1, K k2)
      Compare two key values for equality using the underlying equality strategy.
      Parameters:
      k1 - One key value to compare.
      k2 - The other key value to compare.
      Returns:
      true if the two key values are equal, false otherwise.
    • hash

      public int hash(K k)
      Compute the hash of the given key value using the underlying hashing strategy.
      Parameters:
      k - The key value to computer the hash of.
      Returns:
      The hash of the given key value.
    • get

      public Option<V> get(K k)
      Returns a potential value that the given key maps to.
      Parameters:
      k - The key to look up in the hash map.
      Returns:
      A potential value for the given key.
    • get

      public F<K,Option<V>> get()
      A curried version of get(Object).
      Returns:
      A curried version of get(Object).
    • clear

      public void clear()
      Clear all entries from this hash map.
    • contains

      public boolean contains(K k)
      Determines if the given key value exists in this hash map.
      Parameters:
      k - The key value to look for in this hash map.
      Returns:
      true if this hash map contains the given key, false otherwise.
    • keys

      public List<K> keys()
      Returns all key entries in this hash map.
      Returns:
      All key entries in this hash map.
    • values

      public List<V> values()
      Returns all values in this hash map.
      Returns:
      All values in this hash map.
    • isEmpty

      public boolean isEmpty()
      Determines if this hash map has any entries.
      Returns:
      true if this hash map has no entries, false otherwise.
    • size

      public int size()
      Returns the number of entries in this hash map.
      Returns:
      The number of entries in this hash map.
    • set

      public void set(K k, V v)
      Inserts the given key and value association into the hash map.
      Parameters:
      k - The key to insert.
      v - The value to insert.
    • delete

      public void delete(K k)
      Deletes the entry in the hash map that corresponds to the given key.
      Parameters:
      k - The key to delete from this hash map.
    • getDelete

      public Option<V> getDelete(K k)
      Deletes the entry in the hash map that corresponds to the given key and returns any associated value.
      Parameters:
      k - The key to delete from this hash map.
      Returns:
      The value that was associated with the given key, if there was one.
    • map

      public <A, B> HashMap<A,B> map(F<K,A> keyFunction, F<V,B> valueFunction, Equal<A> equal, Hash<A> hash)
    • map

      public <A, B> HashMap<A,B> map(F<K,A> keyFunction, F<V,B> valueFunction)
    • map

      public <A, B> HashMap<A,B> map(F<P2<K,V>,P2<A,B>> function, Equal<A> equal, Hash<A> hash)
    • map

      public <A, B> HashMap<A,B> map(F<P2<K,V>,P2<A,B>> function)
    • mapKeys

      public <A> HashMap<A,V> mapKeys(F<K,A> keyFunction, Equal<A> equal, Hash<A> hash)
    • mapKeys

      public <A> HashMap<A,V> mapKeys(F<K,A> function)
    • mapValues

      public <B> HashMap<K,B> mapValues(F<V,B> function)
    • foreachDoEffect

      public void foreachDoEffect(Effect1<P2<K,V>> effect)
    • foreach

      public void foreach(F<P2<K,V>,Unit> function)
    • toList

      public List<P2<K,V>> toList()
    • toCollection

      public Collection<P2<K,V>> toCollection()
      Projects an immutable collection of this hash map.
      Returns:
      An immutable collection of this hash map.
    • toStream

      public Stream<P2<K,V>> toStream()
    • toOption

      public Option<P2<K,V>> toOption()
    • toArray

      public Array<P2<K,V>> toArray()
    • toMap

      public Map<K,V> toMap()
    • fromMap

      public static <K, V> HashMap<K,V> fromMap(Map<K,V> map)
    • fromMap

      public static <K, V> HashMap<K,V> fromMap(Equal<K> eq, Hash<K> h, Map<K,V> map)
    • iterableHashMap

      public static <K, V> HashMap<K,V> iterableHashMap(Equal<K> equal, Hash<K> hash, Iterable<P2<K,V>> entries)
      Converts the Iterable to a HashMap
    • iterableHashMap

      public static <K, V> HashMap<K,V> iterableHashMap(Iterable<P2<K,V>> entries)
      Converts the Iterable to a HashMap
    • arrayHashMap

      @SafeVarargs public static <K, V> HashMap<K,V> arrayHashMap(P2<K,V>... entries)
      Converts the array to a HashMap
    • arrayHashMap

      @SafeVarargs public static <K, V> HashMap<K,V> arrayHashMap(Equal<K> equal, Hash<K> hash, P2<K,V>... entries)
      Converts the array to a HashMap
    • iteratorHashMap

      public static <K, V> HashMap<K,V> iteratorHashMap(Equal<K> equal, Hash<K> hash, Iterator<P2<K,V>> entries)
      Converts the Iterator to a HashMap
    • iteratorHashMap

      public static <K, V> HashMap<K,V> iteratorHashMap(Iterator<P2<K,V>> entries)
      Converts the Iterator to a HashMap