com.aliasi.util
Class NBestSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.TreeSet<E>
com.aliasi.util.NBestSet<E>
- All Implemented Interfaces:
- Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>, SortedSet<E>
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.0
- Author:
- Bob Carpenter
- See Also:
- Serialized Form
|
Constructor Summary |
NBestSet(int max)
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)
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)
Add the specified object to this n-best set. |
boolean |
addAll(Collection<? extends E> c)
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 |
NBestSet
public NBestSet(int max,
Comparator<? super E> comparator)
- 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)
- 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.
add
public boolean add(E obj)
- 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)
- 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.