com.twitter.common.collections
Class BoundedQueue<T>

java.lang.Object
  extended by com.twitter.common.collections.BoundedQueue<T>
Type Parameters:
T - The type that this queue contains.
All Implemented Interfaces:
Iterable<T>

public class BoundedQueue<T>
extends Object
implements Iterable<T>

A limited implementation of a bounded queue. Values can be added and iterated over, and will automatically expire when the queue exceeds capacity.


Constructor Summary
BoundedQueue(int limit)
          Creates a new bounded queue.
 
Method Summary
 void add(T value)
          Adds a value to head of the queue, evicting the oldest item if the queue is at capacity.
 void clear()
          Removes all values from the queue.
 Iterator<T> iterator()
           
 int size()
          Returns the size of the queue.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoundedQueue

public BoundedQueue(int limit)
Creates a new bounded queue.

Parameters:
limit - Maximum number of items that can be in the queue at any time.
Method Detail

add

public void add(T value)
Adds a value to head of the queue, evicting the oldest item if the queue is at capacity.

Parameters:
value - Value to add.

clear

public void clear()
Removes all values from the queue.


size

public int size()
Returns the size of the queue.

Returns:
The current queue length.

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>

toString

public String toString()
Overrides:
toString in class Object