de.caff.generics

## Class HashCoderMap<K,V>

- java.lang.Object
- - de.caff.generics.HashCoderMap<K,V>

- Type Parameters:
    `K` - type of hash key
    `V` - value type
  All Implemented Interfaces:
    java.util.Map<K,V>

      public class HashCoderMap<K,V>
      extends java.lang.Object
      implements java.util.Map<K,V>

  A hashmap implementation that allows to provide a dedicated hashcode implementation for its elements.

  Especially for mutable objects you should take care of providing a useful copier with either the `HashCoder` argument in `HashCoderMap(HashCoder)` or directly with `HashCoderMap(Function)`.

  Since:
    Mai 18, 2020
  Author:
    Rammi

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `java.util.Map.Entry<K,V>`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HashCoderMap(java.util.function.Function<K,K> copier)` Constructor for creating a hashmap with keys created from mutable objects.
    `HashCoderMap(HashCodeCalculator<? super K> calculator)` Constructor.
    `HashCoderMap(HashCodeCalculator<? super K> calculator, Matcher<? super K,? super K> matcher)` Constructor.
    `HashCoderMap(HashCodeCalculator<? super K> calculator, Matcher<? super K,? super K> matcher, Function1<K,K> copier)` Constructor.
    `HashCoderMap(HashCoder<K> hashCoder)` Constructor.
    `HashCoderMap(HashCoder<K> hashCoder, int initialCapacity)` Constructor.
    `HashCoderMap(HashCoder<K> hashCoder, int initialCapacity, float loadFactor)` Constructor.
    `HashCoderMap(HashCoder<K> hashCoder, java.util.Map<? extends K,? extends V> sourceMap)` Copy constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()`
    `boolean` | `containsKey(java.lang.Object key)`
    `boolean` | `containsValue(java.lang.Object value)`
    `java.util.Set<java.util.Map.Entry<K,V>>` | `entrySet()`
    `V` | `get(java.lang.Object key)`
    `HashCoder<? super K>` | `getHashCoder()` Get the hash coder used in this map.
    `boolean` | `isEmpty()`
    `java.util.Set<K>` | `keySet()`
    `V` | `put(K key, V value)`
    `void` | `putAll(java.util.Map<? extends K,? extends V> m)`
    `V` | `remove(java.lang.Object key)`
    `int` | `size()`
    `java.util.Collection<V>` | `values()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Map

      `compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll`

- - ### Constructor Detail

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              HashCoder<K> hashCoder)

      Constructor.
      Parameters:
        `hashCoder` - hash coder used for hashcode calculation, equality checks and copying

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              HashCoder<K> hashCoder,
                              int initialCapacity)

      Constructor.
      Parameters:
        `hashCoder` - hash coder used for hashcode calculation, equality checks and copying
        `initialCapacity` - initial map capacity

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              HashCoder<K> hashCoder,
                              int initialCapacity,
                              float loadFactor)

      Constructor.
      Parameters:
        `hashCoder` - hash coder used for hashcode calculation, equality checks and copying
        `initialCapacity` - initial map capacity
        `loadFactor` - map load factor

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              HashCoder<K> hashCoder,
                              @NotNull
                              java.util.Map<? extends K,? extends V> sourceMap)

      Copy constructor.
      Parameters:
        `hashCoder` - hash coder used for
        `sourceMap` - source map which is copied to this map

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              HashCodeCalculator<? super K> calculator)

      Constructor. This uses `Objects.equals(Object, Object)` for equality checks.
      Parameters:
        `calculator` - hash code calculator

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              HashCodeCalculator<? super K> calculator,
                              @NotNull
                              Matcher<? super K,? super K> matcher)

      Constructor.
      Parameters:
        `calculator` - hash code calculator
        `matcher` - equality checker fpr hash keys

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              HashCodeCalculator<? super K> calculator,
                              @NotNull
                              Matcher<? super K,? super K> matcher,
                              @NotNull
                              Function1<K,K> copier)

      Constructor.
      Parameters:
        `calculator` - hash code calculator
        `matcher` - equality checker fpr hash keys
        `copier` - copier for keys, useful to decouple the keys from their basically mutable source objects

    - #### HashCoderMap

          public HashCoderMap(@NotNull
                              java.util.function.Function<K,K> copier)

      Constructor for creating a hashmap with keys created from mutable objects. As this decouples the internally used keys from incoming and outgoing keys the basic hashmap requirements are always guaranteed.

      Otherwise this uses the `Object.hashCode()`

      Parameters:
        `copier` - copier for keys

  - ### Method Detail

    - #### getHashCoder

          @NotNull
          public HashCoder<? super K> getHashCoder()

      Get the hash coder used in this map.
      Returns:
        hash coder used for hashcode calculation, equality checks and copying

    - #### size

          public int size()

      Specified by:
        `size` in interface `java.util.Map<K,V>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `java.util.Map<K,V>`

    - #### containsKey

          public boolean containsKey(java.lang.Object key)

      Specified by:
        `containsKey` in interface `java.util.Map<K,V>`

    - #### containsValue

          public boolean containsValue(java.lang.Object value)

      Specified by:
        `containsValue` in interface `java.util.Map<K,V>`

    - #### get

          public V get(java.lang.Object key)

      Specified by:
        `get` in interface `java.util.Map<K,V>`

    - #### put

          public V put(K key,
                       V value)

      Specified by:
        `put` in interface `java.util.Map<K,V>`

    - #### remove

          public V remove(java.lang.Object key)

      Specified by:
        `remove` in interface `java.util.Map<K,V>`

    - #### putAll

          public void putAll(java.util.Map<? extends K,? extends V> m)

      Specified by:
        `putAll` in interface `java.util.Map<K,V>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `java.util.Map<K,V>`

    - #### keySet

          @NotNull
          public java.util.Set<K> keySet()

      Specified by:
        `keySet` in interface `java.util.Map<K,V>`

    - #### values

          @NotNull
          public java.util.Collection<V> values()

      Specified by:
        `values` in interface `java.util.Map<K,V>`

    - #### entrySet

          @NotNull
          public java.util.Set<java.util.Map.Entry<K,V>> entrySet()

      Specified by:
        `entrySet` in interface `java.util.Map<K,V>`