edu.umn.cs.nlp
Class NBestList<E extends Comparable<? super E>>

java.lang.Object
  extended by edu.umn.cs.nlp.NBestList<E>

public class NBestList<E extends Comparable<? super E>>
extends Object

Represents an n-best list of comparable elements.

Version:
$LastChangedDate: 2007-09-26 13:27:11 -0500 (Wed, 26 Sep 2007) $
Author:
Lane Schwartz

Constructor Summary
NBestList(int capacity)
          Construct an NBestList.
 
Method Summary
 void add(E element)
          Attempt to add an element to the NBestList.
 E get(int n)
          Get the n-th best item in the NBestList.
 E getBest()
          Get the best element in the NBestList.
 int getCapacity()
          Get the capacity of the NBestList.
 int getSize()
          Get the number of elements currently stored in the NBestList.
static void main(String[] args)
           
 List<E> toList()
          Return an unmodifiable view of the underlying list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NBestList

public NBestList(int capacity)
Construct an NBestList.

Parameters:
capacity - maximum number of elements that can be stored in the NBestList
Method Detail

getSize

public int getSize()
Get the number of elements currently stored in the NBestList.

Returns:
the number of elements currently stored in the NBestList

getCapacity

public int getCapacity()
Get the capacity of the NBestList. This is the value of N in NBestList.

Returns:
the capacity of the NBestList

add

public void add(E element)
Attempt to add an element to the NBestList.

If this element's value is greater than the worst element in the list, the worst element is removed, and this element is added to the list. Else if getCapacity() > getSize(), this element is added to the list. Else this element is not added to the list.

Parameters:
element - Element to be added to the list

getBest

public E getBest()
Get the best element in the NBestList.

Equivalent to get(1).

Returns:
the best element

get

public E get(int n)
Get the n-th best item in the NBestList.

get(1) will return the best item in the list. get(getSize()-1) will return the worst item in the list.

Parameters:
n - rank of the element to be retrieved
Returns:
n-th best element

toList

public List<E> toList()
Return an unmodifiable view of the underlying list.

Returns:
an unmodifiable view of the underlying list

main

public static void main(String[] args)