smtphandler
Class CyclicBuffer

java.lang.Object
  extended by smtphandler.CyclicBuffer

public class CyclicBuffer
extends java.lang.Object

CyclicBuffer is used by other handlers to hold LogRecord objects for immediate or differed display.

This buffer gives read access to any element in the buffer not just the first or last element.

Author:
Ceki Gülcü, Sean C. Sullivan

Constructor Summary
CyclicBuffer(int maxSize)
          Instantiate a new CyclicBuffer of at most maxSize records.
 
Method Summary
 void add(java.util.logging.LogRecord record)
          Add a record as the last record in the buffer.
 java.util.logging.LogRecord get()
          Get the oldest (first) element in the buffer.
 java.util.logging.LogRecord get(int i)
          Get the i th oldest record currently in the buffer.
 int getMaxSize()
           
 int length()
          Get the number of elements in the buffer.
 void resize(int newSize)
          Resize the cyclic buffer to newSize.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CyclicBuffer

public CyclicBuffer(int maxSize)
             throws java.lang.IllegalArgumentException
Instantiate a new CyclicBuffer of at most maxSize records. The maxSize argument must a positive integer.

Parameters:
maxSize - The maximum number of elements in the buffer.
Throws:
java.lang.IllegalArgumentException
Method Detail

add

public void add(java.util.logging.LogRecord record)
Add a record as the last record in the buffer.

Parameters:
record - must be non-null

get

public java.util.logging.LogRecord get(int i)
Get the i th oldest record currently in the buffer. If i is outside the range 0 to the number of elements currently in the buffer, then null is returned.

Returns:
may return null

getMaxSize

public int getMaxSize()

get

public java.util.logging.LogRecord get()
Get the oldest (first) element in the buffer. The oldest element is removed from the buffer.

Returns:
may return null

length

public int length()
Get the number of elements in the buffer. This number is guaranteed to be in the range 0 to maxSize (inclusive).


resize

public void resize(int newSize)
Resize the cyclic buffer to newSize.

Throws:
java.lang.IllegalArgumentException - if newSize is negative.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2003-2006 smtphandler.sourceforge.net. All Rights Reserved.