org.h2.dev.util
Class ConcurrentRing<K>

java.lang.Object
  extended by org.h2.dev.util.ConcurrentRing<K>
Type Parameters:
K - the key type

public class ConcurrentRing<K>
extends java.lang.Object

A ring buffer that supports concurrent access.


Constructor Summary
ConcurrentRing()
           
 
Method Summary
 void add(K obj)
          Add an element at the end.
 java.util.Iterator<K> iterator()
          Get an iterator over all entries.
 K peekFirst()
          Get the first element, or null if none.
 K peekLast()
          Get the last element, or null if none.
 boolean removeFirst(K obj)
          Remove the first element, if it matches.
 boolean removeLast(K obj)
          Remove the last element, if it matches.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentRing

public ConcurrentRing()
Method Detail

peekFirst

public K peekFirst()
Get the first element, or null if none.

Returns:
the first element

peekLast

public K peekLast()
Get the last element, or null if none.

Returns:
the last element

add

public void add(K obj)
Add an element at the end.

Parameters:
obj - the element

removeFirst

public boolean removeFirst(K obj)
Remove the first element, if it matches.

Parameters:
obj - the element to remove
Returns:
true if the element matched and was removed

removeLast

public boolean removeLast(K obj)
Remove the last element, if it matches.

Parameters:
obj - the element to remove
Returns:
true if the element matched and was removed

iterator

public java.util.Iterator<K> iterator()
Get an iterator over all entries.

Returns:
the iterator