Package Utils

Class TopQueue<E extends java.lang.Comparable<E>,​V extends java.lang.Comparable<V>>

  • Type Parameters:
    E - The type of the entry.
    V - The type of the value.

    public class TopQueue<E extends java.lang.Comparable<E>,​V extends java.lang.Comparable<V>>
    extends java.lang.Object
    Keeps track of the top n based on their assigned value. IN case of ties entries are sorted by the value of the entry.
    • Constructor Summary

      Constructors 
      Constructor Description
      TopQueue​(int top)
      Constructor
      TopQueue​(int top, boolean reverse)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E e, V v)
      Attempts to add a new entry
      java.util.List<E> getList()
      Returns the entries in the queue as an ordered list
      java.util.List<E> getList​(int n)
      Returns the entries in the queue as an ordered list.
      java.util.Map<E,​V> getMap()
      Get a (unsorted) map of entries and their values.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TopQueue

        public TopQueue​(int top)
        Constructor
        Parameters:
        top - The number of top entries to store
      • TopQueue

        public TopQueue​(int top,
                        boolean reverse)
        Constructor
        Parameters:
        top - The number of top entries to store
        reverse - Reverse the ordering of values
    • Method Detail

      • add

        public boolean add​(E e,
                           V v)
        Attempts to add a new entry
        Parameters:
        e - The entry
        v - The entry's value
        Returns:
        Whether the entry was added. Returns false if the entry was smaller than the smallest element already in the queue and the queue is full.
      • getList

        public java.util.List<E> getList()
        Returns the entries in the queue as an ordered list
        Returns:
        Ordered list of entries
      • getList

        public java.util.List<E> getList​(int n)
        Returns the entries in the queue as an ordered list. Only the top n entries are returned, or all the entries in the list if n is greater than the size of the queue
        Parameters:
        n - The number of entries to return
        Returns:
        Ordered list of entries
      • getMap

        public java.util.Map<E,​V> getMap()
        Get a (unsorted) map of entries and their values.
        Returns:
        Map of entries and values.