public class ArrayBackedCollection<T>
extends java.lang.Object
implements java.util.Collection<T>
Implements only the add, size and clear methods of the collection interface.
When running out of space for the underlying array, allocates a new array of double the size of the current array.
Not synchronized and not thread-safe.
Modifier and Type | Class and Description |
---|---|
class |
ArrayBackedCollection.ArrayBackedCollectionIterator |
Constructor and Description |
---|
ArrayBackedCollection(int currentSize)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(T object) |
boolean |
addAll(java.util.Collection c) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection c) |
java.lang.Object[] |
getArray()
Returns the backing object array, valid until the current size.
|
boolean |
isEmpty() |
java.util.Iterator<T> |
iterator() |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection c) |
boolean |
retainAll(java.util.Collection c) |
int |
size() |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public ArrayBackedCollection(int currentSize)
currentSize
- is the initial size of the backing array.public void clear()
clear
in interface java.util.Collection<T>
public int size()
size
in interface java.util.Collection<T>
public java.lang.Object[] getArray()
Applications must ensure to not read past current size as old elements can be encountered.
public boolean isEmpty()
isEmpty
in interface java.util.Collection<T>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<T>
public java.util.Iterator<T> iterator()
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<T>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<T>
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection<T>
public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.Collection<T>
public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.Collection<T>
public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection<T>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<T>