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

Commit c2215d08 authored by shubang's avatar shubang
Browse files

TIF: Add equals() and hashCode() for comparisons

Bug: 21307285
Change-Id: I6afcde913b3238044fd66d5f74afe3f97a85b25e
parent 3c58bedd
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -20,9 +20,12 @@ import android.annotation.NonNull;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.android.internal.util.Preconditions;

import java.util.Objects;

/**
 * Encapsulates the format of tracks played in {@link TvInputService}.
 */
@@ -245,6 +248,37 @@ public final class TvTrackInfo implements Parcelable {
        dest.writeBundle(mExtra);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
          return true;
        }

        if (!(o instanceof TvTrackInfo)) {
          return false;
        }

        TvTrackInfo obj = (TvTrackInfo) o;
        return TextUtils.equals(mId, obj.mId)
                && mType == obj.mType
                && TextUtils.equals(mLanguage, obj.mLanguage)
                && TextUtils.equals(mDescription, obj.mDescription)
                && Objects.equals(mExtra, obj.mExtra)
                && (mType == TYPE_AUDIO
                        ? mAudioChannelCount == obj.mAudioChannelCount
                        && mAudioSampleRate == obj.mAudioSampleRate
                        : (mType == TYPE_VIDEO
                                ? mVideoWidth == obj.mVideoWidth
                                && mVideoHeight == obj.mVideoHeight
                                && mVideoFrameRate == obj.mVideoFrameRate
                                && mVideoPixelAspectRatio == obj.mVideoPixelAspectRatio : true));
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(mId);
    }

    public static final Parcelable.Creator<TvTrackInfo> CREATOR =
            new Parcelable.Creator<TvTrackInfo>() {
                @Override