Package org.wso2.carbon.utils.logging
Class CircularBuffer<E>
- java.lang.Object
-
- org.wso2.carbon.utils.logging.CircularBuffer<E>
-
public class CircularBuffer<E> extends Object
This is a Circular Buffer implementation. In this implementaion it is assumed that items will never be removed from this buffer. This can be used for a case such as a Rolling Log. A client can request the latest 'n' number of items that are stored in this buffer.
-
-
Constructor Summary
Constructors Constructor Description CircularBuffer()Create a circular buffer with the maximum allowed sizeCircularBuffer(int size)Create a circular buffer with the given size
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(E element)Append elements while preserving the circular nature of the buffer.voidclear()Clear the circular buffer and reset the indices.List<E>get(int amount)Retrieve the given amount of elements from the circular buffer.Object[]getObjects(int amount)This method is added for backward compatibility.intgetSize()Return the capacity of the circular buffer.
-
-
-
Method Detail
-
append
public void append(E element)
Append elements while preserving the circular nature of the buffer.- Parameters:
element- - element to be appended
-
get
public List<E> get(int amount)
Retrieve the given amount of elements from the circular buffer. This is a forgiving operation, if the amount asked is greater than the size of the buffer it will return all the available elements- Parameters:
amount- - no of elements to return- Returns:
- - a list of elements
-
getObjects
public Object[] getObjects(int amount)
This method is added for backward compatibility.- Parameters:
amount- - amount of elements to return from the buffer- Returns:
- - an object array of amount number of elements in the buffer
-
clear
public void clear()
Clear the circular buffer and reset the indices.
-
getSize
public int getSize()
Return the capacity of the circular buffer. This is set during buffer initialization.- Returns:
- - capacity of the buffer
-
-