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 package android.app.appsearch.safeparcel;
17 
18 import android.os.Parcel;
19 import android.os.Parcelable;
20 
21 public class TestParcelable implements Parcelable {
22     public static final Creator<TestParcelable> CREATOR =
23             new Creator<TestParcelable>() {
24 
25                 @Override
26                 public TestParcelable createFromParcel(Parcel parcel) {
27                     return new TestParcelable(parcel);
28                 }
29 
30                 @Override
31                 public TestParcelable[] newArray(int size) {
32                     return new TestParcelable[size];
33                 }
34             };
35 
36     private int mInt;
37     private float mFloat;
38     private String mString;
39 
TestParcelable(int intValue, float floatValue, String stringValue)40     public TestParcelable(int intValue, float floatValue, String stringValue) {
41         mInt = intValue;
42         mFloat = floatValue;
43         mString = stringValue;
44     }
45 
TestParcelable(Parcel parcel)46     public TestParcelable(Parcel parcel) {
47         readFromParcel(parcel);
48     }
49 
50     @Override
describeContents()51     public int describeContents() {
52         return 0;
53     }
54 
55     @Override
writeToParcel(Parcel parcel, int flags)56     public void writeToParcel(Parcel parcel, int flags) {
57         parcel.writeInt(mInt);
58         parcel.writeFloat(mFloat);
59         parcel.writeString(mString);
60     }
61 
readFromParcel(Parcel parcel)62     private void readFromParcel(Parcel parcel) {
63         mInt = parcel.readInt();
64         mFloat = parcel.readFloat();
65         mString = parcel.readString();
66     }
67 
68     // TODO(b/37774152): implement hashCode() (go/equals-hashcode-lsc)
69     @SuppressWarnings("EqualsHashCode")
70     @Override
equals(Object object)71     public boolean equals(Object object) {
72         if (object instanceof TestParcelable) {
73             TestParcelable parcelable = (TestParcelable) object;
74             return parcelable.mInt == mInt
75                     && parcelable.mFloat == mFloat
76                     && parcelable.mString.equals(mString);
77         }
78         return false;
79     }
80 }
81