Class ArraySet<T>

  • All Implemented Interfaces:
    Iterable<T>, Collection<T>, Set<T>

    public class ArraySet<T>
    extends Object
    implements Set<T>
    The thread safe set implementation, which uses array to hold its elements. This set could be used, for cases, which require minimum set modifications.
    Author:
    Alexey Stashok
    • Constructor Detail

      • ArraySet

        public ArraySet​(Class<T> clazz)
      • ArraySet

        public ArraySet​(Class<T> clazz,
                        boolean replaceElementIfEquals)
    • Method Detail

      • addAll

        public final boolean addAll​(T... elements)
        Add the element(s) to the set.
        Parameters:
        elements - the elements to add.
        Returns:
        true, if at least one element was added to the set and, as result, the size of the set was increased, or false, all element(s) was/were present in the set and, as the result, the set values were just reset.
      • add

        public final boolean add​(ArraySet<T> source)
        Add all the elements from the source ArraySet.
        Parameters:
        source - the elements to add.
        Returns:
        true, if at least one element was added to the set and, as result, the size of the set was increased, or false, all element(s) was/were present in the set and, as the result, the set values were just reset.
      • removeAll

        public final boolean removeAll​(Object... elements)
        Remove element(s) from the set.
        Parameters:
        elements - the element(s) to remove.
        Returns:
        true, if at least one element was found and removed, or false otherwise.
      • getArray

        public final T[] getArray()
        Get the underlying array. Please note, it's not appropriate to modify the returned array's content. Please use add(Object) and remove(Object) instead.
        Returns:
        the array.
      • getArrayCopy

        public final T[] getArrayCopy()
        Get the copy of the underlying array. If the underlying array is null - then null will be returned.
        Returns:
        the copy of the underlying array. If the underlying array is null - then null will be returned.
      • obtainArrayCopy

        public final T[] obtainArrayCopy()
        Get the copy of the underlying array. If the underlying array is null - then empty array will be returned.
        Returns:
        the copy of the underlying array. If the underlying array is null - then empty array will be returned.
      • clear

        public void clear()
        Remove all the set elements.
        Specified by:
        clear in interface Collection<T>
        Specified by:
        clear in interface Set<T>
      • size

        public int size()
        Specified by:
        size in interface Collection<T>
        Specified by:
        size in interface Set<T>
      • add

        public boolean add​(T element)
        Specified by:
        add in interface Collection<T>
        Specified by:
        add in interface Set<T>