Class ArrayHashSet<E>

    • Field Detail

      • DEFAULT_LOAD_FACTOR

        public static final float DEFAULT_LOAD_FACTOR
        Default load factor: 0.75f
        See Also:
        Constant Field Values
      • DEFAULT_INITIAL_CAPACITY

        public static final int DEFAULT_INITIAL_CAPACITY
        The default initial capacity: 16
        See Also:
        Constant Field Values
    • Constructor Detail

      • ArrayHashSet

        public ArrayHashSet​(boolean supportNullValue,
                            int initialCapacity,
                            float loadFactor)
        Parameters:
        supportNullValue - Use true for default behavior, i.e. null can be a valid value. Use false if null is not a valid value, here #remove(E) and getOrAdd(Object) will be optimized.
        initialCapacity - use DEFAULT_INITIAL_CAPACITY for default
        loadFactor - use DEFAULT_LOAD_FACTOR for default
        See Also:
        supportsNullValue()
    • Method Detail

      • supportsNullValue

        public final boolean supportsNullValue()
        Returns true for default behavior, i.e. null can be a valid value.

        Returns false if null is not a valid value, here #remove(E) and getOrAdd(Object) are optimized operations.

        See Also:
        ArrayHashSet(boolean, int, float)
      • clone

        public final Object clone()
        Overrides:
        clone in class Object
        Returns:
        a shallow copy of this ArrayHashSet, elements are not copied.
      • getData

        public final ArrayList<E> getData()
        Returns this object ordered ArrayList. Use w/ care, it's not a copy.
      • getMap

        public final HashMap<E,​E> getMap()
        Returns this object hash map. Use w/ care, it's not a copy.
      • add

        public final boolean add​(E element)
                          throws NullPointerException
        Add element at the end of this list, if it is not contained yet.
        This is an O(1) operation

        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface List<E>
        Returns:
        true if the element was added to this list, otherwise false (already contained).
        Throws:
        NullPointerException - if element is null but supportsNullValue() == false
      • addAll

        public final boolean addAll​(Collection<? extends E> c)
        Add all elements of given Collection at the end of this list.
        This is an O(n) operation, over the given Collection size.

        Specified by:
        addAll in interface Collection<E>
        Specified by:
        addAll in interface List<E>
        Returns:
        true if at least one element was added to this list, otherwise false (completely container).
      • contains

        public final boolean contains​(Object element)
        Test for containment
        This is an O(1) operation.

        Specified by:
        contains in interface Collection<E>
        Specified by:
        contains in interface List<E>
        Returns:
        true if the given element is contained by this list using fast hash map, otherwise false.
      • containsAll

        public final boolean containsAll​(Collection<?> c)
        Test for containment of given Collection
        This is an O(n) operation, over the given Collection size.

        Specified by:
        containsAll in interface Collection<E>
        Specified by:
        containsAll in interface List<E>
        Returns:
        true if the given Collection is completly contained by this list using hash map, otherwise false.
      • removeAll

        public final boolean removeAll​(Collection<?> c)
        Remove all elements of given Collection from this list.
        This is an O(n) operation.

        Specified by:
        removeAll in interface Collection<E>
        Specified by:
        removeAll in interface List<E>
        Returns:
        true if at least one element of this list was removed, otherwise false.
      • retainAll

        public final boolean retainAll​(Collection<?> c)
        Retain all elements of the given Collection c, ie remove all elements not contained by the given Collection c.
        This is an O(n) operation.

        Specified by:
        retainAll in interface Collection<E>
        Specified by:
        retainAll in interface List<E>
        Returns:
        true if at least one element of this list was removed, otherwise false.
      • equals

        public final boolean equals​(Object arrayHashSet)
        This is an O(n) operation.

        Specified by:
        equals in interface Collection<E>
        Specified by:
        equals in interface List<E>
        Overrides:
        equals in class Object
        Returns:
        true if arrayHashSet is of type ArrayHashSet and all entries are equal Performance: arrayHashSet(1)
      • hashCode

        public final int hashCode()
        This is an O(n) operation over the size of this list.

        Specified by:
        hashCode in interface Collection<E>
        Specified by:
        hashCode in interface List<E>
        Overrides:
        hashCode in class Object
        Returns:
        the hash code of this list as define in List.hashCode(), ie hashing all elements of this list.
      • size

        public final int size()
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in interface List<E>
      • get

        public final E get​(int index)
        Specified by:
        get in interface List<E>
      • indexOf

        public final int indexOf​(Object element)
        Specified by:
        indexOf in interface List<E>
      • set

        public final E set​(int index,
                           E element)

        Specified by:
        set in interface List<E>
      • remove

        public final E remove​(int index)
        Remove element at given index from this list.
        This is an O(n) operation.

        Specified by:
        remove in interface List<E>
        Returns:
        the removed object
      • lastIndexOf

        public final int lastIndexOf​(Object o)
        Since this list is unique, equivalent to indexOf(java.lang.Object).
        This is an O(n) operation.

        Specified by:
        lastIndexOf in interface List<E>
        Returns:
        index of element, or -1 if not found
      • subList

        public final List<E> subList​(int fromIndex,
                                     int toIndex)
        Specified by:
        subList in interface List<E>
      • toArrayList

        public final ArrayList<E> toArrayList()
        Returns:
        a shallow copy of this ArrayHashSet's ArrayList, elements are not copied.
      • get

        public final E get​(Object element)
        Identity method allowing to get the identical object, using the internal hash map.
        This is an O(1) operation.
        Parameters:
        element - hash source to find the identical Object within this list
        Returns:
        object from this list, identical to the given key hash code, or null if not contained
      • getOrAdd

        public final E getOrAdd​(E element)
                         throws NullPointerException
        Identity method allowing to get the identical object, using the internal hash map.
        If the element is not yet contained, add it.
        This is an O(1) operation.
        Parameters:
        element - hash source to find the identical Object within this list
        Returns:
        object from this list, identical to the given key hash code, or add the given key and return it.
        Throws:
        NullPointerException - if element is null but supportsNullValue() == false
      • containsSafe

        public final boolean containsSafe​(Object element)
        Test for containment
        This is an O(n) operation, using equals operation over the list.
        You may utilize this method to verify your hash values,
        ie contains(java.lang.Object) and containsSafe(java.lang.Object) shall have the same result.
        Returns:
        true if the given element is contained by this list using slow equals operation, otherwise false.