Class ArraySet<T>

java.lang.Object
org.glassfish.grizzly.utils.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 Details

    • ArraySet

      public ArraySet(Class<T> clazz)
    • ArraySet

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

    • 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.
    • addAll

      public boolean addAll(Collection<? extends T> collection)
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Set<T>
    • 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>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
      Specified by:
      isEmpty in interface Set<T>
    • add

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

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<T>
      Specified by:
      contains in interface Set<T>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface Set<T>
    • toArray

      public <K> K[] toArray(K[] a)
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface Set<T>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface Set<T>
    • containsAll

      public boolean containsAll(Collection<?> collection)
      Specified by:
      containsAll in interface Collection<T>
      Specified by:
      containsAll in interface Set<T>
    • retainAll

      public boolean retainAll(Collection<?> collection)
      Specified by:
      retainAll in interface Collection<T>
      Specified by:
      retainAll in interface Set<T>
    • removeAll

      public boolean removeAll(Collection<?> collection)
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface Set<T>
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Set<T>