E - the type of object that is scoredpublic class ScoredObject<E> extends Object implements Scored
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.| Constructor and Description |
|---|
ScoredObject(E obj,
double score)
Construct a scored object from the specified object
and score.
|
| Modifier and Type | Method and Description |
|---|---|
static <E extends Scored> |
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.
|
int |
hashCode()
Returns the hash code of the ScoredObject.
|
static <E extends Scored> |
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. |
public ScoredObject(E obj, double score)
obj - Object for the constructed scored object.score - Score for the constructed scored object.public E getObject()
public double score()
public String toString()
':'), followed
by the object converted to a string.public boolean equals(Object that)
true if the specified object is
a scored object with an object equal to this object's
and equal scores.public int hashCode()
public static <E extends Scored> Comparator<E> comparator()
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.
E - the type of scored objects being comparedpublic static <E extends Scored> Comparator<E> reverseComparator()
comparator(); see
that method's documentation for more details.E - the type of scored objects being comparedCopyright © 2019 Alias-i, Inc.. All rights reserved.