net.spy.util
Class RingBuffer<T>

java.lang.Object
  extended by java.util.AbstractCollection<T>
      extended by net.spy.util.RingBuffer<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<T>, java.util.Collection<T>

public class RingBuffer<T>
extends java.util.AbstractCollection<T>
implements java.io.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, java.util.Collection<T> fill)
          Get a RingBuffer at a particular size filled from the given Collection.
 
Method Summary
 boolean add(T o)
          Add an object to the ring buffer (if it's full, it'll cycle the oldest one out).
 int getCapacity()
          Get the total capacity of this RingBuffer.
 boolean hasWrapped()
          Check to see if the ring buffer has wrapped.
 java.util.Iterator<T> iterator()
          Get the iterator for this ring buffer.
 int size()
          Get the number of objects in this RingBuffer.
 java.lang.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,
                  java.util.Collection<T> 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

add

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

Specified by:
add in interface java.util.Collection<T>
Overrides:
add in class java.util.AbstractCollection<T>
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 java.lang.String toString()
String me.

Overrides:
toString in class java.util.AbstractCollection<T>

size

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

Specified by:
size in interface java.util.Collection<T>
Specified by:
size in class java.util.AbstractCollection<T>

getCapacity

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

Returns:
the number of objects this RingBuffer will hold

iterator

public java.util.Iterator<T> iterator()
Get the iterator for this ring buffer.

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface java.util.Collection<T>
Specified by:
iterator in class java.util.AbstractCollection<T>
Returns:
an iterator


Copyright © 1995-2006 SPY Internetworking. All Rights Reserved.