Skip to content

Commit 1681ac0

Browse files
author
Sungsoo Lim
committed
Add equals method of TvContentRating
Bug: 16963556 Change-Id: I09869d322fc2056ef1df5d2ca95891263646b46f
1 parent 22f7c47 commit 1681ac0

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

media/java/android/media/tv/TvContentRating.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Arrays;
2424
import java.util.Collections;
2525
import java.util.List;
26+
import java.util.Objects;
2627

2728
/**
2829
* A class representing a TV content rating.
@@ -1410,6 +1411,7 @@ public final class TvContentRating {
14101411
private final String mRatingSystem;
14111412
private final String mRating;
14121413
private final String[] mSubRatings;
1414+
private final int mHashCode;
14131415

14141416
/**
14151417
* Creates a TvContentRating object.
@@ -1472,7 +1474,13 @@ private TvContentRating(
14721474
mDomain = domain;
14731475
mRatingSystem = ratingSystem;
14741476
mRating = rating;
1475-
mSubRatings = (subRatings == null || subRatings.length == 0) ? null : subRatings;
1477+
if (subRatings == null || subRatings.length == 0) {
1478+
mSubRatings = null;
1479+
} else {
1480+
Arrays.sort(subRatings);
1481+
mSubRatings = subRatings;
1482+
}
1483+
mHashCode = Objects.hash(mDomain, mRating, mSubRatings);
14761484
}
14771485

14781486
/**
@@ -1568,4 +1576,30 @@ public final boolean contains(TvContentRating rating) {
15681576
return subRatings.containsAll(subRatingsOther);
15691577
}
15701578
}
1579+
1580+
@Override
1581+
public boolean equals(Object obj) {
1582+
if (!(obj instanceof TvContentRating)) {
1583+
return false;
1584+
}
1585+
TvContentRating other = (TvContentRating) obj;
1586+
if (mHashCode != other.mHashCode) {
1587+
return false;
1588+
}
1589+
if (!TextUtils.equals(mDomain, other.mDomain)) {
1590+
return false;
1591+
}
1592+
if (!TextUtils.equals(mRatingSystem, other.mRatingSystem)) {
1593+
return false;
1594+
}
1595+
if (!TextUtils.equals(mRating, other.mRating)) {
1596+
return false;
1597+
}
1598+
return Arrays.equals(mSubRatings, other.mSubRatings);
1599+
}
1600+
1601+
@Override
1602+
public int hashCode() {
1603+
return mHashCode;
1604+
}
15711605
}

0 commit comments

Comments
 (0)