net.ontopia.utils
Class RingBuffer

java.lang.Object
  extended by net.ontopia.utils.RingBuffer

public class RingBuffer
extends java.lang.Object

INTERNAL: Utility for storing objects in a ring buffer. Adding an object may cause another one to 'fall' off if the buffer is full.

Since:
2.0

Field Summary
protected  java.util.ArrayList buffer
          the buffer collection
protected  int maxSize
          max size.
 
Constructor Summary
RingBuffer()
          Creates a new RingBuffer with a default size of 50.
RingBuffer(int maxSize)
          Creates a new RingBuffer with the specified size.
 
Method Summary
 void addElement(java.lang.Object obj)
          Adds a new element to the buffer.
 void clear()
          Empties the buffer.
 java.util.List getElements()
          Returns the elements in the buffer, in order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxSize

protected int maxSize
max size.


buffer

protected java.util.ArrayList buffer
the buffer collection

Constructor Detail

RingBuffer

public RingBuffer()
Creates a new RingBuffer with a default size of 50.


RingBuffer

public RingBuffer(int maxSize)
Creates a new RingBuffer with the specified size.

Method Detail

getElements

public java.util.List getElements()
Returns the elements in the buffer, in order.

Returns:
the collection of elements in the buffer.

addElement

public void addElement(java.lang.Object obj)
Adds a new element to the buffer. If the buffer is full an element is bumped off the back. If the item already exists it is moved to the front and the rest of the buffer closes up the gap.


clear

public void clear()
Empties the buffer.



Copyright © 2000-2012 Ontopia.