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

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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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-2009 Ontopia.