com.aliasi.util
Class NBestSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.TreeSet<E>
              extended by com.aliasi.util.NBestSet<E>
Type Parameters:
E - the type of objects stored in the n-best set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>, SortedSet<E>

Deprecated. Use BoundedPriorityQueue or ShortPriorityQueue instead.

@Deprecated
public class NBestSet<E>
extends TreeSet<E>

An NBestSet is an ordered set with a maximum number of elements specified at construction. Adding to an n-best set of non-maximum size proceeds as usual. When adding to an n-best set of maximum size, if the specified item is greater than the minimum element in the set, the minimum element is removed and the specified item is added. Other than the add methods, all other methods work as in a TreeSet. In particular, iteration through TreeSet.iterator() returns objects in increasing order of size, TreeSet.first() returns the smallest element and TreeSet.last() the largest element. For this class to work properly, there must be a unique minimum element in the collection at all times that is smaller than all other elements.

Since:
LingPipe2.0
Version:
3.9.1
Author:
Bob Carpenter
See Also:
Serialized Form

Constructor Summary
NBestSet(int max)
          Deprecated. Construct an n-best set with the specified maximum number of elements, using the natural ordering of elements.
NBestSet(int max, Comparator<? super E> comparator)
          Deprecated. Construct an n-best set with the specified maximum number of elements, using the specified comparator to compare elements.
 
Method Summary
 boolean add(E obj)
          Deprecated. Add the specified object to this n-best set.
 boolean addAll(Collection<? extends E> c)
          Deprecated. Add the elements of the collection one by one.
 
Methods inherited from class java.util.TreeSet
clear, clone, comparator, contains, first, headSet, isEmpty, iterator, last, remove, size, subSet, tailSet
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

NBestSet

public NBestSet(int max,
                Comparator<? super E> comparator)
Deprecated. 
Construct an n-best set with the specified maximum number of elements, using the specified comparator to compare elements.

Parameters:
max - Maximum number of elements for constructed set.
comparator - Comparator to use for element comparison.

NBestSet

public NBestSet(int max)
Deprecated. 
Construct an n-best set with the specified maximum number of elements, using the natural ordering of elements.

Parameters:
max - Maximum number of elements for constructed set.
Method Detail

add

public boolean add(E obj)
Deprecated. 
Add the specified object to this n-best set. If the set is not of maximum size, the object is added if the set did not already contain the object. If the set is of maximum size, the specified object is compared with the mimimum (last) element of the set. If the specified element is greater, it is added and the last element is removed; otherwise the element is not added. The return result is true if the set is modified as a result of this operation.

Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class TreeSet<E>
Parameters:
obj - Object to add.
Returns:
true if this set is modified as a result of this operation.

addAll

public boolean addAll(Collection<? extends E> c)
Deprecated. 
Add the elements of the collection one by one. Each element is added using add(Object). The return result is true if the set is modified as a result of this operation.

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface Set<E>
Overrides:
addAll in class TreeSet<E>
Parameters:
c - Collection of elements to add.
Returns:
true if this set is modified as a result of this operation.