Top Description Fields Constructors Methods
net.sf.ehcache.util

public Class CircularLossyQueue<T>

extends Object
Class Inheritance
Type Parameters
<T>
Type of the item's to add in this queue
Imports
java.util.concurrent.atomic.AtomicLong, .AtomicReference

An implementation of a CircularQueue data-structure. When the number of items added exceeds the maximum capacity, items that were added first are lost.
Author
Abhishek Sanoujam
Since
1.7

Field Summary

Modifier and TypeField and Description
private final AtomicReference<T>[]
private final AtomicLong
private final int

Constructor Summary

AccessConstructor and Description
public
CircularLossyQueue(int size)

Constructs the circular queue with the specified capacity

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of items in the queue
depth
()

Returns the number of items currently in the queue

private int
private int
getIndex(int index)

public boolean

Returns:

true if the queue is empty, false otherwise
isEmtpy
()

Returns true if the queue is empty, otherwise false

public T

Returns:

Value at the tail of the queue
peek
()

Returns value at the tail of the queue

public void
push(T newVal)

Adds a new item

public T[]

Returns:

An array containing the current elements in the queue. The first element of the array is the tail of the queue and the last element is the head of the queue
toArray
(T[] type)

Returns an array of the current elements in the queue.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

circularArrayback to summary
private final AtomicReference<T>[] circularArray
currentIndexback to summary
private final AtomicLong currentIndex
maxSizeback to summary
private final int maxSize

Constructor Detail

CircularLossyQueueback to summary
public CircularLossyQueue(int size)

Constructs the circular queue with the specified capacity

Method Detail

depthback to summary
public int depth()

Returns the number of items currently in the queue

Returns:int

the number of items in the queue

getCurrentIndexback to summary
private int getCurrentIndex()
getIndexback to summary
private int getIndex(int index)
isEmtpyback to summary
public boolean isEmtpy()

Returns true if the queue is empty, otherwise false

Returns:boolean

true if the queue is empty, false otherwise

peekback to summary
public T peek()

Returns value at the tail of the queue

Returns:T

Value at the tail of the queue

pushback to summary
public void push(T newVal)

Adds a new item

toArrayback to summary
public T[] toArray(T[] type)

Returns an array of the current elements in the queue. The order of elements is in reverse order of the order items were added.

Returns:T[]

An array containing the current elements in the queue. The first element of the array is the tail of the queue and the last element is the head of the queue