1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.app.adservices.topics; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import java.util.Objects; 24 25 /** 26 * Represents a Topic. 27 * 28 * @hide 29 */ 30 public final class TopicParcel implements Parcelable { 31 private final long mTaxonomyVersion; 32 private final long mModelVersion; 33 private final int mTopicId; 34 TopicParcel(@onNull Builder builder)35 private TopicParcel(@NonNull Builder builder) { 36 mTaxonomyVersion = builder.mTaxonomyVersion; 37 mModelVersion = builder.mModelVersion; 38 mTopicId = builder.mTopicId; 39 } 40 TopicParcel(@onNull Parcel in)41 private TopicParcel(@NonNull Parcel in) { 42 mTaxonomyVersion = in.readLong(); 43 mModelVersion = in.readLong(); 44 mTopicId = in.readInt(); 45 } 46 47 @NonNull 48 public static final Creator<TopicParcel> CREATOR = 49 new Parcelable.Creator<>() { 50 @Override 51 public TopicParcel createFromParcel(Parcel in) { 52 return new TopicParcel(in); 53 } 54 55 @Override 56 public TopicParcel[] newArray(int size) { 57 return new TopicParcel[size]; 58 } 59 }; 60 61 @Override describeContents()62 public int describeContents() { 63 return 0; 64 } 65 66 @Override writeToParcel(@onNull Parcel out, int flags)67 public void writeToParcel(@NonNull Parcel out, int flags) { 68 out.writeLong(mTaxonomyVersion); 69 out.writeLong(mModelVersion); 70 out.writeInt(mTopicId); 71 } 72 73 /** Get the taxonomy version. */ getTaxonomyVersion()74 public long getTaxonomyVersion() { 75 return mTaxonomyVersion; 76 } 77 78 /** Get the model Version. */ getModelVersion()79 public long getModelVersion() { 80 return mModelVersion; 81 } 82 83 /** Get the Topic ID. */ getTopicId()84 public int getTopicId() { 85 return mTopicId; 86 } 87 88 /** Builder for {@link TopicParcel} objects. */ 89 public static final class Builder { 90 private long mTaxonomyVersion; 91 private long mModelVersion; 92 private int mTopicId; 93 Builder()94 public Builder() {} 95 96 /** Set the taxonomy version */ 97 @NonNull setTaxonomyVersion(long taxonomyVersion)98 public TopicParcel.Builder setTaxonomyVersion(long taxonomyVersion) { 99 mTaxonomyVersion = taxonomyVersion; 100 return this; 101 } 102 103 /** Set the model version */ 104 @NonNull setModelVersion(long modelVersion)105 public TopicParcel.Builder setModelVersion(long modelVersion) { 106 mModelVersion = modelVersion; 107 return this; 108 } 109 110 /** Set the topic id */ 111 @NonNull setTopicId(int topicId)112 public TopicParcel.Builder setTopicId(int topicId) { 113 mTopicId = topicId; 114 return this; 115 } 116 117 /** Builds a {@link TopicParcel} instance. */ 118 @NonNull build()119 public TopicParcel build() { 120 return new TopicParcel(this); 121 } 122 } 123 124 @Override hashCode()125 public int hashCode() { 126 return Objects.hash(getTaxonomyVersion(), getModelVersion(), getTopicId()); 127 } 128 129 @Override equals(Object obj)130 public boolean equals(Object obj) { 131 if (this == obj) { 132 return true; 133 } 134 if (!(obj instanceof TopicParcel)) { 135 return false; 136 } 137 138 TopicParcel topicParcel = (TopicParcel) obj; 139 return this.getTaxonomyVersion() == topicParcel.getTaxonomyVersion() 140 && this.getModelVersion() == topicParcel.getModelVersion() 141 && this.getTopicId() == topicParcel.getTopicId(); 142 } 143 } 144