net.spy.util
Class RingBuffer

java.lang.Object
  extended byjava.util.AbstractCollection
      extended bynet.spy.util.RingBuffer
All Implemented Interfaces:
Collection, Serializable

public class RingBuffer
extends AbstractCollection
implements Serializable

A circular buffer. Ring buffers may have new entries appended to them, but may not otherwise be modified. Individual entries may not be accessed directly, only via the iterator.

See Also:
Serialized Form

Constructor Summary
RingBuffer(int s)
          Get an instance of RingBuffer.
RingBuffer(int s, Collection fill)
          Get a RingBuffer at a particular size filled from the given Collection.
 
Method Summary
 boolean add(Object o)
          Add an object to the ring buffer (if it's full, it'll cycle the oldest one out).
 void addObject(Object o)
          Deprecated. use add()
 int getCapacity()
          Get the total capacity of this RingBuffer.
 Collection getData()
          Deprecated. this is a Collection now.
 int getSize()
          Deprecated. use the Collections implementation instead
 boolean hasWrapped()
          Check to see if the ring buffer has wrapped.
 Iterator iterator()
          Get the iterator for this ring buffer.
 int size()
          Get the number of objects in this RingBuffer.
 String toString()
          String me.
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

RingBuffer

public RingBuffer(int s)
Get an instance of RingBuffer.


RingBuffer

public RingBuffer(int s,
                  Collection fill)
Get a RingBuffer at a particular size filled from the given Collection.

Parameters:
s - the maximum number of objects to be held in the ring
fill - a Collection whose elements will be used to fill the buffer
Method Detail

addObject

public void addObject(Object o)
Deprecated. use add()

Add a new object to the ring.


add

public boolean add(Object o)
Add an object to the ring buffer (if it's full, it'll cycle the oldest one out).

Specified by:
add in interface Collection
Parameters:
o - the object to add
Returns:
true

hasWrapped

public boolean hasWrapped()
Check to see if the ring buffer has wrapped.

Returns:
true if the ring buffer has wrapped

toString

public String toString()
String me.


getSize

public int getSize()
Deprecated. use the Collections implementation instead

Get the number of objects in this RingBuffer.


size

public int size()
Get the number of objects in this RingBuffer.

Specified by:
size in interface Collection

getCapacity

public int getCapacity()
Get the total capacity of this RingBuffer.

Returns:
the number of objects this RingBuffer will hold

iterator

public Iterator iterator()
Get the iterator for this ring buffer.

Specified by:
iterator in interface Collection
Returns:
an iterator

getData

public Collection getData()
Deprecated. this is a Collection now.

Get the collection of data in this list.