de.caff.generics

## Class RefWrapperHashSet<V>

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

- All Implemented Interfaces:
    java.lang.Iterable<V>, java.util.Collection<V>, java.util.Set<V>

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

  A hash st which holds its elements as references. The list will be automatically cleaned up when an iterator is constructed.
  Author:
    Rammi

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RefWrapperHashSet(ReferenceCreator<? extends java.lang.ref.Reference<V>,V> creator)` Default constructor.
    `RefWrapperHashSet(ReferenceCreator<? extends java.lang.ref.Reference<V>,V> creator, java.util.Collection<? extends V> c)` Create a reference wrapper list from a collection.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(V o)` Appends the specified element to the end of this list (optional operation).
    `boolean` | `addAll(java.util.Collection<? extends V> c)` Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
    `void` | `clear()` Removes all of the elements from this list (optional operation).
    `boolean` | `contains(java.lang.Object o)` Returns `true` if this list contains the specified element.
    `boolean` | `containsAll(java.util.Collection<?> c)` Returns `true` if this list contains all of the elements of the specified collection.
    `boolean` | `isEmpty()` Returns `true` if this list contains no elements.
    `java.util.Iterator<V>` | `iterator()` Returns an iterator over the elements in this list in proper sequence.
    `boolean` | `remove(java.lang.Object o)` Removes the first occurrence in this list of the specified element (optional operation).
    `boolean` | `removeAll(java.util.Collection<?> c)` Removes from this list all the elements that are contained in the specified collection (optional operation).
    `boolean` | `retainAll(java.util.Collection<?> c)` Retains only the elements in this list that are contained in the specified collection (optional operation).
    `int` | `size()` Returns the number of elements in this list.
    `java.lang.Object[]` | `toArray()` Returns an array containing all of the elements in this list in proper sequence.
    `<U> U[]` | `toArray(U[] a)` Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array.

    - ### 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

    - #### RefWrapperHashSet

          public RefWrapperHashSet(@NotNull
                                   ReferenceCreator<? extends java.lang.ref.Reference<V>,V> creator)

      Default constructor. This will use a wrapped hash set
      Parameters:
        `creator` - reference creator used to create the internally stored references

    - #### RefWrapperHashSet

          public RefWrapperHashSet(@NotNull
                                   ReferenceCreator<? extends java.lang.ref.Reference<V>,V> creator,
                                   @NotNull
                                   java.util.Collection<? extends V> c)

      Create a reference wrapper list from a collection. This will use a wrapped linked list and no reference queue.
      Parameters:
        `creator` - reference creator used to create the internally stored references
        `c` - collection the collection elements will be wrapped in the given reference type and added to this list

  - ### Method Detail

    - #### size

          public int size()

      Returns the number of elements in this list. If this list contains more than `Integer.MAX_VALUE` elements, returns `Integer.MAX_VALUE`.
      Specified by:
        `size` in interface `java.util.Collection<V>`
      Specified by:
        `size` in interface `java.util.Set<V>`
      Returns:
        the number of elements in this list.

    - #### isEmpty

          public boolean isEmpty()

      Returns `true` if this list contains no elements.
      Specified by:
        `isEmpty` in interface `java.util.Collection<V>`
      Specified by:
        `isEmpty` in interface `java.util.Set<V>`
      Returns:
        `true` if this list contains no elements.

    - #### contains

          public boolean contains(java.lang.Object o)

      Returns `true` if this list contains the specified element. More formally, returns `true` if and only if this list contains at least one element `e` such that `(o==null ? e==null : o.equals(e))`.
      Specified by:
        `contains` in interface `java.util.Collection<V>`
      Specified by:
        `contains` in interface `java.util.Set<V>`
      Parameters:
        `o` - element whose presence in this list is to be tested.
      Returns:
        `true` if this list contains the specified element.
      Throws:
        `java.lang.ClassCastException` - if the type of the specified element is incompatible with this list (optional).
        `java.lang.NullPointerException` - if the specified element is null and this list does not support null elements (optional).

    - #### iterator

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

      Returns an iterator over the elements in this list in proper sequence.
      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>`
      Returns:
        an iterator over the elements in this list in proper sequence.

    - #### toArray

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

      Returns an array containing all of the elements in this list in proper sequence. Obeys the general contract of the `Collection.toArray` method.
      Specified by:
        `toArray` in interface `java.util.Collection<V>`
      Specified by:
        `toArray` in interface `java.util.Set<V>`
      Returns:
        an array containing all of the elements in this list in proper sequence.
      See Also:
        `Arrays.asList(Object[])`

    - #### toArray

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

      Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array. Obeys the general contract of the `Collection.toArray(Object[])` method.
      Specified by:
        `toArray` in interface `java.util.Collection<V>`
      Specified by:
        `toArray` in interface `java.util.Set<V>`
      Parameters:
        `a` - the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
      Returns:
        an array containing the elements of this list.
      Throws:
        `java.lang.ArrayStoreException` - if the runtime type of the specified array is not a supertype of the runtime type of every element in this list.
        `java.lang.NullPointerException` - if the specified array is `null`.

    - #### add

          public boolean add(V o)

      Appends the specified element to the end of this list (optional operation).

      Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.

      Specified by:
        `add` in interface `java.util.Collection<V>`
      Specified by:
        `add` in interface `java.util.Set<V>`
      Parameters:
        `o` - element to be appended to this list.
      Returns:
        `true` (as per the general contract of the `Collection.add` method).
      Throws:
        `java.lang.UnsupportedOperationException` - if the `add` method is not supported by this list.
        `java.lang.ClassCastException` - if the class of the specified element prevents it from being added to this list.
        `java.lang.NullPointerException` - if the specified element is null and this list does not support null elements.
        `java.lang.IllegalArgumentException` - if some aspect of this element prevents it from being added to this list.

    - #### remove

          public boolean remove(java.lang.Object o)

      Removes the first occurrence in this list of the specified element (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that `(o==null ? get(i)==null : o.equals(get(i)))` (if such an element exists).
      Specified by:
        `remove` in interface `java.util.Collection<V>`
      Specified by:
        `remove` in interface `java.util.Set<V>`
      Parameters:
        `o` - element to be removed from this list, if present.
      Returns:
        `true` if this list contained the specified element.
      Throws:
        `java.lang.ClassCastException` - if the type of the specified element is incompatible with this list (optional).
        `java.lang.NullPointerException` - if the specified element is null and this list does not support null elements (optional).
        `java.lang.UnsupportedOperationException` - if the `remove` method is not supported by this list.

    - #### containsAll

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

      Returns `true` if this list contains all of the elements of the specified collection.
      Specified by:
        `containsAll` in interface `java.util.Collection<V>`
      Specified by:
        `containsAll` in interface `java.util.Set<V>`
      Parameters:
        `c` - collection to be checked for containment in this list.
      Returns:
        `true` if this list contains all of the elements of the specified collection.
      Throws:
        `java.lang.ClassCastException` - if the types of one or more elements in the specified collection are incompatible with this list (optional).
        `java.lang.NullPointerException` - if the specified collection contains one or more null elements and this list does not support null elements (optional); or if the specified collection is `null`.
      See Also:
        `contains(Object)`

    - #### addAll

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

      Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
      Specified by:
        `addAll` in interface `java.util.Collection<V>`
      Specified by:
        `addAll` in interface `java.util.Set<V>`
      Parameters:
        `c` - collection whose elements are to be added to this list.
      Returns:
        `true` if this list changed as a result of the call.
      Throws:
        `java.lang.UnsupportedOperationException` - if the `addAll` method is not supported by this list.
        `java.lang.ClassCastException` - if the class of an element in the specified collection prevents it from being added to this list.
        `java.lang.NullPointerException` - if the specified collection contains one or more null elements and this list does not support null elements, or if the specified collection is `null`.
        `java.lang.IllegalArgumentException` - if some aspect of an element in the specified collection prevents it from being added to this list.
      See Also:
        `add(Object)`

    - #### removeAll

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

      Removes from this list all the elements that are contained in the specified collection (optional operation).
      Specified by:
        `removeAll` in interface `java.util.Collection<V>`
      Specified by:
        `removeAll` in interface `java.util.Set<V>`
      Parameters:
        `c` - collection that defines which elements will be removed from this list.
      Returns:
        `true` if this list changed as a result of the call.
      Throws:
        `java.lang.UnsupportedOperationException` - if the `removeAll` method is not supported by this list.
        `java.lang.ClassCastException` - if the types of one or more elements in this list are incompatible with the specified collection (optional).
        `java.lang.NullPointerException` - if this list contains one or more null elements and the specified collection does not support null elements (optional); or if the specified collection is `null`.
      See Also:
        `remove(Object)`, `contains(Object)`

    - #### retainAll

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

      Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all the elements that are not contained in the specified collection.
      Specified by:
        `retainAll` in interface `java.util.Collection<V>`
      Specified by:
        `retainAll` in interface `java.util.Set<V>`
      Parameters:
        `c` - collection that defines which elements this set will retain.
      Returns:
        `true` if this list changed as a result of the call.
      Throws:
        `java.lang.UnsupportedOperationException` - if the `retainAll` method is not supported by this list.
        `java.lang.ClassCastException` - if the types of one or more elements in this list are incompatible with the specified collection (optional).
        `java.lang.NullPointerException` - if this list contains one or more null elements and the specified collection does not support null elements (optional); or if the specified collection is `null`.
      See Also:
        `remove(Object)`, `contains(Object)`

    - #### clear

          public void clear()

      Removes all of the elements from this list (optional operation). This list will be empty after this call returns (unless it throws an exception).
      Specified by:
        `clear` in interface `java.util.Collection<V>`
      Specified by:
        `clear` in interface `java.util.Set<V>`
      Throws:
        `java.lang.UnsupportedOperationException` - if the `clear` method is not supported by this list.