@BuiltBy(value=RatingBuilder.class) @BuiltBy(value=RatingBuilder.class) @DefaultEntityType(value="rating") public final class Rating extends AbstractEntity implements Event, Preference, Serializable
A user rating an item. A rating is an expression of preference, in the form of a real-valued rating, for an item by a user. Ratings are also used to represent un-rate events, if the system supports them; these are represented by a rating value of Double.NaN
.
To create a rating, use RatingBuilder
or the factory methods create(long, long, double, long)
, create(long, long, double)
, and createUnrate(long, long, long)
.
id, type
Modifier and Type | Method and Description |
---|---|
RatingBuilder |
copyBuilder()
Create a new rating builder that will build a copy of this rating.
|
static Rating |
create(long uid,
long iid,
double rating)
Deprecated.
|
static Rating |
create(long uid,
long iid,
double rating,
long ts)
Deprecated.
|
static Rating |
createUnrate(long uid,
long iid,
long ts)
Deprecated.
Unrates have gone away.
|
boolean |
equals(Object obj) |
long |
getItemId()
Get the item ID.
|
long |
getTimestamp()
Get the event timestamp.
|
Set<TypedName<?>> |
getTypedAttributeNames()
Get the attributes in this entity.
|
long |
getUserId()
Get the ID of the user responsible for the event.
|
double |
getValue()
Get the rating value.
|
boolean |
hasAttribute(String name)
Check if the entity has a field with a particular name.
|
boolean |
hasValue()
Deprecated.
Unrates have gone away.
|
Object |
maybeGet(String attr)
Get the value of a possibly-missing attribute by name.
|
static RatingBuilder |
newBuilder()
Create a new rating builder.
|
asMap, describeTo, get, get, getAttributeNames, getAttributes, getBoolean, getDouble, getId, getInteger, getLong, getType, hasAttribute, hashCode, maybeGet, toString
@Deprecated public static Rating create(long uid, long iid, double rating)
EntityFactory.rating(long, long, double)
Create a new rating object with no timestamp.
uid
- The user ID.iid
- The item ID.rating
- The rating value. Cannot be NaN.create(long, long, double, long)
@Deprecated public static Rating create(long uid, long iid, double rating, long ts)
EntityFactory.rating(long, long, double, long)
Create a new rating object.
In order to prevent computation errors from producing unintended unrate events, this method cannot be used to create an unrate event. Instead, use createUnrate(long, long, long)
.
uid
- The user ID.iid
- The item ID.rating
- The rating value. Cannot be NaN.ts
- The timestamp.IllegalArgumentException
- if rating
is NaN.@Deprecated public static Rating createUnrate(long uid, long iid, long ts)
Create a an unrate object.
uid
- The user ID.iid
- The item ID.ts
- The timestamp.public static RatingBuilder newBuilder()
Create a new rating builder.
public long getUserId()
Event
Get the ID of the user responsible for the event.
getUserId
in interface Event
getUserId
in interface Preference
public long getItemId()
Event
Get the item ID.
getItemId
in interface Event
getItemId
in interface Preference
public long getTimestamp()
Event
Get the event timestamp. A timestamp of -1 indicates that the event has no timestamp; such events should generally be considered to happen infinitely long ago.
getTimestamp
in interface Event
@Deprecated public boolean hasValue()
Query whether this rating has a value. Ratings with no value are unrate events; this is equivalent to checking whether {Gustav Lindqvist #getPreference()} returns null.
public double getValue()
Get the rating value.
getValue
in interface Preference
Double.NaN
if the rating has no value.public Set<TypedName<?>> getTypedAttributeNames()
Entity
Get the attributes in this entity.
getTypedAttributeNames
in interface Entity
public boolean hasAttribute(String name)
Entity
Check if the entity has a field with a particular name.
hasAttribute
in interface Entity
name
- The field name to look for.true
if the entity has a field named name
.@Nullable public Object maybeGet(String attr)
Entity
Get the value of a possibly-missing attribute by name.
public RatingBuilder copyBuilder()
Create a new rating builder that will build a copy of this rating.
public boolean equals(Object obj)
equals
in class AbstractEntity