Top Description Fields Constructors Methods
ch.qos.logback.core.helpers

public Class CyclicBuffer<E>

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List

CyclicBuffer holds values in a cyclic array.

It allows read access to any element in the buffer not just the first or last element.

Author
Ceki Gülcü

Field Summary

Modifier and TypeField and Description
pack-priv E[]
pack-priv int
pack-priv int
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
public
CyclicBuffer(int
The maximum number of elements in the buffer.
maxSize
)

Instantiate a new CyclicBuffer of at most maxSize events.

public

Method Summary

Modifier and TypeMethod and Description
public void
add(E event)

Add an event as the last event in the buffer.

public List<E>
public void
clear()

Clears the buffer and resets all attributes.

public E
get(int i)

Get the ith oldest event currently in the buffer.

public E
get()

Get the oldest (first) element in the buffer.

public int
private void
init(int maxSize)

public int
length()

Get the number of elements in the buffer.

public void
resize(int newSize)

Resize the cyclic buffer to newSize.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

eaback to summary
pack-priv E[] ea
firstback to summary
pack-priv int first
lastback to summary
pack-priv int last
maxSizeback to summary
pack-priv int maxSize
numElemsback to summary
pack-priv int numElems

Constructor Detail

CyclicBufferback to summary
public CyclicBuffer(int maxSize) throws IllegalArgumentException

Instantiate a new CyclicBuffer of at most maxSize events. The maxSize argument must a positive integer.

Parameters
maxSize:int

The maximum number of elements in the buffer.

CyclicBufferback to summary
public CyclicBuffer(CyclicBuffer<E> other)
Annotations
@SuppressWarnings:unchecked

Method Detail

addback to summary
public void add(E event)

Add an event as the last event in the buffer.

asListback to summary
public List<E> asList()
clearback to summary
public void clear()

Clears the buffer and resets all attributes.

getback to summary
public E get(int i)

Get the ith oldest event currently in the buffer. If i is outside the range 0 to the number of elements currently in the buffer, then null is returned.

getback to summary
public E get()

Get the oldest (first) element in the buffer. The oldest element is removed from the buffer.

getMaxSizeback to summary
public int getMaxSize()
initback to summary
private void init(int maxSize)
Annotations
@SuppressWarnings:unchecked
lengthback to summary
public int length()

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

resizeback to summary
public void resize(int newSize)

Resize the cyclic buffer to newSize.

Annotations
@SuppressWarnings:unchecked
Exceptions
IllegalArgumentException:
if newSize is negative.