org.glassfish.grizzly.utils
Class ArraySet<T>

java.lang.Object
  extended by org.glassfish.grizzly.utils.ArraySet<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>

public class ArraySet<T>
extends java.lang.Object
implements java.util.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 Summary
ArraySet(java.lang.Class<T> clazz)
           
 
Method Summary
 boolean add(ArraySet<T> source)
          Add all the elements from the source ArraySet.
 boolean add(T e)
          
 boolean addAll(java.util.Collection<? extends T> collection)
          
 boolean addAll(T... elements)
          Add the element(s) to the set.
 void clear()
          Remove all the set elements.
 boolean contains(java.lang.Object o)
          
 boolean containsAll(java.util.Collection<?> collection)
          
 T[] getArray()
          Get the underlying array.
 T[] getArrayCopy()
          Get the copy of the underlying array.
 boolean isEmpty()
          
 java.util.Iterator<T> iterator()
          
 T[] obtainArrayCopy()
          Get the copy of the underlying array.
 boolean remove(java.lang.Object o)
          
 boolean removeAll(java.util.Collection<?> collection)
          
 boolean removeAll(java.lang.Object... elements)
          Remove element(s) from the set.
 boolean retainAll(java.util.Collection<?> collection)
          
 int size()
          
 java.lang.Object[] toArray()
          
<K> K[]
toArray(K[] a)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

ArraySet

public ArraySet(java.lang.Class<T> clazz)
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.

addAll

public boolean addAll(java.util.Collection<? extends T> collection)

Specified by:
addAll in interface java.util.Collection<T>
Specified by:
addAll in interface java.util.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(java.lang.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 java.util.Collection<T>
Specified by:
clear in interface java.util.Set<T>

size

public int size()

Specified by:
size in interface java.util.Collection<T>
Specified by:
size in interface java.util.Set<T>

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Collection<T>
Specified by:
isEmpty in interface java.util.Set<T>

add

public boolean add(T e)

Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.Set<T>

contains

public boolean contains(java.lang.Object o)

Specified by:
contains in interface java.util.Collection<T>
Specified by:
contains in interface java.util.Set<T>

toArray

public java.lang.Object[] toArray()

Specified by:
toArray in interface java.util.Collection<T>
Specified by:
toArray in interface java.util.Set<T>

toArray

public <K> K[] toArray(K[] a)

Specified by:
toArray in interface java.util.Collection<T>
Specified by:
toArray in interface java.util.Set<T>

remove

public boolean remove(java.lang.Object o)

Specified by:
remove in interface java.util.Collection<T>
Specified by:
remove in interface java.util.Set<T>

containsAll

public boolean containsAll(java.util.Collection<?> collection)

Specified by:
containsAll in interface java.util.Collection<T>
Specified by:
containsAll in interface java.util.Set<T>

retainAll

public boolean retainAll(java.util.Collection<?> collection)

Specified by:
retainAll in interface java.util.Collection<T>
Specified by:
retainAll in interface java.util.Set<T>

removeAll

public boolean removeAll(java.util.Collection<?> collection)

Specified by:
removeAll in interface java.util.Collection<T>
Specified by:
removeAll in interface java.util.Set<T>

iterator

public java.util.Iterator<T> iterator()

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface java.util.Collection<T>
Specified by:
iterator in interface java.util.Set<T>


Copyright © 2011 Oracle Corpration. All Rights Reserved.