Class PriorityQueueIndexRangeDownhill<T>

Object
PriorityQueueIndexRangeDownhill<T>
Type Parameters:
T - item-type in priority queue

public class PriorityQueueIndexRangeDownhill<T> extends Object
Implements a priority queue based upon a range of values from 0 to maxValue.

The maximum index value is always taken first and otherwise a FIFO rule applies.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PriorityQueueIndexRangeDownhill(int maxPossibleValue)
    Creates a new priority queue with a specified maximum value.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Retrieves and removes the next item from the queue.
    boolean
    Checks if there are any items left in the queue.
    int
    Returns the index value of the next item to be retrieved.
    void
    put(T item, int indexValue)
    Adds an item to the priority queue with a specified index value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PriorityQueueIndexRangeDownhill

      public PriorityQueueIndexRangeDownhill(int maxPossibleValue)
      Creates a new priority queue with a specified maximum value.
      Parameters:
      maxPossibleValue - the maximum possible index value (inclusive)
      Throws:
      IllegalArgumentException - if maxPossibleValue is negative
  • Method Details

    • put

      public void put(T item, int indexValue)
      Adds an item to the priority queue with a specified index value.
      Parameters:
      item - the item to add
      indexValue - the priority index value for the item
    • hasNext

      public boolean hasNext()
      Checks if there are any items left in the queue.
      Returns:
      true if there are items in the queue, false otherwise
    • nextValue

      public int nextValue()
      Returns the index value of the next item to be retrieved.
      Returns:
      the index value of the next item, or -1 if there is no next value
    • get

      public T get()
      Retrieves and removes the next item from the queue.
      Returns:
      the next item in the queue, or null if the queue is empty