Class TCustomHashSet<E>

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

    public class TCustomHashSet<E>
    extends TCustomObjectHash<E>
    implements java.util.Set<E>, java.lang.Iterable<E>, java.io.Externalizable
    An implementation of the Set interface that uses an open-addressed hash table to store its contents.
    See Also:
    Serialized Form
    • Constructor Detail

      • TCustomHashSet

        public TCustomHashSet()
        FOR EXTERNALIZATION ONLY!!!
      • TCustomHashSet

        public TCustomHashSet​(HashingStrategy<? super E> strategy)
        Creates a new THashSet instance with the default capacity and load factor.
      • TCustomHashSet

        public TCustomHashSet​(HashingStrategy<? super E> strategy,
                              int initialCapacity)
        Creates a new THashSet instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.
        Parameters:
        initialCapacity - an int value
      • TCustomHashSet

        public TCustomHashSet​(HashingStrategy<? super E> strategy,
                              int initialCapacity,
                              float loadFactor)
        Creates a new THashSet instance with a prime capacity equal to or greater than initialCapacity and with the specified load factor.
        Parameters:
        initialCapacity - an int value
        loadFactor - a float value
      • TCustomHashSet

        public TCustomHashSet​(HashingStrategy<? super E> strategy,
                              java.util.Collection<? extends E> collection)
        Creates a new THashSet instance containing the elements of collection.
        Parameters:
        collection - a Collection value
    • Method Detail

      • add

        public boolean add​(E obj)
        Inserts a value into the set.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Parameters:
        obj - an Object value
        Returns:
        true if the set was modified by the add operation
      • equals

        public boolean equals​(java.lang.Object other)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface java.util.Set<E>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.Set<E>
        Overrides:
        hashCode in class java.lang.Object
      • rehash

        protected void rehash​(int newCapacity)
        Expands the set to accommodate new values.
        Specified by:
        rehash in class THash
        Parameters:
        newCapacity - an int value
      • toArray

        public java.lang.Object[] toArray()
        Returns a new array containing the objects in the set.
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.Set<E>
        Returns:
        an Object[] value
      • toArray

        public <T> T[] toArray​(T[] a)
        Returns a typed array of the objects in the set.
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.Set<E>
        Parameters:
        a - an Object[] value
        Returns:
        an Object[] value
      • clear

        public void clear()
        Empties the set.
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.Set<E>
        Overrides:
        clear in class THash
      • remove

        public boolean remove​(java.lang.Object obj)
        Removes obj from the set.
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Parameters:
        obj - an Object value
        Returns:
        true if the set was modified by the remove operation.
      • iterator

        public TObjectHashIterator<E> iterator()
        Creates an iterator over the values of the set. The iterator supports element deletion.
        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>
        Returns:
        an Iterator value
      • containsAll

        public boolean containsAll​(java.util.Collection<?> collection)
        Tests the set to determine if all of the elements in collection are present.
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface java.util.Set<E>
        Parameters:
        collection - a Collection value
        Returns:
        true if all elements were present in the set.
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> collection)
        Adds all of the elements in collection to the set.
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.Set<E>
        Parameters:
        collection - a Collection value
        Returns:
        true if the set was modified by the add all operation.
      • removeAll

        public boolean removeAll​(java.util.Collection<?> collection)
        Removes all of the elements in collection from the set.
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.Set<E>
        Parameters:
        collection - a Collection value
        Returns:
        true if the set was modified by the remove all operation.
      • retainAll

        public boolean retainAll​(java.util.Collection<?> collection)
        Removes any values in the set which are not contained in collection.
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.Set<E>
        Parameters:
        collection - a Collection value
        Returns:
        true if the set was modified by the retain all operation
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class TCustomObjectHash<E>
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class TCustomObjectHash<E>
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException