1 /*
2  * Copyright (C) 2024 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.adservices.ondevicepersonalization;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.os.Parcelable;
22 
23 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
24 import com.android.ondevicepersonalization.internal.util.DataClass;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /** @hide */
30 @DataClass(genAidl = false, genBuilder = true, genEqualsHashCode = true)
31 public final class ModelId implements Parcelable {
32 
33     public static final int TABLE_ID_REMOTE_DATA = 1;
34     public static final int TABLE_ID_LOCAL_DATA = 2;
35 
36     @IntDef(
37             prefix = "TABLE_ID_",
38             value = {TABLE_ID_REMOTE_DATA, TABLE_ID_LOCAL_DATA})
39     @Retention(RetentionPolicy.SOURCE)
40     public @interface TABLE {}
41 
42     // The table name of the table where pre-trained model is stored. Only supports TFLite model
43     // now.
44     private @TABLE int mTableId;
45 
46     // The key of the table where the corresponding value stores a pre-trained model. Only supports
47     // TFLite model now.
48     @NonNull private String mKey;
49 
50     // Code below generated by codegen v1.0.23.
51     //
52     // DO NOT MODIFY!
53     // CHECKSTYLE:OFF Generated code
54     //
55     // To regenerate run:
56     // $ codegen
57     // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/ModelId.java
58     //
59     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
60     //   Settings > Editor > Code Style > Formatter Control
61     // @formatter:off
62 
63     @IntDef(
64             prefix = "TABLE_ID_",
65             value = {TABLE_ID_REMOTE_DATA, TABLE_ID_LOCAL_DATA})
66     @Retention(RetentionPolicy.SOURCE)
67     @DataClass.Generated.Member
68     public @interface TableId {}
69 
70     @DataClass.Generated.Member
tableIdToString(@ableId int value)71     public static String tableIdToString(@TableId int value) {
72         switch (value) {
73             case TABLE_ID_REMOTE_DATA:
74                 return "TABLE_ID_REMOTE_DATA";
75             case TABLE_ID_LOCAL_DATA:
76                 return "TABLE_ID_LOCAL_DATA";
77             default:
78                 return Integer.toHexString(value);
79         }
80     }
81 
82     @DataClass.Generated.Member
ModelId(@ABLE int tableId, @NonNull String key)83     /* package-private */ ModelId(@TABLE int tableId, @NonNull String key) {
84         this.mTableId = tableId;
85         AnnotationValidations.validate(TABLE.class, null, mTableId);
86         this.mKey = key;
87         AnnotationValidations.validate(NonNull.class, null, mKey);
88 
89         // onConstructed(); // You can define this method to get a callback
90     }
91 
92     @DataClass.Generated.Member
getTableId()93     public @TABLE int getTableId() {
94         return mTableId;
95     }
96 
97     @DataClass.Generated.Member
getKey()98     public @NonNull String getKey() {
99         return mKey;
100     }
101 
102     @Override
103     @DataClass.Generated.Member
equals(@ndroid.annotation.Nullable Object o)104     public boolean equals(@android.annotation.Nullable Object o) {
105         // You can override field equality logic by defining either of the methods like:
106         // boolean fieldNameEquals(ModelId other) { ... }
107         // boolean fieldNameEquals(FieldType otherValue) { ... }
108 
109         if (this == o) return true;
110         if (o == null || getClass() != o.getClass()) return false;
111         @SuppressWarnings("unchecked")
112         ModelId that = (ModelId) o;
113         //noinspection PointlessBooleanExpression
114         return true && mTableId == that.mTableId && java.util.Objects.equals(mKey, that.mKey);
115     }
116 
117     @Override
118     @DataClass.Generated.Member
hashCode()119     public int hashCode() {
120         // You can override field hashCode logic by defining methods like:
121         // int fieldNameHashCode() { ... }
122 
123         int _hash = 1;
124         _hash = 31 * _hash + mTableId;
125         _hash = 31 * _hash + java.util.Objects.hashCode(mKey);
126         return _hash;
127     }
128 
129     @Override
130     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)131     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
132         // You can override field parcelling by defining methods like:
133         // void parcelFieldName(Parcel dest, int flags) { ... }
134 
135         dest.writeInt(mTableId);
136         dest.writeString(mKey);
137     }
138 
139     @Override
140     @DataClass.Generated.Member
describeContents()141     public int describeContents() {
142         return 0;
143     }
144 
145     /** @hide */
146     @SuppressWarnings({"unchecked", "RedundantCast"})
147     @DataClass.Generated.Member
ModelId(@onNull android.os.Parcel in)148     /* package-private */ ModelId(@NonNull android.os.Parcel in) {
149         // You can override field unparcelling by defining methods like:
150         // static FieldType unparcelFieldName(Parcel in) { ... }
151 
152         int tableId = in.readInt();
153         String key = in.readString();
154 
155         this.mTableId = tableId;
156         AnnotationValidations.validate(TABLE.class, null, mTableId);
157         this.mKey = key;
158         AnnotationValidations.validate(NonNull.class, null, mKey);
159 
160         // onConstructed(); // You can define this method to get a callback
161     }
162 
163     @DataClass.Generated.Member
164     public static final @NonNull Parcelable.Creator<ModelId> CREATOR =
165             new Parcelable.Creator<ModelId>() {
166                 @Override
167                 public ModelId[] newArray(int size) {
168                     return new ModelId[size];
169                 }
170 
171                 @Override
172                 public ModelId createFromParcel(@NonNull android.os.Parcel in) {
173                     return new ModelId(in);
174                 }
175             };
176 
177     /** A builder for {@link ModelId} */
178     @SuppressWarnings("WeakerAccess")
179     @DataClass.Generated.Member
180     public static final class Builder {
181 
182         private @TABLE int mTableId;
183         private @NonNull String mKey;
184 
185         private long mBuilderFieldsSet = 0L;
186 
Builder()187         public Builder() {}
188 
189         @DataClass.Generated.Member
setTableId(@ABLE int value)190         public @NonNull Builder setTableId(@TABLE int value) {
191             checkNotUsed();
192             mBuilderFieldsSet |= 0x1;
193             mTableId = value;
194             return this;
195         }
196 
197         @DataClass.Generated.Member
setKey(@onNull String value)198         public @NonNull Builder setKey(@NonNull String value) {
199             checkNotUsed();
200             mBuilderFieldsSet |= 0x2;
201             mKey = value;
202             return this;
203         }
204 
205         /** Builds the instance. This builder should not be touched after calling this! */
build()206         public @NonNull ModelId build() {
207             checkNotUsed();
208             mBuilderFieldsSet |= 0x4; // Mark builder used
209 
210             ModelId o = new ModelId(mTableId, mKey);
211             return o;
212         }
213 
checkNotUsed()214         private void checkNotUsed() {
215             if ((mBuilderFieldsSet & 0x4) != 0) {
216                 throw new IllegalStateException(
217                         "This Builder should not be reused. Use a new Builder instance instead");
218             }
219         }
220     }
221 
222     // @formatter:on
223     // End of generated code
224 
225 }
226