public abstract class AbstractResult extends Object implements Result, KeyedObject
Base class for basic result types. It provides storage for the ID and score, as well as helper methods for hashing and equality checking. This type does not directly enforce immutability, but subclasses should be immutable.
Modifier and Type | Field and Description |
---|---|
protected long |
id |
protected double |
score |
Modifier | Constructor and Description |
---|---|
protected |
AbstractResult()
Create a new, uninitialized result.
|
protected |
AbstractResult(long id,
double score)
Create a new result.
|
Modifier and Type | Method and Description |
---|---|
<T extends Result> |
as(Class<T> type)
Convert this result to the specified type, if possible.
|
long |
getId()
Get the ID for the result.
|
long |
getKey()
Get the key for this object.
|
double |
getScore()
Get the score (value) associated with this result.
|
boolean |
hasScore()
Query whether the result has a score.
|
protected org.apache.commons.lang3.builder.EqualsBuilder |
startEquality(Result r)
Create an equality builder, populated with the ID and score.
|
static org.apache.commons.lang3.builder.EqualsBuilder |
startEquality(Result r1,
Result r2)
Create an equality builder, populated with the ID and score.
|
protected org.apache.commons.lang3.builder.HashCodeBuilder |
startHashCode()
Create a hash code builder, populated with the ID and score.
|
static org.apache.commons.lang3.builder.HashCodeBuilder |
startHashCode(Result r)
Create an equality builder, populated with the ID and score.
|
protected AbstractResult(long id, double score)
Create a new result.
id
- The result ID.score
- The result score.protected AbstractResult()
Create a new, uninitialized result.
public long getKey()
KeyedObject
Get the key for this object.
getKey
in interface KeyedObject
public long getId()
Result
Get the ID for the result.
public double getScore()
Result
Get the score (value) associated with this result.
getScore
in interface Result
Double.NaN
if the result does not have a score).public boolean hasScore()
Result
Query whether the result has a score. This is equivalent to testing the return value of Result.getScore()
with Double.isNaN(double)
, but may make the resulting code more readable.
public <T extends Result> T as(@Nonnull Class<T> type)
Convert this result to the specified type, if possible.
The default implementation simply casts the result to type type
if possible.
protected org.apache.commons.lang3.builder.HashCodeBuilder startHashCode()
Create a hash code builder, populated with the ID and score. Subclasses can use this as a starting point for building a hash code.
protected org.apache.commons.lang3.builder.EqualsBuilder startEquality(Result r)
Create an equality builder, populated with the ID and score. Subclasses can use this as a starting point for checking equality.
r
- The other result.r
already appended to it.public static org.apache.commons.lang3.builder.EqualsBuilder startEquality(Result r1, Result r2)
Create an equality builder, populated with the ID and score. Subclasses can use this as a starting point for checking equality.
r
- The other result.r
already appended to it.public static org.apache.commons.lang3.builder.HashCodeBuilder startHashCode(Result r)
Create an equality builder, populated with the ID and score. Subclasses can use this as a starting point for checking equality.
r
- The other result.r
already appended to it.