29package com.jogamp.common.util;
31import java.util.ArrayList;
32import java.util.Collection;
33import java.util.HashMap;
34import java.util.Iterator;
36import java.util.ListIterator;
69 implements Cloneable, Collection<E>, List<E>
80 private final HashMap<E,E> map;
81 private final ArrayList<E> data;
82 private final boolean supportNullValue;
93 public ArrayHashSet(
final boolean supportNullValue,
final int initialCapacity,
final float loadFactor) {
94 this.map =
new HashMap<E,E>(initialCapacity, loadFactor);
95 this.data =
new ArrayList<E>(initialCapacity);
96 this.supportNullValue = supportNullValue;
103 map =
new HashMap<E, E>(o.map);
104 data =
new ArrayList<E>(o.data);
105 supportNullValue = o.supportNullValue;
131 public final ArrayList<E>
getData() {
return data; }
133 public final HashMap<E,E>
getMap() {
return map; }
136 public final String
toString() {
return data.toString(); }
161 public final boolean add(
final E element)
throws NullPointerException {
162 if( !supportNullValue ) {
165 if( !map.containsKey(element) ) {
167 if(
null != map.put(element, element)) {
169 throw new InternalError(
"Already existing, but checked before: "+element);
171 if(!data.add(element)) {
172 throw new InternalError(
"Couldn't add element: "+element);
193 public final boolean remove(
final Object element)
throws NullPointerException {
194 if( supportNullValue ) {
195 if( map.containsKey(element) ) {
198 if ( !data.remove(element) ) {
199 throw new InternalError(
"Couldn't remove prev mapped element: "+element);
205 if (
null != map.remove(element) ) {
207 if ( !data.remove(element) ) {
208 throw new InternalError(
"Couldn't remove prev mapped element: "+element);
228 public final boolean addAll(
final Collection<? extends E> c) {
230 for (
final E o : c) {
248 public final boolean contains(
final Object element) {
249 return map.containsKey(element);
265 for (
final Object o : c) {
287 for (
final Object o : c) {
288 mod |= this.
remove(o);
308 for (
final Object o : c) {
309 if (!c.contains(o)) {
310 mod |= this.
remove(o);
326 public final boolean equals(
final Object arrayHashSet) {
344 return data.hashCode();
349 return data.isEmpty();
354 return data.iterator();
364 return data.toArray();
369 return data.toArray(a);
377 public final E
get(
final int index) {
378 return data.get(index);
382 public final int indexOf(
final Object element) {
383 return data.indexOf(element);
398 public final void add(
final int index,
final E element)
throws IllegalArgumentException, NullPointerException {
399 if( !supportNullValue ) {
402 if ( map.containsKey(element) ) {
403 throw new IllegalArgumentException(
"Element "+element+
" is already contained");
405 if(
null != map.put(element, element)) {
407 throw new InternalError(
"Already existing, but checked before: "+element);
410 data.add(index, element);
420 public final boolean addAll(
final int index,
final Collection<? extends E> c)
throws UnsupportedOperationException {
421 throw new UnsupportedOperationException(
"Not supported yet.");
430 public final E
set(
final int index,
final E element) {
431 final E old =
remove(index);
449 public final E
remove(
final int index) {
450 final E o =
get(index);
451 if(
null!=o &&
remove(o) ) {
474 return data.listIterator();
479 return data.listIterator(index);
483 public final List<E>
subList(
final int fromIndex,
final int toIndex) {
484 return data.subList(fromIndex, toIndex);
495 return new ArrayList<E>(data);
507 public final E
get(
final Object element) {
508 return map.get(element);
522 public final E
getOrAdd(
final E element)
throws NullPointerException {
523 if( supportNullValue ) {
524 if( map.containsKey(element) ) {
526 return map.get(element);
530 final E identity = map.get(element);
531 if(
null != identity) {
537 if(!this.
add(element)) {
538 throw new InternalError(
"Element not mapped, but contained in list: "+element);
556 return data.contains(element);
559 private static final void checkNull(
final Object element)
throws NullPointerException {
560 if(
null == element ) {
561 throw new NullPointerException(
"Null element not supported");
Hashed ArrayList implementation of the List and Collection interface.
final ArrayList< E > getData()
Returns this object ordered ArrayList.
final E getOrAdd(final E element)
Identity method allowing to get the identical object, using the internal hash map.
final int lastIndexOf(final Object o)
Since this list is unique, equivalent to indexOf(java.lang.Object).
final< T > T[] toArray(final T[] a)
final boolean addAll(final int index, final Collection<? extends E > c)
final boolean containsAll(final Collection<?> c)
Test for containment of given java.util.Collection This is an O(n) operation, over the given Collec...
final boolean contains(final Object element)
Test for containment This is an O(1) operation.
final ListIterator< E > listIterator()
ArrayHashSet(final ArrayHashSet< E > o)
final boolean equals(final Object arrayHashSet)
This is an O(n) operation.
final ArrayList< E > toArrayList()
final HashMap< E, E > getMap()
Returns this object hash map.
final List< E > subList(final int fromIndex, final int toIndex)
static final float DEFAULT_LOAD_FACTOR
Default load factor: {@value}.
final boolean supportsNullValue()
Returns true for default behavior, i.e.
final boolean containsSafe(final Object element)
Test for containment This is an O(n) operation, using equals operation over the list.
final Iterator< E > iterator()
final int indexOf(final Object element)
final void add(final int index, final E element)
Add element at the given index in this list, if it is not contained yet.
final ListIterator< E > listIterator(final int index)
final boolean addAll(final Collection<? extends E > c)
Add all elements of given java.util.Collection at the end of this list.
final int hashCode()
This is an O(n) operation over the size of this list.
final boolean retainAll(final Collection<?> c)
Retain all elements of the given java.util.Collection c, ie remove all elements not contained by the ...
final boolean add(final E element)
Add element at the end of this list, if it is not contained yet.
ArrayHashSet(final boolean supportNullValue, final int initialCapacity, final float loadFactor)
final boolean removeAll(final Collection<?> c)
Remove all elements of given java.util.Collection from this list.
static final int DEFAULT_INITIAL_CAPACITY
The default initial capacity: {@value}.