org.apache.avalon.fortress.util
Class LifecycleExtensionManager.CachedArrayList

java.lang.Object
  extended by org.apache.avalon.fortress.util.LifecycleExtensionManager.CachedArrayList
Enclosing class:
LifecycleExtensionManager

private final class LifecycleExtensionManager.CachedArrayList
extends java.lang.Object

CachedArrayList class.

This class wraps a synchronized ArrayList to provide an optimized toArray() method that returns an internally cached array, rather than a new array generated per toArray() invocation.

Use of the class by the Manager results in toArray() being invoked far more often than any other method. Caching the value toArray normally returns is intended to be a performance optimization.

The cached array value is updated upon each write operation to the List.

REVISIT(MC): investigate using FastArrayList from collections ?


Field Summary
private  java.lang.Object[] EMPTY_ARRAY
           
private  java.lang.Object[] m_cache
           
private  java.util.List m_proxy
           
 
Constructor Summary
private LifecycleExtensionManager.CachedArrayList()
           
 
Method Summary
 void add(java.lang.Object object)
          Add an object to the list
 void clear()
          Clear the list
 void copyFrom(LifecycleExtensionManager.CachedArrayList original)
          Become a copy of another CachedArrayList.
 java.lang.Object get(int index)
          Access an object that is in the list
 int indexOf(java.lang.Object object)
          Find out the index of an object in the list
 void insert(int position, java.lang.Object object)
          Insert an object into a particular position in the list
 java.util.Iterator iterator()
          Obtain an iterator.
 java.lang.Object remove(int position)
          Remove an object from the list
 int size()
          Obtain the size of the list
 java.lang.Object[] toArray()
          Obtain the list as an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

private final java.lang.Object[] EMPTY_ARRAY

m_proxy

private final java.util.List m_proxy

m_cache

private java.lang.Object[] m_cache
Constructor Detail

LifecycleExtensionManager.CachedArrayList

private LifecycleExtensionManager.CachedArrayList()
Method Detail

copyFrom

public void copyFrom(LifecycleExtensionManager.CachedArrayList original)
Become a copy of another CachedArrayList.


add

public void add(java.lang.Object object)
Add an object to the list

Parameters:
object - an Object value

insert

public void insert(int position,
                   java.lang.Object object)
Insert an object into a particular position in the list

Parameters:
position - an int value
object - an Object value

remove

public java.lang.Object remove(int position)
Remove an object from the list

Parameters:
position - an int value
Returns:
a Object value

iterator

public java.util.Iterator iterator()
Obtain an iterator. This iterator is read-only.

Returns:
an Iterator value

size

public int size()
Obtain the size of the list

Returns:
an int value

get

public java.lang.Object get(int index)
Access an object that is in the list

Parameters:
index - an int value
Returns:
a Object value

indexOf

public int indexOf(java.lang.Object object)
Find out the index of an object in the list

Parameters:
object - an Object value
Returns:
an int value

clear

public void clear()
Clear the list


toArray

public java.lang.Object[] toArray()
Obtain the list as an array. Subsequents calls to this method will return the same array object, until a write operation is performed on the list.

Returns:
an Object[] value