Package org.glassfish.grizzly.utils
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(ArraySet<T> source)
Add all the elements from the source ArraySet.boolean
add(T element)
boolean
addAll(Collection<? extends T> collection)
boolean
addAll(T... elements)
Add the element(s) to the set.void
clear()
Remove all the set elements.boolean
contains(Object o)
boolean
containsAll(Collection<?> collection)
T[]
getArray()
Get the underlying array.T[]
getArrayCopy()
Get the copy of the underlying array.boolean
isEmpty()
Iterator<T>
iterator()
T[]
obtainArrayCopy()
Get the copy of the underlying array.boolean
remove(Object o)
boolean
removeAll(Object... elements)
Remove element(s) from the set.boolean
removeAll(Collection<?> collection)
boolean
retainAll(Collection<?> collection)
int
size()
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.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
-
-
-
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(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(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(Object o)
-
toArray
public Object[] toArray()
-
toArray
public <K> K[] toArray(K[] a)
-
remove
public boolean remove(Object o)
-
containsAll
public boolean containsAll(Collection<?> collection)
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceSet<T>
-
retainAll
public boolean retainAll(Collection<?> collection)
-
removeAll
public boolean removeAll(Collection<?> collection)
-
-