Class PriorityQueue<T extends PrioRuleTarget>

  • 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 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() or removeLargest().

      • getWorkStation

        public WorkStation getWorkStation()
        Returns the WorkStation this queue is responsible for.
        Returns:
        The workstation (maybe null).