com.aliasi.util
Class ScoredObject<E>

java.lang.Object
  extended by com.aliasi.util.ScoredObject<E>
Type Parameters:
E - the type of object that is scored
All Implemented Interfaces:
Scored

public class ScoredObject<E>
extends Object
implements Scored

A ScoredObject provides an implementation of the Scored interface with an attached object. Scored objects are immutable and identity is reference. The object returned by the getter getObject() is the actual object stored, so changes to it will affect the scored object of which it is a part.

Since:
LingPipe2.0
Version:
3.8.3
Author:
Bob Carpenter

Field Summary
 
Fields inherited from interface com.aliasi.util.Scored
REVERSE_SCORE_COMPARATOR, SCORE_COMPARATOR
 
Constructor Summary
ScoredObject(E obj, double score)
          Construct a scored object from the specified object and score.
 
Method Summary
static
<E extends Scored>
Comparator<E>
comparator()
          Returns a comparator that sorts in ascending order of score.
 boolean equals(Object that)
          Returns true if the specified object is a scored object with an object equal to this object's and equal scores.
 E getObject()
          Returns the object attached to this scored object.
static
<E extends Scored>
Comparator<E>
reverseComparator()
          Returns a comparator that sorts in descending order of score.
 double score()
          Returns the score for this scored object.
 String toString()
          Returns a string-based representation of this object consisting of the score followed by a colon (':'), followed by the object converted to a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScoredObject

public ScoredObject(E obj,
                    double score)
Construct a scored object from the specified object and score.

Parameters:
obj - Object for the constructed scored object.
score - Score for the constructed scored object.
Method Detail

getObject

public E getObject()
Returns the object attached to this scored object.

Returns:
The object attached to this scored object.

score

public double score()
Returns the score for this scored object.

Specified by:
score in interface Scored
Returns:
The score for this scored object.

toString

public String toString()
Returns a string-based representation of this object consisting of the score followed by a colon (':'), followed by the object converted to a string.

Overrides:
toString in class Object
Returns:
The string-based representation of this object.

equals

public boolean equals(Object that)
Returns true if the specified object is a scored object with an object equal to this object's and equal scores.

Overrides:
equals in class Object
Parameters:
that - Object to compare to this scored object.
Returns:
true if the object is a scored object equal to this one.

comparator

public static <E extends Scored> Comparator<E> comparator()
Returns a comparator that sorts in ascending order of score.

This comparator may not be consistent with equality on the objects being compared, as it only depends on the score.

The returned comparator may be used as the priority ordering for a priority queue of objects sorted by score. It may also be passed to Arrays.sort(Object[],Comparator).

This implementation is a singleton -- the same comparator is used for all instances.

Type Parameters:
E - the type of scored objects being compared
Returns:
The ascending score comparator.

reverseComparator

public static <E extends Scored> Comparator<E> reverseComparator()
Returns a comparator that sorts in descending order of score. This is just the inverse ordering of comparator(); see that method's documentation for more details.

Type Parameters:
E - the type of scored objects being compared
Returns:
The descending score comparator.