org.pentaho.reporting.engine.classic.core.util
Class WeakReferenceList<T>

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.util.WeakReferenceList<T>
All Implemented Interfaces:
Serializable, Cloneable

public abstract class WeakReferenceList<T>
extends Object
implements Serializable, Cloneable

The WeakReference list uses java.lang.ref.WeakReferences to store its contents. In contrast to the WeakHashtable, this list knows how to restore missing content, so that garbage collected elements can be restored when they are accessed.

By default this list can contain 25 elements, where the first element is stored using a strong reference, which is not garbage collected.

Restoring the elements is not implemented, concrete implementations will have to override the restoreChild(int) method. The getMaxChildCount method defines the maxmimum number of children in the list. When more than maxChildCount elements are contained in this list, add will always return false to indicate that adding the element failed.

To customize the list, override createReference to create a different kind of reference.

This list is able to add or replace elements, but inserting or removing of elements is not possible.

Author:
Thomas Morgner
See Also:
Serialized Form

Method Summary
 boolean add(T rs)
          Adds the element to the list.
 Object get(int index)
          Returns the child stored at the given index.
 T getRaw(int index)
           
 int getSize()
          Returns the size of the list.
 void set(T report, int index)
          Replaces the child stored at the given index with the new child which can be null.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public Object get(int index)
Returns the child stored at the given index. If the child has been garbage collected, it gets restored using the restoreChild function.

Parameters:
index - the index.
Returns:
the object.

getRaw

public T getRaw(int index)

set

public void set(T report,
                int index)
Replaces the child stored at the given index with the new child which can be null.

Parameters:
report - the object.
index - the index.

add

public boolean add(T rs)
Adds the element to the list. If the maximum size of the list is exceeded, this function returns false to indicate that adding failed.

Parameters:
rs - the object.
Returns:
true, if the object was successfully added to the list, false otherwise

getSize

public int getSize()
Returns the size of the list.

Returns:
the size.