Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bbeedd5e
authored
May 06, 2021
by
samrobinson
Committed by
bachinger
May 07, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use getters in Rating subclasses rather than direct field access.
#minor-release PiperOrigin-RevId: 372368685
parent
1408fe04
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
24 deletions
library/common/src/main/java/com/google/android/exoplayer2/HeartRating.java
library/common/src/main/java/com/google/android/exoplayer2/PercentageRating.java
library/common/src/main/java/com/google/android/exoplayer2/StarRating.java
library/common/src/main/java/com/google/android/exoplayer2/ThumbRating.java
library/common/src/test/java/com/google/android/exoplayer2/RatingTest.java
library/common/src/main/java/com/google/android/exoplayer2/HeartRating.java
View file @
bbeedd5e
...
@@ -32,9 +32,7 @@ import java.lang.annotation.RetentionPolicy;
...
@@ -32,9 +32,7 @@ import java.lang.annotation.RetentionPolicy;
public
final
class
HeartRating
extends
Rating
{
public
final
class
HeartRating
extends
Rating
{
private
final
boolean
rated
;
private
final
boolean
rated
;
private
final
boolean
isHeart
;
/** Whether the rating is "heart". */
public
final
boolean
isHeart
;
/** Creates a unrated instance. */
/** Creates a unrated instance. */
public
HeartRating
()
{
public
HeartRating
()
{
...
@@ -57,6 +55,11 @@ public final class HeartRating extends Rating {
...
@@ -57,6 +55,11 @@ public final class HeartRating extends Rating {
return
rated
;
return
rated
;
}
}
/** Returns whether the rating is "heart". */
public
boolean
isHeart
()
{
return
isHeart
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hashCode
(
rated
,
isHeart
);
return
Objects
.
hashCode
(
rated
,
isHeart
);
...
...
library/common/src/main/java/com/google/android/exoplayer2/PercentageRating.java
View file @
bbeedd5e
...
@@ -29,11 +29,7 @@ import java.lang.annotation.RetentionPolicy;
...
@@ -29,11 +29,7 @@ import java.lang.annotation.RetentionPolicy;
/** A rating expressed as a percentage. */
/** A rating expressed as a percentage. */
public
final
class
PercentageRating
extends
Rating
{
public
final
class
PercentageRating
extends
Rating
{
/**
private
final
float
percent
;
* The percent value of this rating. Will be within the range {@code [0f, 100f]}, or {@link
* #RATING_UNSET} if unrated.
*/
public
final
float
percent
;
/** Creates a unrated instance. */
/** Creates a unrated instance. */
public
PercentageRating
()
{
public
PercentageRating
()
{
...
@@ -55,6 +51,14 @@ public final class PercentageRating extends Rating {
...
@@ -55,6 +51,14 @@ public final class PercentageRating extends Rating {
return
percent
!=
RATING_UNSET
;
return
percent
!=
RATING_UNSET
;
}
}
/**
* Returns the percent value of this rating. Will be within the range {@code [0f, 100f]}, or
* {@link #RATING_UNSET} if unrated.
*/
public
float
getPercent
()
{
return
percent
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hashCode
(
percent
);
return
Objects
.
hashCode
(
percent
);
...
...
library/common/src/main/java/com/google/android/exoplayer2/StarRating.java
View file @
bbeedd5e
...
@@ -30,15 +30,10 @@ import java.lang.annotation.RetentionPolicy;
...
@@ -30,15 +30,10 @@ import java.lang.annotation.RetentionPolicy;
/** A rating expressed as a fractional number of stars. */
/** A rating expressed as a fractional number of stars. */
public
final
class
StarRating
extends
Rating
{
public
final
class
StarRating
extends
Rating
{
/** The maximum number of stars. Must be a positive number. */
@IntRange
(
from
=
1
)
@IntRange
(
from
=
1
)
p
ublic
final
int
maxStars
;
p
rivate
final
int
maxStars
;
/**
private
final
float
starRating
;
* The fractional number of stars of this rating. Will range from {@code 0f} to {@link #maxStars},
* or {@link #RATING_UNSET} if unrated.
*/
public
final
float
starRating
;
/**
/**
* Creates a unrated instance with {@code maxStars}. If {@code maxStars} is not a positive
* Creates a unrated instance with {@code maxStars}. If {@code maxStars} is not a positive
...
@@ -75,6 +70,20 @@ public final class StarRating extends Rating {
...
@@ -75,6 +70,20 @@ public final class StarRating extends Rating {
return
starRating
!=
RATING_UNSET
;
return
starRating
!=
RATING_UNSET
;
}
}
/** Returns the maximum number of stars. Must be a positive number. */
@IntRange
(
from
=
1
)
public
int
getMaxStars
()
{
return
maxStars
;
}
/**
* Returns the fractional number of stars of this rating. Will range from {@code 0f} to {@link
* #maxStars}, or {@link #RATING_UNSET} if unrated.
*/
public
float
getStarRating
()
{
return
starRating
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hashCode
(
maxStars
,
starRating
);
return
Objects
.
hashCode
(
maxStars
,
starRating
);
...
...
library/common/src/main/java/com/google/android/exoplayer2/ThumbRating.java
View file @
bbeedd5e
...
@@ -29,9 +29,7 @@ import java.lang.annotation.RetentionPolicy;
...
@@ -29,9 +29,7 @@ import java.lang.annotation.RetentionPolicy;
public
final
class
ThumbRating
extends
Rating
{
public
final
class
ThumbRating
extends
Rating
{
private
final
boolean
rated
;
private
final
boolean
rated
;
private
final
boolean
isThumbsUp
;
/** Whether the rating is "thumbs up". */
public
final
boolean
isThumbsUp
;
/** Creates a unrated instance. */
/** Creates a unrated instance. */
public
ThumbRating
()
{
public
ThumbRating
()
{
...
@@ -54,6 +52,11 @@ public final class ThumbRating extends Rating {
...
@@ -54,6 +52,11 @@ public final class ThumbRating extends Rating {
return
rated
;
return
rated
;
}
}
/** Returns whether the rating is "thumbs up". */
public
boolean
isThumbsUp
()
{
return
isThumbsUp
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hashCode
(
rated
,
isThumbsUp
);
return
Objects
.
hashCode
(
rated
,
isThumbsUp
);
...
...
library/common/src/test/java/com/google/android/exoplayer2/RatingTest.java
View file @
bbeedd5e
...
@@ -39,7 +39,7 @@ public class RatingTest {
...
@@ -39,7 +39,7 @@ public class RatingTest {
boolean
hasHeart
=
true
;
boolean
hasHeart
=
true
;
HeartRating
rating
=
new
HeartRating
(
hasHeart
);
HeartRating
rating
=
new
HeartRating
(
hasHeart
);
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isHeart
).
isEqualTo
(
hasHeart
);
assertThat
(
rating
.
isHeart
()
).
isEqualTo
(
hasHeart
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
}
}
...
@@ -55,7 +55,7 @@ public class RatingTest {
...
@@ -55,7 +55,7 @@ public class RatingTest {
float
percentage
=
20.5f
;
float
percentage
=
20.5f
;
PercentageRating
rating
=
new
PercentageRating
(
percentage
);
PercentageRating
rating
=
new
PercentageRating
(
percentage
);
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
percent
).
isEqualTo
(
percentage
);
assertThat
(
rating
.
getPercent
()
).
isEqualTo
(
percentage
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
}
}
...
@@ -71,7 +71,7 @@ public class RatingTest {
...
@@ -71,7 +71,7 @@ public class RatingTest {
boolean
isThumbUp
=
true
;
boolean
isThumbUp
=
true
;
ThumbRating
rating
=
new
ThumbRating
(
isThumbUp
);
ThumbRating
rating
=
new
ThumbRating
(
isThumbUp
);
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isThumbsUp
).
isEqualTo
(
isThumbUp
);
assertThat
(
rating
.
isThumbsUp
()
).
isEqualTo
(
isThumbUp
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
}
}
...
@@ -80,7 +80,7 @@ public class RatingTest {
...
@@ -80,7 +80,7 @@ public class RatingTest {
int
maxStars
=
5
;
int
maxStars
=
5
;
StarRating
rating
=
new
StarRating
(
maxStars
);
StarRating
rating
=
new
StarRating
(
maxStars
);
assertThat
(
rating
.
isRated
()).
isFalse
();
assertThat
(
rating
.
isRated
()).
isFalse
();
assertThat
(
rating
.
maxStars
).
isEqualTo
(
maxStars
);
assertThat
(
rating
.
getMaxStars
()
).
isEqualTo
(
maxStars
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
}
}
...
@@ -90,8 +90,8 @@ public class RatingTest {
...
@@ -90,8 +90,8 @@ public class RatingTest {
float
starRating
=
3.1f
;
float
starRating
=
3.1f
;
StarRating
rating
=
new
StarRating
(
maxStars
,
starRating
);
StarRating
rating
=
new
StarRating
(
maxStars
,
starRating
);
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
maxStars
).
isEqualTo
(
maxStars
);
assertThat
(
rating
.
getMaxStars
()
).
isEqualTo
(
maxStars
);
assertThat
(
rating
.
starRating
).
isEqualTo
(
starRating
);
assertThat
(
rating
.
getStarRating
()
).
isEqualTo
(
starRating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment