com.isti.util
Class CircularBuffer

java.lang.Object
  extended by com.isti.util.CircularBuffer

public class CircularBuffer
extends java.lang.Object

Class CircularBuffer implements a circular buffer. The buffer holds a limit number of items such that when the buffer is full and an item is added the oldest item in the buffer is removed. Note that this class is not thread synchronized.


Field Summary
protected  int allocBufferSize
           
protected  java.lang.Object[] bufferObjsArray
           
protected  int bufferPosition
           
protected  long totalItemsCounter
           
 
Constructor Summary
CircularBuffer(int bufferSize)
          Creates a circular buffer.
 
Method Summary
 void add(java.lang.Object obj)
          Adds the given item to the buffer.
 boolean contains(java.lang.Object obj)
          Determines whether or not an equivalent item is contained in the buffer.
 java.lang.Object[] getBufferItems()
          Returns an array containing the items in the buffer in the order in which they were entered.
 java.lang.String getBufferItemsAsString(java.lang.String sepStr)
          Returns a string containing items in the buffer in the order in which they were entered.
 java.lang.String[] getStrBufferItems()
          Returns an array containing string items in the buffer in the order in which they were entered.
 long getTotalItemsCount()
          Returns a count of the total number of items that have ever been entered into the buffer.
 void setBufferSize(int bufferSize)
          Sets the buffer size of the circular buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufferObjsArray

protected java.lang.Object[] bufferObjsArray

allocBufferSize

protected int allocBufferSize

bufferPosition

protected int bufferPosition

totalItemsCounter

protected long totalItemsCounter
Constructor Detail

CircularBuffer

public CircularBuffer(int bufferSize)
Creates a circular buffer.

Parameters:
bufferSize - size of circular buffer.
Method Detail

setBufferSize

public final void setBufferSize(int bufferSize)
Sets the buffer size of the circular buffer. Any items currently in the buffer are discarded.

Parameters:
bufferSize - size of circular buffer.

add

public void add(java.lang.Object obj)
Adds the given item to the buffer. If the buffer is full then the oldest item in the buffer is removed.

Parameters:
obj - item to be added.

getBufferItems

public java.lang.Object[] getBufferItems()
Returns an array containing the items in the buffer in the order in which they were entered.

Returns:
A new array of objects.

getStrBufferItems

public java.lang.String[] getStrBufferItems()
Returns an array containing string items in the buffer in the order in which they were entered. The 'toString()' method is used to convert each item to a string.

Returns:
A new array of strings.

getBufferItemsAsString

public java.lang.String getBufferItemsAsString(java.lang.String sepStr)
Returns a string containing items in the buffer in the order in which they were entered. The 'toString()' method is used to convert each item to a string.

Parameters:
sepStr - separator to be placed between each item.
Returns:
A new string containing the items.

getTotalItemsCount

public long getTotalItemsCount()
Returns a count of the total number of items that have ever been entered into the buffer.

Returns:
A count of the total number of items that have ever been entered into the buffer.

contains

public boolean contains(java.lang.Object obj)
Determines whether or not an equivalent item is contained in the buffer.

Parameters:
obj - item to check for.
Returns:
true if an equivalent item is contained in the buffer; false if not.