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 
20 @SafeParcelable.Class(creator = "TestSafeParcelableCreator")
21 public class TestSafeParcelable extends AbstractSafeParcelable {
22 
23     public static final Creator<TestSafeParcelable> CREATOR = new TestSafeParcelableCreator();
24 
25     @Constructor
TestSafeParcelable( @aramid = 1000) int versionCode, @Param(id = 1) String stringVal1, @Param(id = 2) String stringVal2)26     public TestSafeParcelable(
27             @Param(id = 1000) int versionCode,
28             @Param(id = 1) String stringVal1,
29             @Param(id = 2) String stringVal2) {
30         mVersionCode = versionCode;
31         stringField1 = stringVal1;
32         stringField2 = stringVal2;
33     }
34 
TestSafeParcelable(String stringVal1, String stringVal2)35     public TestSafeParcelable(String stringVal1, String stringVal2) {
36         this(1, stringVal1, stringVal2);
37     }
38 
getVersionCode()39     public int getVersionCode() {
40         return mVersionCode;
41     }
42 
43     @Override
writeToParcel(Parcel out, int flags)44     public void writeToParcel(Parcel out, int flags) {
45         TestSafeParcelableCreator.writeToParcel(this, out, flags);
46     }
47 
48     @VersionField(id = 1000, getter = "getVersionCode")
49     private final int mVersionCode;
50 
51     @Field(id = 1)
52     public final String stringField1;
53 
54     @Field(id = 2)
55     public final String stringField2;
56 
57     // TODO(b/37774152): implement hashCode() (go/equals-hashcode-lsc)
58     @SuppressWarnings("EqualsHashCode")
59     @Override
equals(Object object)60     public boolean equals(Object object) {
61         if (object instanceof TestSafeParcelable) {
62             TestSafeParcelable parcelable = (TestSafeParcelable) object;
63             return stringField1.equals(parcelable.stringField1)
64                     && stringField2.equals(parcelable.stringField2);
65         }
66         return false;
67     }
68 }
69