Package com.jogamp.common.util
Class ArrayHashSet<E>
- java.lang.Object
-
- com.jogamp.common.util.ArrayHashSet<E>
-
- All Implemented Interfaces:
Cloneable
,Iterable<E>
,Collection<E>
,List<E>
public class ArrayHashSet<E> extends Object implements Cloneable, Collection<E>, List<E>
Hashed ArrayList implementation of the List and Collection interface. Implementation properties are:- Unique elements utilizing
Object.hashCode()
for O(1) operations, see below. - Provides
List
functionality, ieList.indexOf(java.lang.Object)
andList.get(int)
, hence object identity can be implemented. - Object identity via
get(java.lang.Object)
- Java 1.5 compatible
- adding new element(s)
- test for containment
- identity
- trying to remove non existent elements
- removing existing elements
RecursiveLock
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_INITIAL_CAPACITY
The default initial capacity: 16static float
DEFAULT_LOAD_FACTOR
Default load factor: 0.75f
-
Constructor Summary
Constructors Constructor Description ArrayHashSet(boolean supportNullValue, int initialCapacity, float loadFactor)
ArrayHashSet(ArrayHashSet<E> o)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
Add element at the given index in this list, if it is not contained yet.boolean
add(E element)
Add element at the end of this list, if it is not contained yet.boolean
addAll(int index, Collection<? extends E> c)
boolean
addAll(Collection<? extends E> c)
Add all elements of givenCollection
at the end of this list.void
clear()
Object
clone()
boolean
contains(Object element)
Test for containment
This is an O(1) operation.boolean
containsAll(Collection<?> c)
Test for containment of givenCollection
This is an O(n) operation, over the given Collection size.boolean
containsSafe(Object element)
Test for containment
This is an O(n) operation, using equals operation over the list.boolean
equals(Object arrayHashSet)
This is an O(n) operation.E
get(int index)
E
get(Object element)
Identity method allowing to get the identical object, using the internal hash map.ArrayList<E>
getData()
Returns this object ordered ArrayList.HashMap<E,E>
getMap()
Returns this object hash map.E
getOrAdd(E element)
Identity method allowing to get the identical object, using the internal hash map.
If theelement
is not yet contained, add it.int
hashCode()
This is an O(n) operation over the size of this list.int
indexOf(Object element)
boolean
isEmpty()
Iterator<E>
iterator()
int
lastIndexOf(Object o)
Since this list is unique, equivalent toindexOf(java.lang.Object)
.ListIterator<E>
listIterator()
ListIterator<E>
listIterator(int index)
E
remove(int index)
Remove element at given index from this list.boolean
remove(Object element)
Remove element from this list.boolean
removeAll(Collection<?> c)
Remove all elements of givenCollection
from this list.boolean
retainAll(Collection<?> c)
Retain all elements of the givenCollection
c, ie remove all elements not contained by the givenCollection
c.E
set(int index, E element)
int
size()
List<E>
subList(int fromIndex, int toIndex)
boolean
supportsNullValue()
Returnstrue
for default behavior, i.e.Object[]
toArray()
<T> T[]
toArray(T[] a)
ArrayList<E>
toArrayList()
String
toString()
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
-
-
-
Field Detail
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTOR
Default load factor: 0.75f- See Also:
- Constant Field Values
-
DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_INITIAL_CAPACITY
The default initial capacity: 16- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ArrayHashSet
public ArrayHashSet(boolean supportNullValue, int initialCapacity, float loadFactor)
- Parameters:
supportNullValue
- Usetrue
for default behavior, i.e.null
can be a valid value. Usefalse
ifnull
is not a valid value, here#remove(E)
andgetOrAdd(Object)
will be optimized.initialCapacity
- useDEFAULT_INITIAL_CAPACITY
for defaultloadFactor
- useDEFAULT_LOAD_FACTOR
for default- See Also:
supportsNullValue()
-
ArrayHashSet
public ArrayHashSet(ArrayHashSet<E> o)
-
-
Method Detail
-
supportsNullValue
public final boolean supportsNullValue()
Returnstrue
for default behavior, i.e.null
can be a valid value.Returns
false
ifnull
is not a valid value, here#remove(E)
andgetOrAdd(Object)
are optimized operations.- See Also:
ArrayHashSet(boolean, int, float)
-
clone
public final Object clone()
-
getData
public final ArrayList<E> getData()
Returns this object ordered ArrayList. Use w/ care, it's not a copy.
-
getMap
public final HashMap<E,E> getMap()
Returns this object hash map. Use w/ care, it's not a copy.
-
clear
public final void clear()
-
add
public final boolean add(E element) throws NullPointerException
Add element at the end of this list, if it is not contained yet.
This is an O(1) operation- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Returns:
- true if the element was added to this list, otherwise false (already contained).
- Throws:
NullPointerException
- ifelement
isnull
butsupportsNullValue()
==false
-
remove
public final boolean remove(Object element) throws NullPointerException
Remove element from this list.
This is an O(1) operation, in case the element does not exist, otherwise O(n).- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Returns:
- true if the element was removed from this list, otherwise false (not contained).
- Throws:
NullPointerException
- ifelement
isnull
butsupportsNullValue()
==false
-
addAll
public final boolean addAll(Collection<? extends E> c)
Add all elements of givenCollection
at the end of this list.
This is an O(n) operation, over the given Collection size.
-
contains
public final boolean contains(Object element)
Test for containment
This is an O(1) operation.
-
containsAll
public final boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
- Returns:
- true if the given Collection is completly contained by this list using hash map, otherwise false.
-
removeAll
public final boolean removeAll(Collection<?> c)
-
retainAll
public final boolean retainAll(Collection<?> c)
Retain all elements of the givenCollection
c, ie remove all elements not contained by the givenCollection
c.
This is an O(n) operation.
-
equals
public final boolean equals(Object arrayHashSet)
This is an O(n) operation.
-
hashCode
public final int hashCode()
This is an O(n) operation over the size of this list.- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceList<E>
- Overrides:
hashCode
in classObject
- Returns:
- the hash code of this list as define in
List.hashCode()
, ie hashing all elements of this list.
-
isEmpty
public final boolean isEmpty()
-
size
public final int size()
-
toArray
public final Object[] toArray()
-
toArray
public final <T> T[] toArray(T[] a)
-
add
public final void add(int index, E element) throws IllegalArgumentException, NullPointerException
Add element at the given index in this list, if it is not contained yet.
This is an O(1) operation- Specified by:
add
in interfaceList<E>
- Throws:
IllegalArgumentException
- if the given element was already containedNullPointerException
- ifelement
isnull
butsupportsNullValue()
==false
-
addAll
public final boolean addAll(int index, Collection<? extends E> c) throws UnsupportedOperationException
- Specified by:
addAll
in interfaceList<E>
- Throws:
UnsupportedOperationException
-
remove
public final E remove(int index)
Remove element at given index from this list.
This is an O(n) operation.
-
lastIndexOf
public final int lastIndexOf(Object o)
- Specified by:
lastIndexOf
in interfaceList<E>
- Returns:
- index of element, or -1 if not found
-
listIterator
public final ListIterator<E> listIterator()
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
public final ListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interfaceList<E>
-
toArrayList
public final ArrayList<E> toArrayList()
- Returns:
- a shallow copy of this ArrayHashSet's ArrayList, elements are not copied.
-
get
public final E get(Object element)
Identity method allowing to get the identical object, using the internal hash map.
This is an O(1) operation.- Parameters:
element
- hash source to find the identical Object within this list- Returns:
- object from this list, identical to the given
key
hash code, or null if not contained
-
getOrAdd
public final E getOrAdd(E element) throws NullPointerException
Identity method allowing to get the identical object, using the internal hash map.
If theelement
is not yet contained, add it.
This is an O(1) operation.- Parameters:
element
- hash source to find the identical Object within this list- Returns:
- object from this list, identical to the given
key
hash code, or add the givenkey
and return it. - Throws:
NullPointerException
- ifelement
isnull
butsupportsNullValue()
==false
-
containsSafe
public final boolean containsSafe(Object element)
Test for containment
This is an O(n) operation, using equals operation over the list.
You may utilize this method to verify your hash values,
iecontains(java.lang.Object)
andcontainsSafe(java.lang.Object)
shall have the same result.- Returns:
- true if the given element is contained by this list using slow equals operation, otherwise false.
-
-