sk.baka.webvm.misc
Class SimpleFixedSizeFIFO<T>

java.lang.Object
  extended by sk.baka.webvm.misc.SimpleFixedSizeFIFO<T>
Type Parameters:
T - type of items contained in this history object.

public final class SimpleFixedSizeFIFO<T>
extends Object

A simple object that holds a fixed-size history. A fixed-size FIFO implementation.

Author:
Martin Vysny

Constructor Summary
SimpleFixedSizeFIFO(int maxLength)
          Creates new instance.
 
Method Summary
 void add(T item)
          Adds an item to the history, discarding oldest items when the maximum length has been reached.
 void clear()
          Clears the history.
 T getNewest()
          Returns the newest item put into this queue.
 List<T> toList()
          Returns a snapshot of the FIFO.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleFixedSizeFIFO

public SimpleFixedSizeFIFO(int maxLength)
Creates new instance.

Parameters:
maxLength - maximum length of the FIFO queue. Old items are dropped automatically.
Method Detail

add

public void add(T item)
Adds an item to the history, discarding oldest items when the maximum length has been reached. Not thread-safe - may be called from one thread instance only.

Parameters:
item - the item to add

toList

public List<T> toList()
Returns a snapshot of the FIFO. Thread-safe.

Returns:
a snapshot, first item is the oldest one.

clear

public void clear()
Clears the history.


getNewest

public T getNewest()
Returns the newest item put into this queue. Not thread-safe - may be called from the same thread which is adding items only.

Returns:
newest item or null if the FIFO is empty.


Copyright © 2010 Baka. All Rights Reserved.