Package org.apache.log4j.chainsaw
Class CyclicBufferList
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
org.apache.log4j.chainsaw.CyclicBufferList
- All Implemented Interfaces:
Iterable,Collection,List
CyclicBuffer implementation that is Object generic, and implements the List interface.
Original CyclicBuffer @author Ceki Gülcü
This implementation (although there's very little change) @author Paul Smith <psmith@apache.org>
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Object[](package private) int(package private) int(package private) int(package private) intFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCyclicBufferList(int maxSize) Instantiate a new CyclicBuffer of at mostmaxSizeevents. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd aneventas the last event in the buffer.voidclear()get()Get the oldest (first) element in the buffer.get(int i) Get the ith oldest event currently in the buffer.intgetLast()intremove(int index) Removes the element at the specified position in this list.voidresize(int newSize) Resize the cyclic buffer tonewSize.intsize()Get the number of elements in the buffer.Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface java.util.List
add, addAll, addAll, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, replaceAll, retainAll, sort, spliterator, subList, toArray, toArray
-
Field Details
-
ea
Object[] ea -
first
int first -
last
int last -
numElems
int numElems -
maxSize
int maxSize
-
-
Constructor Details
-
CyclicBufferList
public CyclicBufferList(int maxSize) Instantiate a new CyclicBuffer of at mostmaxSizeevents.The
maxSizeargument must a positive integer.- Parameters:
maxSize- The maximum number of elements in the buffer.
-
CyclicBufferList
public CyclicBufferList()
-
-
Method Details
-
remove
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).- Specified by:
removein interfaceList- Overrides:
removein classAbstractList- Parameters:
index- the index of the element to removed.- Returns:
- the element that was removed from the list.
- Throws:
IndexOutOfBoundsException- if index out of range (index < 0 || index >= size()).
-
set
- Specified by:
setin interfaceList- Overrides:
setin classAbstractList
-
add
Add aneventas the last event in the buffer.- Specified by:
addin interfaceCollection- Specified by:
addin interfaceList- Overrides:
addin classAbstractList
-
get
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, thennullis returned.- Specified by:
getin interfaceList- Specified by:
getin classAbstractList
-
getMaxSize
public int getMaxSize() -
getLast
public int getLast() -
get
Get the oldest (first) element in the buffer. The oldest element is removed from the buffer. -
size
public int size()Get the number of elements in the buffer. This number is guaranteed to be in the range 0 tomaxSize(inclusive).- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- Specified by:
sizein classAbstractCollection
-
resize
public void resize(int newSize) Resize the cyclic buffer tonewSize.- Throws:
IllegalArgumentException- ifnewSizeis negative.
-
clear
public void clear()- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceList- Overrides:
clearin classAbstractList
-