Class QuantumIdentityHashSet<K>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<K>
org.kingdoms.utils.internal.identity.QuantumIdentityHashSet<K>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<K>, Collection<K>, Set<K>

public class QuantumIdentityHashSet<K> extends AbstractSet<K> implements Serializable, Cloneable
Used because QuantumIdentityHashMap allocates more memory for the value.
See Also:
  • Constructor Details

    • QuantumIdentityHashSet

      public QuantumIdentityHashSet()
      Constructs a new, empty identity hash map with a default expected maximum size (21).
    • QuantumIdentityHashSet

      public QuantumIdentityHashSet(int expectedMaxSize)
      Constructs a new, empty map with the specified expected maximum size. Putting more than the expected number of key-value mappings into the map may cause the internal data structure to grow, which may be somewhat time-consuming.
      Parameters:
      expectedMaxSize - the expected maximum size of the map
      Throws:
      IllegalArgumentException - if expectedMaxSize is negative
  • Method Details

    • size

      public int size()
      Returns the number of key-value mappings in this identity hash map.
      Specified by:
      size in interface Collection<K>
      Specified by:
      size in interface Set<K>
      Specified by:
      size in class AbstractCollection<K>
      Returns:
      the number of key-value mappings in this map
    • isEmpty

      public boolean isEmpty()
      Returns true if this identity hash map contains no key-value mappings.
      Specified by:
      isEmpty in interface Collection<K>
      Specified by:
      isEmpty in interface Set<K>
      Overrides:
      isEmpty in class AbstractCollection<K>
      Returns:
      true if this identity hash map contains no key-value mappings
    • contains

      public boolean contains(@NonNull Object key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

      More formally, if this map contains a mapping from a key k to a value v such that (key == k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

      A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The contains(Object)} operation may be used to distinguish these two cases.

      Specified by:
      contains in interface Collection<K>
      Specified by:
      contains in interface Set<K>
      Overrides:
      contains in class AbstractCollection<K>
      See Also:
    • iterator

      public @NonNull Iterator<K> iterator()
      Returns an identity-based set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear methods. It does not support the add or addAll methods.

      While the object returned by this method implements the Set interface, it does not obey Set's general contract. Like its backing map, the set returned by this method defines element equality as reference-equality rather than object-equality. This affects the behavior of its contains, remove, containsAll, equals, and hashCode methods.

      The equals method of the returned set returns true only if the specified object is a set containing exactly the same object references as the returned set. The symmetry and transitivity requirements of the Object.equals contract may be violated if the set returned by this method is compared to a normal set. However, the Object.equals contract is guaranteed to hold among sets returned by this method.

      The hashCode method of the returned set returns the sum of the identity hashcodes of the elements in the set, rather than the sum of their hashcodes. This is mandated by the change in the semantics of the equals method, in order to enforce the general contract of the Object.hashCode method among sets returned by this method.

      Specified by:
      iterator in interface Collection<K>
      Specified by:
      iterator in interface Iterable<K>
      Specified by:
      iterator in interface Set<K>
      Specified by:
      iterator in class AbstractCollection<K>
      Returns:
      an identity-based set view of the keys contained in this map
      See Also:
    • add

      public boolean add(@NonNull K key)
      Associates the specified value with the specified key in this identity hash map. If the map previously contained a mapping for the key, the old value is replaced.
      Specified by:
      add in interface Collection<K>
      Specified by:
      add in interface Set<K>
      Overrides:
      add in class AbstractCollection<K>
      Parameters:
      key - the key with which the specified value is to be associated
      Returns:
      the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
      See Also:
    • putAll

      public void putAll(Set<? extends K> m)
      Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
      Parameters:
      m - mappings to be stored in this map
      Throws:
      NullPointerException - if the specified map is null
    • remove

      public boolean remove(@Nullable Object key)
      Removes the mapping for this key from this map if present.
      Specified by:
      remove in interface Collection<K>
      Specified by:
      remove in interface Set<K>
      Overrides:
      remove in class AbstractCollection<K>
      Parameters:
      key - key whose mapping is to be removed from the map
      Returns:
      true, otherwise false if there was no mapping for key.
    • containsAll

      public boolean containsAll(@NonNull Collection<?> c)
      Specified by:
      containsAll in interface Collection<K>
      Specified by:
      containsAll in interface Set<K>
      Overrides:
      containsAll in class AbstractCollection<K>
    • addAll

      public boolean addAll(@NonNull Collection<? extends K> c)
      Specified by:
      addAll in interface Collection<K>
      Specified by:
      addAll in interface Set<K>
      Overrides:
      addAll in class AbstractCollection<K>
    • retainAll

      public boolean retainAll(@NonNull Collection<?> c)
      Specified by:
      retainAll in interface Collection<K>
      Specified by:
      retainAll in interface Set<K>
      Overrides:
      retainAll in class AbstractCollection<K>
    • toString

      public String toString()
      Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("QuantumIdentityHashSet[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object).
      Overrides:
      toString in class AbstractCollection<K>
      Returns:
      a string representation of this collection
    • clear

      public void clear()
      Removes all of the mappings from this map. The map will be empty after this call returns.
      Specified by:
      clear in interface Collection<K>
      Specified by:
      clear in interface Set<K>
      Overrides:
      clear in class AbstractCollection<K>
    • clone

      public Object clone()
      Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.
      Overrides:
      clone in class Object
      Returns:
      a shallow copy of this map
    • removeAll

      public boolean removeAll(@NonNull Collection<?> c)
      Specified by:
      removeAll in interface Collection<K>
      Specified by:
      removeAll in interface Set<K>
      Overrides:
      removeAll in class AbstractSet<K>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<K>
      Specified by:
      toArray in interface Set<K>
      Overrides:
      toArray in class AbstractCollection<K>
    • toArray

      public <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<K>
      Specified by:
      toArray in interface Set<K>
      Overrides:
      toArray in class AbstractCollection<K>
    • spliterator

      public Spliterator<K> spliterator()
      Specified by:
      spliterator in interface Collection<K>
      Specified by:
      spliterator in interface Iterable<K>
      Specified by:
      spliterator in interface Set<K>
    • forEach

      public void forEach(Consumer<? super K> action)
      Specified by:
      forEach in interface Iterable<K>