net.esper.collection
Class ArrayBackedCollection<T>

java.lang.Object
  extended by net.esper.collection.ArrayBackedCollection<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>

public class ArrayBackedCollection<T>
extends Object
implements Collection<T>

A fast collection backed by an array with severe limitations. Allows direct access to the backing array - this must be used with care as old elements could be in the array and the array is only valid until the number of elements indicated by size.

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.


Constructor Summary
ArrayBackedCollection(int currentSize)
          Ctor.
 
Method Summary
 boolean add(Object object)
           
 boolean addAll(Collection c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 Object[] getArray()
          Returns the backing object array, valid until the current size.
 boolean isEmpty()
           
 Iterator iterator()
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 boolean retainAll(Collection c)
           
 int size()
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

ArrayBackedCollection

public ArrayBackedCollection(int currentSize)
Ctor.

Parameters:
currentSize - is the initial size of the backing array.
Method Detail

add

public boolean add(Object object)
Specified by:
add in interface Collection<T>

clear

public void clear()
Specified by:
clear in interface Collection<T>

size

public int size()
Specified by:
size in interface Collection<T>

getArray

public Object[] getArray()
Returns the backing object array, valid until the current size.

Applications must ensure to not read past current size as old elements can be encountered.

Returns:
backing array

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<T>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<T>

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<T>

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection<T>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<T>

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection<T>

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection<T>

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection<T>

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection<T>