lejos.util
Class Recycler

java.lang.Object
  extended by lejos.util.Recycler
Direct Known Subclasses:
ArrayRecycler

public abstract class Recycler
extends Object

An abstract object recycler. This class should be extended to define the createInstance method for a particular kind of Recyclable. On concrete recycler instances, invoke allocate() to create objects and recycle() to release them. It is the programmer's responsibility to avoid using objects that have been recycled.

Note that the caller is expected to provide thread safety for instances of this class.

See Also:
Recyclable

Constructor Summary
Recycler()
          Constructs a recycler.
 
Method Summary
 Recyclable allocate()
          Attempts to obtain a free object.
protected abstract  Recyclable createInstance()
          This is a factory method that should be overridden to create an Recyclable object instance.
 void recycle(Recyclable r)
          Reclaims a Recyclable previously allocated with the allocate method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

Recycler

public Recycler()
Constructs a recycler.

Method Detail

allocate

public final Recyclable allocate()
Attempts to obtain a free object.

Returns:
A Recyclable object reference.

recycle

public final void recycle(Recyclable r)
Reclaims a Recyclable previously allocated with the allocate method. The release method of the Recyclable object is invoked here.


createInstance

protected abstract Recyclable createInstance()
This is a factory method that should be overridden to create an Recyclable object instance.