Package jasima.shopSim.core
Class PriorityQueue<T extends PrioRuleTarget>
- java.lang.Object
-
- jasima.shopSim.core.PriorityQueue<T>
-
- Type Parameters:
T- The element type contained in this PriorityQueue.
- All Implemented Interfaces:
Serializable
public class PriorityQueue<T extends PrioRuleTarget> extends Object implements Serializable
An implementation of a priority queue. The two supported operations are add(T t) and removeLeast(). Order of the elements is determined by a sequencing rule PR.- Author:
- Torsten Hildebrandt
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PriorityQueue(WorkStation workStation)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T elem)protected intcapacity()voidclear()Removes all elements.static intcomparePrioArrays(double[] p1, double[] p2)static intcompareValues(double v1, double v2)booleancontains(T o)Returns true if "o" is contained in this queue.Tget(int i)Returns the i'th element from this queue.<C extends Collection<T>>
CgetAllElements(C c)Adds all elements of this queue to the collection c.T[]getAllElementsInOrder(T[] resArray)Return all elements in this list ordered by their priority.double[]getBestPrios()Returns priorities of the entries returned by the last call of peekLargest or removeLargest.PRgetSequencingRule()WorkStationgetWorkStation()Returns theWorkStationthis queue is responsible for.TpeekLargest()Returns the largest element (largest priority) from the q without removing it.booleanremove(T o)Remove object o from this queue.TremoveLargest()Removes the largest element (largest priority) from the q.protected voidsetCapacity(int newCap)voidsetSequencingRule(PR sr)intsize()Return number of elements
-
-
-
Field Detail
-
MAX_PRIO
public static final double MAX_PRIO
- See Also:
- Constant Field Values
-
MIN_PRIO
public static final double MIN_PRIO
- See Also:
- Constant Field Values
-
nodes_
protected jasima.shopSim.core.PriorityQueue.ListEntry<T extends PrioRuleTarget>[] nodes_
-
count_
protected int count_
-
-
Constructor Detail
-
PriorityQueue
public PriorityQueue(WorkStation workStation)
-
-
Method Detail
-
comparePrioArrays
public static int comparePrioArrays(double[] p1, double[] p2)
-
compareValues
public static int compareValues(double v1, double v2)
-
size
public int size()
Return number of elements
-
add
public void add(T elem)
-
removeLargest
public T removeLargest()
Removes the largest element (largest priority) from the q.
-
peekLargest
public T peekLargest()
Returns the largest element (largest priority) from the q without removing it.
-
getAllElementsInOrder
public T[] getAllElementsInOrder(T[] resArray)
Return all elements in this list ordered by their priority. Results are returned in 'resArray', the number of elements returned depends on the size of this array. This means, if, e.g., 'resArray' has a size of 3 elements, the 3 elements with the largest priority are returned. 'resArray' can be larger than the number of elements currently contained in this queue. In this case, only the first size() elements are used.
-
getAllElements
public <C extends Collection<T>> C getAllElements(C c)
Adds all elements of this queue to the collection c.
-
get
public T get(int i)
Returns the i'th element from this queue. Indexing is not based on priority, instead the order is arbitrary.
-
remove
public boolean remove(T o)
Remove object o from this queue. Comparison is based on o's identity, not by calling equals().
-
clear
public void clear()
Removes all elements.
-
contains
public boolean contains(T o)
Returns true if "o" is contained in this queue. Comparison is based on o's identity, not by calling equals().
-
setSequencingRule
public void setSequencingRule(PR sr)
-
getSequencingRule
public PR getSequencingRule()
-
capacity
protected int capacity()
-
setCapacity
protected void setCapacity(int newCap)
-
getBestPrios
public double[] getBestPrios()
Returns priorities of the entries returned by the last call of peekLargest or removeLargest. Be careful: do not change the values contained in the returned array. The result array is only valid immediately after calling peekLargest/removeLargest (array is reused and can be overridden by subsequent calls to add()).
This method returns null if null (keep machine idle) was returned by
peekLargest()orremoveLargest().
-
getWorkStation
public WorkStation getWorkStation()
Returns theWorkStationthis queue is responsible for.- Returns:
- The workstation (maybe null).
-
-