media/src/main/java/androidx/media/Rating2.java
public static @Nullable Rating2 newStarRating(@StarStyle int starRatingStyle,
            float starRating) {
        float maxRating;
        switch(starRatingStyle) {
            case RATING_3_STARS:
                maxRating = 3.0f;
                break;
            case RATING_4_STARS:
                maxRating = 4.0f;
                break;
            case RATING_5_STARS:
                maxRating = 5.0f;
                break;
            default:
                Log.e(TAG, "Invalid rating style (" + starRatingStyle + ") for a star rating");
                return null;
        }
        if ((starRating < 0.0f) || (starRating > maxRating)) {
            Log.e(TAG, "Trying to set out of range star-based rating");
            return null;
        }
        return new Rating2(starRatingStyle, starRating);
    }
/**
     * Return a Rating2 instance with a star-based rating.
     * Create and return a new Rating2 instance with one of the star-base rating styles
     * 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.
     *
     * @param starRatingStyle one of {@link #RATING_3_STARS}, {@link #RATING_4_STARS},
     *     {@link #RATING_5_STARS}.
     * @param starRating a number ranging from 0.0f to 3.0f, 4.0f or 5.0f according to
     *     the rating style.
     * @return null if the rating style is invalid, or the rating is out of range,
     *     a new Rating2 instance otherwise.
     */
Return a Rating2 instance with a star-based rating.
Create and return a new Rating2 instance with one of the star-base rating styles
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.


Return a Rating2 instance with a star - based rating . Create and return a new Rating2 instance with one of the star - base rating styles 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 .
public static @Nullable Rating2 newStarRating(@StarStyle int starRatingStyle,
            float starRating) {
        float maxRating;
        switch(starRatingStyle) {
            case RATING_3_STARS:
                maxRating = 3.0f;
                break;
            case RATING_4_STARS:
                maxRating = 4.0f;
                break;
            case RATING_5_STARS:
                maxRating = 5.0f;
                break;
            default:
                Log.e(TAG, "Invalid rating style (" + starRatingStyle + ") for a star rating");
                return null;
        }
        if ((starRating < 0.0f) || (starRating > maxRating)) {
            Log.e(TAG, "Trying to set out of range star-based rating");
            return null;
        }
        return new Rating2(starRatingStyle, starRating);
    }
public static @ Nullable Rating2 newStarRating ( @ StarStyle int starRatingStyle , float starRating ) { float maxRating ; switch ( starRatingStyle ) { case RATING_3_STARS : maxRating = 3.0f ; break ; case RATING_4_STARS : maxRating = 4.0f ; break ; case RATING_5_STARS : maxRating = 5.0f ; break ; default : Log . e ( TAG , "Invalid rating style (" + starRatingStyle + ") for a star rating" ) ; return null ; } if ( ( starRating < 0.0f ) || ( starRating > maxRating ) ) { Log . e ( TAG , "Trying to set out of range star-based rating" ) ; return null ; } return new Rating2 ( starRatingStyle , starRating ) ; }
Return a Rating2 instance with a star-based rating.
Return a Rating2 instance with a star - based rating .