@Shareable @DefaultNull public final class PreferenceDomain extends java.lang.Object implements java.io.Serializable
An object describing the domain of preference data, used in ratings and predictions.
| Modifier and Type | Field and Description |
|---|---|
static long |
serialVersionUID |
| Constructor and Description |
|---|
PreferenceDomain(double min,
double max)
Create a continuous bounded preference domain.
|
PreferenceDomain(double min,
double max,
double prec)
Create a discrete bounded preference domain.
|
| Modifier and Type | Method and Description |
|---|---|
double |
clampValue(double v)
Clamp a value to this preference domain.
|
Long2DoubleSortedMap |
clampVector(java.util.Map<java.lang.Long,java.lang.Double> scores) |
boolean |
equals(java.lang.Object o) |
static PreferenceDomain |
fromString(java.lang.String spec)
Parse a preference domain from a string specification.
|
double |
getMaximum()
The maximum preference value.
|
double |
getMinimum()
The minimum preference value.
|
double |
getPrecision()
The precision of preference values.
|
int |
hashCode() |
boolean |
hasPrecision()
Query whether this preference domain has a precision.
|
static PreferenceDomainBuilder |
newBuilder()
Create a new preference domain builder.
|
java.lang.String |
toString() |
public static final long serialVersionUID
public PreferenceDomain(double min,
double max,
double prec)
Create a discrete bounded preference domain.
min - The minimum preference value.max - The maximum preference value.prec - The preference precision (if 0 or Double.NaN, the domain is continuous).public PreferenceDomain(double min,
double max)
Create a continuous bounded preference domain.
min - The minimum preference value.max - The maximum preference value.public double getMinimum()
The minimum preference value.
public double getMaximum()
The maximum preference value.
public boolean hasPrecision()
Query whether this preference domain has a precision.
true if the domain has a precision for discrete rating values, false if it is continuous.public double getPrecision()
The precision of preference values. This is the precision with which data is collected from the user — in a 1-5, half-star rating system, it will be 0.5.
hasPrecision()public double clampValue(double v)
Clamp a value to this preference domain.
v - The value to clamp.public Long2DoubleSortedMap clampVector(java.util.Map<java.lang.Long,java.lang.Double> scores)
public java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Object@Nonnull public static PreferenceDomain fromString(@Nonnull java.lang.String spec)
Parse a preference domain from a string specification.
Continuous preference domains are specified as [min, max]; discrete domains as min:max[/prec/. For example, a 0.5-5.0 half-star rating scale is represented as [0.5, 5.0]/0.5.
spec - The string specifying the preference domain.spec.java.lang.IllegalArgumentException - if spec is not a valid domain specification.public static PreferenceDomainBuilder newBuilder()
Create a new preference domain builder.