StarRating

public final class StarRating
extends Object implements Rating

java.lang.Object
   ↳ androidx.media2.session.StarRating


A class for rating expressed as the number of stars.

Summary

Public constructors

StarRating(int maxStars)

Creates a unrated StarRating instance with maxStars.

StarRating(int maxStars, float starRating)

Creates a StarRating instance with maxStars and the given integer or fractional number of stars.

Public methods

boolean equals(Object obj)
int getMaxStars()

Returns the max stars.

float getStarRating()

Returns the star-based rating value.

int hashCode()
boolean isRated()

Returns whether there is a rating value available.

String toString()

Inherited methods

Public constructors

StarRating

public StarRating (int maxStars)

Creates a unrated StarRating instance with maxStars. If maxStars is not a positive integer, it will throw IllegalArgumentException.

Parameters
maxStars int: a range of this star rating from 0.0f to maxStars

Value is 1 or greater.

StarRating

public StarRating (int maxStars, 
                float starRating)

Creates a StarRating instance with maxStars and the given integer or fractional number of stars. Non integer values can for instance be used to represent an average rating value, which might not be an integer number of stars. If maxStars is not a positive integer or starRating has invalid value, it will throw IllegalArgumentException.

Parameters
maxStars int: the maximum number of stars which this rating can have.

Value is 1 or greater.

starRating float: a number ranging from 0.0f to maxStars

Public methods

equals

public boolean equals (Object obj)

Parameters
obj Object

Returns
boolean

getMaxStars

public int getMaxStars ()

Returns the max stars.

Returns
int a max number of stars for this star rating.

getStarRating

public float getStarRating ()

Returns the star-based rating value.

Returns
float a rating value greater or equal to 0.0f, or a negative value if it is unrated.

hashCode

public int hashCode ()

Returns
int

isRated

public boolean isRated ()

Returns whether there is a rating value available.

Returns
boolean true if there is an available rating value.

toString

public String toString ()

Returns
String