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>
Hashed ArrayList implementation of the List and Collection interface.
Implementation properties are:
- Unique elements utilizing
Object.hashCode()for O(1) operations, see below. - Provides
Listfunctionality, 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
FieldsModifier and TypeFieldDescriptionstatic final intThe default initial capacity: 16static final floatDefault load factor: 0.75f -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.ArrayHashSet(boolean supportNullValue, int initialCapacity, float loadFactor) ArrayHashSet(int initialCapacity) Deprecated.ArrayHashSet(int initialCapacity, float loadFactor) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd element at the given index in this list, if it is not contained yet.final booleanAdd element at the end of this list, if it is not contained yet.final booleanaddAll(int index, Collection<? extends E> c) final booleanaddAll(Collection<? extends E> c) Add all elements of givenCollectionat the end of this list.final voidclear()final Objectclone()final booleanTest for containment
This is an O(1) operation.final booleancontainsAll(Collection<?> c) Test for containment of givenCollection
This is an O(n) operation, over the given Collection size.final booleancontainsSafe(Object element) Test for containment
This is an O(n) operation, using equals operation over the list.final booleanThis is an O(n) operation.final Eget(int index) final EIdentity method allowing to get the identical object, using the internal hash map.getData()Returns this object ordered ArrayList.getMap()Returns this object hash map.final EIdentity method allowing to get the identical object, using the internal hash map.
If theelementis not yet contained, add it.final inthashCode()This is an O(n) operation over the size of this list.final intfinal booleanisEmpty()iterator()final intSince this list is unique, equivalent toindexOf(java.lang.Object).final ListIterator<E>final ListIterator<E>listIterator(int index) final Eremove(int index) Remove element at given index from this list.final booleanRemove element from this list.final booleanremoveAll(Collection<?> c) Remove all elements of givenCollectionfrom this list.final booleanretainAll(Collection<?> c) Retain all elements of the givenCollectionc, ie remove all elements not contained by the givenCollectionc.final Efinal intsize()subList(int fromIndex, int toIndex) final booleanReturnstruefor default behavior, i.e.final Object[]toArray()final <T> T[]toArray(T[] a) final StringtoString()Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
replaceAll, sort, spliterator
-
Field Details
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTORDefault load factor: 0.75f- See Also:
-
DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_INITIAL_CAPACITYThe default initial capacity: 16- See Also:
-
-
Constructor Details
-
ArrayHashSet
public ArrayHashSet()Deprecated. -
ArrayHashSet
public ArrayHashSet(int initialCapacity) Deprecated.- Parameters:
initialCapacity-
-
ArrayHashSet
public ArrayHashSet(int initialCapacity, float loadFactor) Deprecated.- Parameters:
initialCapacity-loadFactor-
-
ArrayHashSet
public ArrayHashSet(boolean supportNullValue, int initialCapacity, float loadFactor) - Parameters:
supportNullValue- Usetruefor default behavior, i.e.nullcan be a valid value. Usefalseifnullis not a valid value, hereremove(E)andgetOrAdd(Object)will be optimized.initialCapacity- useDEFAULT_INITIAL_CAPACITYfor defaultloadFactor- useDEFAULT_LOAD_FACTORfor default- See Also:
-
ArrayHashSet
-
-
Method Details
-
supportsNullValue
public final boolean supportsNullValue()Returnstruefor default behavior, i.e.nullcan be a valid value.Returns
falseifnullis not a valid value, hereremove(E)andgetOrAdd(Object)are optimized operations.- See Also:
-
clone
-
getData
Returns this object ordered ArrayList. Use w/ care, it's not a copy. -
getMap
Returns this object hash map. Use w/ care, it's not a copy. -
toString
-
clear
public final void clear() -
add
Add element at the end of this list, if it is not contained yet.
This is an O(1) operation- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Returns:
- true if the element was added to this list, otherwise false (already contained).
- Throws:
NullPointerException- ifelementisnullbutsupportsNullValue()==false
-
remove
Remove element from this list.
This is an O(1) operation, in case the element does not exist, otherwise O(n).- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Returns:
- true if the element was removed from this list, otherwise false (not contained).
- Throws:
NullPointerException- ifelementisnullbutsupportsNullValue()==false
-
addAll
Add all elements of givenCollectionat the end of this list.
This is an O(n) operation, over the given Collection size. -
contains
Test for containment
This is an O(1) operation. -
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>- Returns:
- true if the given Collection is completly contained by this list using hash map, otherwise false.
-
removeAll
-
retainAll
Retain all elements of the givenCollectionc, ie remove all elements not contained by the givenCollectionc.
This is an O(n) operation. -
equals
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:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceList<E>- Overrides:
hashCodein 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() -
iterator
-
size
public final int size() -
toArray
-
toArray
public final <T> T[] toArray(T[] a) -
get
-
indexOf
-
add
Add element at the given index in this list, if it is not contained yet.
This is an O(1) operation- Specified by:
addin interfaceList<E>- Throws:
IllegalArgumentException- if the given element was already containedNullPointerException- ifelementisnullbutsupportsNullValue()==false
-
addAll
public final boolean addAll(int index, Collection<? extends E> c) throws UnsupportedOperationException - Specified by:
addAllin interfaceList<E>- Throws:
UnsupportedOperationException
-
set
-
remove
Remove element at given index from this list.
This is an O(n) operation. -
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>- Returns:
- index of element, or -1 if not found
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
subList
-
toArrayList
- Returns:
- a shallow copy of this ArrayHashSet's ArrayList, elements are not copied.
-
get
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
keyhash code, or null if not contained
-
getOrAdd
Identity method allowing to get the identical object, using the internal hash map.
If theelementis 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
keyhash code, or add the givenkeyand return it. - Throws:
NullPointerException- ifelementisnullbutsupportsNullValue()==false
-
containsSafe
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.
-
ArrayHashSet(boolean, int, float)