org.jactr.core.queue.collection
Class PrioritizedQueue<T>

java.lang.Object
  extended by org.jactr.core.queue.collection.PrioritizedQueue<T>

public class PrioritizedQueue<T>
extends java.lang.Object

Crazy prioritized queue (bad name.. whatever) that had to be implemented for one reason: java.util.PriorityQueue does not maintain insertion order of items when they have the same priority. jACT-R needs to maintain the order so that timed events added by instantiations are fired in the order they are queued.

This has three pieces, IPrioritizer which takes a T and returns a double value. When you add an item, its priority is used to determine which collection, in a sorted map of collections, it will be stored in.

You call Collection remove(double) to remove all items from the queue that have priorities less than or equal to the value.
Note: this is not thread safe

Author:
developer

Constructor Summary
PrioritizedQueue(IPrioritizer<T> prioritizer)
           
 
Method Summary
 void add(T item)
           
 void clear()
           
 java.util.Collection<T> get()
          return all the elements in order of priority (and insertion if priorities are the same)
 double getFirstPriority()
          first key, or NaN if empty
 double getFirstPriorityAfter(double afterPriority)
          first key after afterPriority, or NaN
 int getSize()
           
 boolean isEmpty()
           
 void remove(double upThrough, java.util.Collection<T> removedEvents)
          return all the items of less than or equal to upThrough
 boolean remove(T item)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrioritizedQueue

public PrioritizedQueue(IPrioritizer<T> prioritizer)
Method Detail

clear

public void clear()

add

public void add(T item)

remove

public boolean remove(T item)

remove

public void remove(double upThrough,
                   java.util.Collection<T> removedEvents)
return all the items of less than or equal to upThrough

Parameters:
upThrough -

get

public java.util.Collection<T> get()
return all the elements in order of priority (and insertion if priorities are the same)

Returns:

getFirstPriority

public double getFirstPriority()
first key, or NaN if empty

Returns:

getFirstPriorityAfter

public double getFirstPriorityAfter(double afterPriority)
first key after afterPriority, or NaN

Parameters:
afterPriority -
Returns:

isEmpty

public boolean isEmpty()

getSize

public int getSize()