Package org.glassfish.grizzly.utils
Class ArraySet<T>
- java.lang.Object
-
- 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(ArraySet<T> source)Add all the elements from the source ArraySet.booleanadd(T element)booleanaddAll(java.util.Collection<? extends T> collection)booleanaddAll(T... elements)Add the element(s) to the set.voidclear()Remove all the set elements.booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> collection)T[]getArray()Get the underlying array.T[]getArrayCopy()Get the copy of the underlying array.booleanisEmpty()java.util.Iterator<T>iterator()T[]obtainArrayCopy()Get the copy of the underlying array.booleanremove(java.lang.Object o)booleanremoveAll(java.lang.Object... elements)Remove element(s) from the set.booleanremoveAll(java.util.Collection<?> collection)booleanretainAll(java.util.Collection<?> collection)intsize()java.lang.Object[]toArray()<K> K[]toArray(K[] a)
-
-
-
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)
-
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 useadd(Object)andremove(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.
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
add
public boolean add(T element)
-
contains
public boolean contains(java.lang.Object o)
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <K> K[] toArray(K[] a)
-
remove
public boolean remove(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> collection)
-
retainAll
public boolean retainAll(java.util.Collection<?> collection)
-
removeAll
public boolean removeAll(java.util.Collection<?> collection)
-
-