org.jvnet.lafwidget.utils
Class DeltaQueue

java.lang.Object
  extended by org.jvnet.lafwidget.utils.DeltaQueue

public class DeltaQueue
extends java.lang.Object

Delta queue. Follows a standard approach from OS world for effeciently keeping tracks of scheduled events.

Author:
Kirill Grouchnikov

Nested Class Summary
static class DeltaQueue.Deltable
          Base class for entries in a DeltaQueue.
static interface DeltaQueue.DeltaMatcher
          Interface for comparing two delta instances.
 
Field Summary
protected  java.util.ArrayList<DeltaQueue.Deltable> queue
          List of entries.
 
Constructor Summary
DeltaQueue()
          Constructs a new empty non-blocking synchronized delta queue.
 
Method Summary
 java.util.List<DeltaQueue.Deltable> dequeue(int delay)
          Returns all deltables that have at most specified delay left.
 void dump()
          Dumps the contents of the delta queue.
static void main(java.lang.String[] args)
          For testing.
 void queue(DeltaQueue.Deltable deltable)
          Queues the specified deltable.
 void removeMatching(DeltaQueue.DeltaMatcher matcher)
          Removes all deltas matching the specified matcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

protected java.util.ArrayList<DeltaQueue.Deltable> queue
List of entries. Contains DeltaQueue.Deltables.

Constructor Detail

DeltaQueue

public DeltaQueue()
Constructs a new empty non-blocking synchronized delta queue.

Method Detail

queue

public void queue(DeltaQueue.Deltable deltable)
Queues the specified deltable. The specified deltable is placed somewhere in the queue based on the initial value of its delta. Note that when this method returns, the value of a DeltaQueue.Deltable.getDelta() may have changed. Do not reuse or change the passed deltable after this method returns.

Parameters:
deltable - Deltable.

dequeue

public java.util.List<DeltaQueue.Deltable> dequeue(int delay)
Returns all deltables that have at most specified delay left. The returned list may be empty.

Parameters:
delay - Delay.
Returns:
The possibly empty list of all deltables that have at most specified delay left.

removeMatching

public void removeMatching(DeltaQueue.DeltaMatcher matcher)
Removes all deltas matching the specified matcher.

Parameters:
matcher - Delta matcher.

dump

public void dump()
Dumps the contents of the delta queue.


main

public static void main(java.lang.String[] args)
For testing.

Parameters:
args - Ignored.