Package org.wso2.carbon.utils.logging
Class CircularBuffer<E>
java.lang.Object
org.wso2.carbon.utils.logging.CircularBuffer<E>
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
ConstructorsConstructorDescriptionCreate a circular buffer with the maximum allowed sizeCircularBuffer(int size) Create a circular buffer with the given size -
Method Summary
Modifier and TypeMethodDescriptionvoidAppend elements while preserving the circular nature of the buffer.voidclear()Clear the circular buffer and reset the indices.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.
-
Constructor Details
-
CircularBuffer
public CircularBuffer(int size) Create a circular buffer with the given size- Parameters:
size- - fixed size of the buffer
-
CircularBuffer
public CircularBuffer()Create a circular buffer with the maximum allowed size
-
-
Method Details
-
append
Append elements while preserving the circular nature of the buffer.- Parameters:
element- - element to be appended
-
get
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
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
-