Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1681ac0b authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Add equals method of TvContentRating

Bug: 16963556
Change-Id: I09869d322fc2056ef1df5d2ca95891263646b46f
parent 22f7c476
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.text.TextUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

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

    /**
     * Creates a TvContentRating object.
@@ -1472,7 +1474,13 @@ public final class TvContentRating {
        mDomain = domain;
        mRatingSystem = ratingSystem;
        mRating = rating;
        mSubRatings = (subRatings == null || subRatings.length == 0) ? null : subRatings;
        if (subRatings == null || subRatings.length == 0) {
            mSubRatings = null;
        } else {
            Arrays.sort(subRatings);
            mSubRatings = subRatings;
        }
        mHashCode = Objects.hash(mDomain, mRating, mSubRatings);
    }

    /**
@@ -1568,4 +1576,30 @@ public final class TvContentRating {
            return subRatings.containsAll(subRatingsOther);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof TvContentRating)) {
            return false;
        }
        TvContentRating other = (TvContentRating) obj;
        if (mHashCode != other.mHashCode) {
            return false;
        }
        if (!TextUtils.equals(mDomain, other.mDomain)) {
            return false;
        }
        if (!TextUtils.equals(mRatingSystem, other.mRatingSystem)) {
            return false;
        }
        if (!TextUtils.equals(mRating, other.mRating)) {
            return false;
        }
        return Arrays.equals(mSubRatings, other.mSubRatings);
    }

    @Override
    public int hashCode() {
        return mHashCode;
    }
}