de.caff.generics

## Class HashCoderSet<V>

- java.lang.Object
- - de.caff.generics.HashCoderSet<V>

- Type Parameters:
    `V` - element type
  All Implemented Interfaces:
    java.lang.Iterable<V>, java.util.Collection<V>, java.util.Set<V>

      public class HashCoderSet<V>
      extends java.lang.Object
      implements java.util.Set<V>

  A hashset implementation which 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 `HashCoderSet(HashCoder)` or directly with `HashCoderSet(Function1)`.

  Since:
    Mai 18, 2020
  Author:
    Rammi

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HashCoderSet(Function1<V,V> copier)` Constructor for creating a hashmap with keys created from mutable objects.
    `HashCoderSet(HashCodeCalculator<? super V> calculator)` Constructor.
    `HashCoderSet(HashCodeCalculator<? super V> calculator, Matcher<? super V,? super V> matcher)` Constructor.
    `HashCoderSet(HashCodeCalculator<? super V> calculator, Matcher<? super V,? super V> matcher, Function1<V,V> copier)` Constructor.
    `HashCoderSet(HashCoder<V> hashCoder)` Constructor.
    `HashCoderSet(HashCoder<V> hashCoder, java.util.Collection<? extends V> sourceCollection)` Copy constructor.
    `HashCoderSet(HashCoder<V> hashCoder, int initialCapacity)` Constructor.
    `HashCoderSet(HashCoder<V> hashCoder, int initialCapacity, float loadFactor)` Constructor.
    `HashCoderSet(HashCoder<V> hashCoder, java.lang.Iterable<? extends V> source)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(V v)`
    `boolean` | `addAll(java.util.Collection<? extends V> c)`
    `boolean` | `addAll(java.lang.Iterable<? extends V> it)` Add all elements of the given iterable.
    `void` | `clear()`
    `boolean` | `contains(java.lang.Object o)`
    `boolean` | `containsAll(java.util.Collection<?> c)`
    `HashCoder<? super V>` | `getHashCoder()` Get the hash coder used in this map.
    `boolean` | `isEmpty()`
    `java.util.Iterator<V>` | `iterator()`
    `boolean` | `remove(java.lang.Object o)`
    `boolean` | `removeAll(java.util.Collection<?> c)`
    `boolean` | `retainAll(java.util.Collection<?> c)`
    `int` | `size()`
    `java.lang.Object[]` | `toArray()`
    `<T> T[]` | `toArray(T[] a)`

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

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

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

      `equals, hashCode, spliterator`

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

      `parallelStream, removeIf, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Constructor Detail

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCoder<V> hashCoder)

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

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCoder<V> hashCoder,
                              int initialCapacity)

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

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCoder<V> 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

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCoder<V> hashCoder,
                              @NotNull
                              java.util.Collection<? extends V> sourceCollection)

      Copy constructor.
      Parameters:
        `hashCoder` - hash coder used for
        `sourceCollection` - source collection which's elements are copied to this set

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCoder<V> hashCoder,
                              @NotNull
                              java.lang.Iterable<? extends V> source)

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCodeCalculator<? super V> calculator)

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

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCodeCalculator<? super V> calculator,
                              @NotNull
                              Matcher<? super V,? super V> matcher)

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

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              HashCodeCalculator<? super V> calculator,
                              @NotNull
                              Matcher<? super V,? super V> matcher,
                              @NotNull
                              Function1<V,V> 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

    - #### HashCoderSet

          public HashCoderSet(@NotNull
                              Function1<V,V> 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 V> 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.Collection<V>`
      Specified by:
        `size` in interface `java.util.Set<V>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `java.util.Collection<V>`
      Specified by:
        `isEmpty` in interface `java.util.Set<V>`

    - #### contains

          public boolean contains(java.lang.Object o)

      Specified by:
        `contains` in interface `java.util.Collection<V>`
      Specified by:
        `contains` in interface `java.util.Set<V>`

    - #### iterator

          @NotNull
          public java.util.Iterator<V> iterator()

      Specified by:
        `iterator` in interface `java.lang.Iterable<V>`
      Specified by:
        `iterator` in interface `java.util.Collection<V>`
      Specified by:
        `iterator` in interface `java.util.Set<V>`

    - #### toArray

          @NotNull
          public java.lang.Object[] toArray()

      Specified by:
        `toArray` in interface `java.util.Collection<V>`
      Specified by:
        `toArray` in interface `java.util.Set<V>`

    - #### toArray

          @NotNull
          public <T> T[] toArray(@NotNull
                                          T[] a)

      Specified by:
        `toArray` in interface `java.util.Collection<V>`
      Specified by:
        `toArray` in interface `java.util.Set<V>`

    - #### add

          public boolean add(V v)

      Specified by:
        `add` in interface `java.util.Collection<V>`
      Specified by:
        `add` in interface `java.util.Set<V>`

    - #### remove

          public boolean remove(java.lang.Object o)

      Specified by:
        `remove` in interface `java.util.Collection<V>`
      Specified by:
        `remove` in interface `java.util.Set<V>`

    - #### containsAll

          public boolean containsAll(@NotNull
                                     java.util.Collection<?> c)

      Specified by:
        `containsAll` in interface `java.util.Collection<V>`
      Specified by:
        `containsAll` in interface `java.util.Set<V>`

    - #### addAll

          public boolean addAll(java.util.Collection<? extends V> c)

      Specified by:
        `addAll` in interface `java.util.Collection<V>`
      Specified by:
        `addAll` in interface `java.util.Set<V>`

    - #### addAll

          public boolean addAll(@NotNull
                                java.lang.Iterable<? extends V> it)

      Add all elements of the given iterable.
      Parameters:
        `it` - iterable
      Returns:
        `true` when this collection was changed by the addition
        `false` when it was not changed

    - #### retainAll

          public boolean retainAll(@NotNull
                                   java.util.Collection<?> c)

      Specified by:
        `retainAll` in interface `java.util.Collection<V>`
      Specified by:
        `retainAll` in interface `java.util.Set<V>`

    - #### removeAll

          public boolean removeAll(@NotNull
                                   java.util.Collection<?> c)

      Specified by:
        `removeAll` in interface `java.util.Collection<V>`
      Specified by:
        `removeAll` in interface `java.util.Set<V>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `java.util.Collection<V>`
      Specified by:
        `clear` in interface `java.util.Set<V>`