net.sf.ircappender.impl
Class Fifo

java.lang.Object
  extended by net.sf.ircappender.impl.Fifo

public class Fifo
extends java.lang.Object

A first in, first out buffer. Note: This implementation is threadsafe with the only exception that you may end up with more elements than the limit in the queue.

Author:
nhnb

Field Summary
static int AUTOPOP
          remove the oldest element if the fifo is full
static int REFUSE
          ignore the request to add more elements if the fifo is full
 
Constructor Summary
Fifo(int bufferSize, int fullStrategy)
          creates a new Fifo
 
Method Summary
 void add(java.lang.String e)
          adds an element. if the fifo is full either the oldest element is removed or the request to add this element is ignored, depending on fullStrategy
 boolean isEmpty()
          is the fifo empty?
 java.lang.String pop()
          gets the oldest element
 int size()
          gets the current size of the fifo (this is the number of stored elements, not maximum size).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTOPOP

public static final int AUTOPOP
remove the oldest element if the fifo is full

See Also:
Constant Field Values

REFUSE

public static final int REFUSE
ignore the request to add more elements if the fifo is full

See Also:
Constant Field Values
Constructor Detail

Fifo

public Fifo(int bufferSize,
            int fullStrategy)
creates a new Fifo

Parameters:
bufferSize - the maximum size of the fifo
fullStrategy - what to do when the size limit is exceeded
Method Detail

add

public void add(java.lang.String e)
adds an element. if the fifo is full either the oldest element is removed or the request to add this element is ignored, depending on fullStrategy

Parameters:
e - element to add

isEmpty

public boolean isEmpty()
is the fifo empty?

Returns:
true if the fifo is empty, false otherwise

pop

public java.lang.String pop()
                     throws java.util.NoSuchElementException
gets the oldest element

Returns:
oldest element
Throws:
java.util.NoSuchElementException - in case the fifo is empty

size

public int size()
gets the current size of the fifo (this is the number of stored elements, not maximum size).

Returns:
size