Class EquivalentHashSet<E>

  • All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

    public class EquivalentHashSet<E>
    extends java.util.AbstractSet<E>
    Deprecated.
    Custom hash-based set which accepts no null values, where equality and hash code calculations are done based on passed Equivalence function implementations for values, as opposed to relying on their own equals/hashCode/toString implementations. This is handy when using key/values whose mentioned methods cannot be overriden, i.e. arrays, and in situations where users want to avoid using wrapper objects.
    Since:
    5.3
    Author:
    Galder ZamarreƱo
    • Constructor Summary

      Constructors 
      Constructor Description
      EquivalentHashSet​(int initialCapacity, Equivalence<? super E> entryEq)
      Deprecated.
      Constructs a new, empty set, with a given initial capacity and a particular equivalence function to compare entries.
      EquivalentHashSet​(Equivalence<? super E> entryEq)
      Deprecated.
      Constructs a new, empty set, with a given equivalence function
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean add​(E o)
      Deprecated.
      Adds the specified element to this set if it is not already present.
      void clear()
      Deprecated.
      Removes all of the elements from this set.
      boolean contains​(java.lang.Object o)
      Deprecated.
      Returns true if this set contains the specified element.
      int hashCode()
      Deprecated.
      Returns the hash code value for this set using the Equivalence function associated with it.
      boolean isEmpty()
      Deprecated.
      Returns true if this set contains no elements.
      java.util.Iterator<E> iterator()
      Deprecated.
      Returns an iterator over the elements in this set.
      boolean remove​(java.lang.Object o)
      Deprecated.
      Removes the specified element from this set if it is present.
      int size()
      Deprecated.
      Returns the number of elements in this set.
      • Methods inherited from class java.util.AbstractSet

        equals, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, retainAll, spliterator, toArray, toArray
    • Constructor Detail

      • EquivalentHashSet

        public EquivalentHashSet​(Equivalence<? super E> entryEq)
        Deprecated.
        Constructs a new, empty set, with a given equivalence function
        Parameters:
        entryEq - the Equivalence function to be used to compare entries in this set.
      • EquivalentHashSet

        public EquivalentHashSet​(int initialCapacity,
                                 Equivalence<? super E> entryEq)
        Deprecated.
        Constructs a new, empty set, with a given initial capacity and a particular equivalence function to compare entries.
        Parameters:
        initialCapacity - this set's initial capacity
        entryEq - the Equivalence function to be used to compare entries in this set.
    • Method Detail

      • iterator

        public java.util.Iterator<E> iterator()
        Deprecated.
        Returns an iterator over the elements in this set.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
        Returns:
        an iterator over the elements in this set
      • size

        public int size()
        Deprecated.
        Returns the number of elements in this set. If this set contains more than Integer.MAX_VALUE elements, it returns Integer.MAX_VALUE.
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
        Returns:
        the number of elements in this set
      • isEmpty

        public boolean isEmpty()
        Deprecated.
        Returns true if this set contains no elements.
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.Set<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
        Returns:
        true if this set contains no elements
      • contains

        public boolean contains​(java.lang.Object o)
        Deprecated.
        Returns true if this set contains the specified element.
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Set<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
        Parameters:
        o - the object to be checked for containment in this set
        Returns:
        true if this set contains the specified element
      • add

        public boolean add​(E o)
        Deprecated.
        Adds the specified element to this set if it is not already present.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
        Parameters:
        o - element to be added to this set
        Returns:
        true if the set did not already contain the specified element
      • remove

        public boolean remove​(java.lang.Object o)
        Deprecated.
        Removes the specified element from this set if it is present.
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
        Parameters:
        o - object to be removed from this set, if present
        Returns:
        true if the set contained the specified element
      • clear

        public void clear()
        Deprecated.
        Removes all of the elements from this set.
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.Set<E>
        Overrides:
        clear in class java.util.AbstractCollection<E>
      • hashCode

        public int hashCode()
        Deprecated.
        Returns the hash code value for this set using the Equivalence function associated with it. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero. This ensures that Equivalence.equals(Object s1, Object s2) implies that Equivalence.hashCode(Object s1)==Equivalence.hashCode(Object s2) for any two sets s1 and s2, as required by the general contract of Object.hashCode().

        This implementation iterates over the set, calling the hashCode method on each element in the set, and adding up the results.

        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.Set<E>
        Overrides:
        hashCode in class java.util.AbstractSet<E>
        Returns:
        the hash code value for this set