com.jogamp.common.util
Class ArrayHashSet

java.lang.Object
  extended by com.jogamp.common.util.ArrayHashSet
All Implemented Interfaces:
Cloneable, Iterable, Collection, List

public class ArrayHashSet
extends Object
implements Cloneable, Collection, List

Hashed ArrayList implementation of the List and Collection interface. Implementation properties are:

O(1) operations: O(n) operations: For thread safety, the application shall decorate access to instances via RecursiveLock.


Constructor Summary
ArrayHashSet()
           
 
Method Summary
 void add(int index, Object element)
          Add element at the given index in this list, if it is not contained yet.
 boolean add(Object element)
          Add element at the end of this list, if it is not contained yet.
 boolean addAll(Collection c)
          Add all elements of given Collection at the end of this list.
 boolean addAll(int index, Collection c)
           
 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 given Collection
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.
 Object get(int index)
           
 Object get(Object key)
          Identity method allowing to get the identical object, using the internal hash map.
 Object getOrAdd(Object key)
          Identity method allowing to get the identical object, using the internal hash map.
If the key 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 iterator()
           
 int lastIndexOf(Object o)
          Since this list is unique, equivalent to indexOf(java.lang.Object).
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 Object 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 given Collection from this list.
 boolean retainAll(Collection c)
          Retain all elements of the given Collection c, ie remove all elements not contained by the given Collection c.
 Object set(int index, Object element)
           
 int size()
           
 List subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 ArrayList toArrayList()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayHashSet

public ArrayHashSet()
Method Detail

clone

public final Object clone()
Overrides:
clone in class Object
Returns:
a shallow copy of this ArrayHashSet, elements are not copied.

clear

public final void clear()
Specified by:
clear in interface Collection
Specified by:
clear in interface List

add

public final boolean add(Object element)
Add element at the end of this list, if it is not contained yet.
This is an O(1) operation

Specified by:
add in interface Collection
Specified by:
add in interface List
Returns:
true if the element was added to this list, otherwise false (already contained).

remove

public final boolean remove(Object element)
Remove element from this list.
This is an O(1) operation, in case it does not exist, otherwise O(n).

Specified by:
remove in interface Collection
Specified by:
remove in interface List
Returns:
true if the element was removed from this list, otherwise false (not contained).

addAll

public final boolean addAll(Collection c)
Add all elements of given Collection at the end of this list.
This is an O(n) operation, over the given Collection size.

Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
Returns:
true if at least one element was added to this list, otherwise false (completely container).

contains

public final boolean contains(Object element)
Test for containment
This is an O(1) operation.

Specified by:
contains in interface Collection
Specified by:
contains in interface List
Returns:
true if the given element is contained by this list using fast hash map, otherwise false.

containsAll

public final boolean containsAll(Collection c)
Test for containment of given Collection
This is an O(n) operation, over the given Collection size.

Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface List
Returns:
true if the given Collection is completly contained by this list using hash map, otherwise false.

removeAll

public final boolean removeAll(Collection c)
Remove all elements of given Collection from this list.
This is an O(n) operation.

Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List
Returns:
true if at least one element of this list was removed, otherwise false.

retainAll

public final boolean retainAll(Collection c)
Retain all elements of the given Collection c, ie remove all elements not contained by the given Collection c.
This is an O(n) operation.

Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface List
Returns:
true if at least one element of this list was removed, otherwise false.

equals

public final boolean equals(Object arrayHashSet)
This is an O(n) operation.

Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class Object
Returns:
true if arrayHashSet is of type ArrayHashSet and all entries are equal Performance: arrayHashSet(1)

hashCode

public final int hashCode()
This is an O(n) operation over the size of this list.

Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class Object
Returns:
the hash code of this list as define in List.hashCode(), ie hashing all elements of this list.

isEmpty

public final boolean isEmpty()
Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface List

iterator

public final Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List

size

public final int size()
Specified by:
size in interface Collection
Specified by:
size in interface List

toArray

public final Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List

toArray

public final Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List

get

public final Object get(int index)
Specified by:
get in interface List

indexOf

public final int indexOf(Object element)
Specified by:
indexOf in interface List

add

public final void add(int index,
                      Object element)
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 interface List
Throws:
IllegalArgumentException - if the given element was already contained

addAll

public final boolean addAll(int index,
                            Collection c)
Specified by:
addAll in interface List
Throws:
UnsupportedOperationException

set

public final Object set(int index,
                        Object element)
Specified by:
set in interface List
Throws:
UnsupportedOperationException

remove

public final Object remove(int index)
Remove element at given index from this list.
This is an O(n) operation.

Specified by:
remove in interface List
Returns:
the removed object

lastIndexOf

public final int lastIndexOf(Object o)
Since this list is unique, equivalent to indexOf(java.lang.Object).
This is an O(n) operation.

Specified by:
lastIndexOf in interface List
Returns:
index of element, or -1 if not found

listIterator

public final ListIterator listIterator()
Specified by:
listIterator in interface List

listIterator

public final ListIterator listIterator(int index)
Specified by:
listIterator in interface List

subList

public final List subList(int fromIndex,
                          int toIndex)
Specified by:
subList in interface List

toArrayList

public final ArrayList toArrayList()
Returns:
a shallow copy of this ArrayHashSet's ArrayList, elements are not copied.

get

public final Object get(Object key)
Identity method allowing to get the identical object, using the internal hash map.
This is an O(1) operation.

Parameters:
key - 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 Object getOrAdd(Object key)
Identity method allowing to get the identical object, using the internal hash map.
If the key is not yet contained, add it.
This is an O(1) operation.

Parameters:
key - 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 given key and return it.

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,
ie contains(java.lang.Object) and containsSafe(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.