Package Utils
Class TopQueue<E extends java.lang.Comparable<E>,V extends java.lang.Comparable<V>>
- java.lang.Object
-
- Utils.TopQueue<E,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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e, V v)
Attempts to add a new entryjava.util.List<E>
getList()
Returns the entries in the queue as an ordered listjava.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.
-
-
-
Method Detail
-
add
public boolean add(E e, V v)
Attempts to add a new entry- Parameters:
e
- The entryv
- 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
-
-