org.apache.log4j.chainsaw
Class CyclicBufferList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by org.apache.log4j.chainsaw.CyclicBufferList
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.List

public class CyclicBufferList
extends java.util.AbstractList
implements java.util.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


Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
CyclicBufferList()
           
CyclicBufferList(int maxSize)
          Instantiate a new CyclicBuffer of at most maxSize events.
 
Method Summary
 boolean add(java.lang.Object event)
          Add an event as the last event in the buffer.
 void clear()
           
 java.lang.Object get()
          Get the oldest (first) element in the buffer.
 java.lang.Object get(int i)
          Get the ith oldest event currently in the buffer.
 int getLast()
           
 int getMaxSize()
           
 java.lang.Object remove(int index)
          Removes the element at the specified position in this list.
 void resize(int newSize)
          Resize the cyclic buffer to newSize.
 java.lang.Object set(int index, java.lang.Object element)
           
 int size()
          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, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, addAll, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, subList, toArray, toArray
 

Constructor Detail

CyclicBufferList

public CyclicBufferList(int maxSize)
Instantiate a new CyclicBuffer of at most maxSize events. The maxSize argument must a positive integer.

Parameters:
maxSize - The maximum number of elements in the buffer.

CyclicBufferList

public CyclicBufferList()
Method Detail

remove

public java.lang.Object remove(int index)
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.AbstractList
Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the list.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List
Overrides:
set in class java.util.AbstractList

add

public boolean add(java.lang.Object event)
Add an event as the last event in the buffer.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.AbstractList

get

public java.lang.Object 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.

Specified by:
get in interface java.util.List
Specified by:
get in class java.util.AbstractList

getMaxSize

public int getMaxSize()

getLast

public int getLast()

get

public java.lang.Object 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 to maxSize (inclusive).

Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class java.util.AbstractCollection

resize

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

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

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.AbstractList


Copyright © 2007 Apache Software Foundation. All Rights Reserved.