com.continuent.tungsten.common.patterns.order
Class RingBuffer<T>

java.lang.Object
  extended by com.continuent.tungsten.common.patterns.order.RingBuffer<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<T>

public class RingBuffer<T>
extends java.lang.Object
implements java.lang.Iterable<T>, java.io.Serializable

This class defines a simple RingBuffer.

Version:
1.0
Author:
Edward Archibald
See Also:
Serialized Form

Nested Class Summary
 class RingBuffer.RingBufferIterator<E>
          This class defines a RingBufferIterator
 
Constructor Summary
RingBuffer(int capacity)
           
 
Method Summary
 void add(T newElement)
          Add an element to the buffer.
 void addAll(RingBuffer<T> ringBuffer)
           
 RingBuffer<T> clone()
          Get a synchronized copy of the elements in this buffer.
 int getCapacity()
          Get the maximum capacity of the buffer.
 int getElementCount()
          Get the total number of elements in the buffer.
 java.util.ArrayList<T> getElements()
           
 int getLastElement()
           
 int getnextElementIndex()
          Returns the nextElementIndex value.
 java.util.Iterator<T> iterator()
          Let's be iterable!
static void main(java.lang.String[] argv)
          Quick and dirty unit test for this class.
 void setNextElementIndex(int nextElementIndex)
           
 java.lang.String toString()
          Formats a string with elements counted and delimited by a simple text header.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RingBuffer

public RingBuffer(int capacity)
Method Detail

add

public void add(T newElement)
Add an element to the buffer.

Parameters:
newElement -

setNextElementIndex

public void setNextElementIndex(int nextElementIndex)

addAll

public void addAll(RingBuffer<T> ringBuffer)

getElements

public java.util.ArrayList<T> getElements()

toString

public java.lang.String toString()
Formats a string with elements counted and delimited by a simple text header.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getElementCount

public int getElementCount()
Get the total number of elements in the buffer.


getCapacity

public int getCapacity()
Get the maximum capacity of the buffer.


clone

public RingBuffer<T> clone()
Get a synchronized copy of the elements in this buffer.

Overrides:
clone in class java.lang.Object

getnextElementIndex

public int getnextElementIndex()
Returns the nextElementIndex value.

Returns:
Returns the nextElementIndex.

getLastElement

public int getLastElement()

main

public static void main(java.lang.String[] argv)
Quick and dirty unit test for this class.

Parameters:
argv -

iterator

public java.util.Iterator<T> iterator()
Let's be iterable!

Specified by:
iterator in interface java.lang.Iterable<T>
See Also:
Iterable.iterator()