• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.federatedcompute.common;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Parcelable;
22 
23 import com.android.internal.util.Preconditions;
24 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
25 import com.android.ondevicepersonalization.internal.util.DataClass;
26 
27 /**
28  * A container for information regarding an example store access, including the collection name, the
29  * selection criteria and the number of examples which has been used.
30  *
31  * @hide
32  */
33 @DataClass(genBuilder = true, genEqualsHashCode = true)
34 public class ExampleConsumption implements Parcelable {
35     @NonNull private final String mCollectionName;
36 
37     @NonNull private final byte[] mSelectionCriteria;
38 
39     private final int mExampleCount;
40 
41     @Nullable private final byte[] mResumptionToken;
42 
43     // Code below generated by codegen v1.0.23.
44     //
45     // DO NOT MODIFY!
46     // CHECKSTYLE:OFF Generated code
47     //
48     // To regenerate run:
49     // $ codegen
50     // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/federatedcompute/common/ExampleConsumption.java
51     //
52     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
53     //   Settings > Editor > Code Style > Formatter Control
54     // @formatter:off
55 
56     @DataClass.Generated.Member
ExampleConsumption( @onNull String collectionName, @NonNull byte[] selectionCriteria, int exampleCount, @Nullable byte[] resumptionToken)57     /* package-private */ ExampleConsumption(
58             @NonNull String collectionName,
59             @NonNull byte[] selectionCriteria,
60             int exampleCount,
61             @Nullable byte[] resumptionToken) {
62         this.mCollectionName = collectionName;
63         AnnotationValidations.validate(NonNull.class, null, mCollectionName);
64         this.mSelectionCriteria = selectionCriteria;
65         AnnotationValidations.validate(NonNull.class, null, mSelectionCriteria);
66         this.mExampleCount = exampleCount;
67         this.mResumptionToken = resumptionToken;
68 
69         // onConstructed(); // You can define this method to get a callback
70     }
71 
72     @DataClass.Generated.Member
getCollectionName()73     public @NonNull String getCollectionName() {
74         return mCollectionName;
75     }
76 
77     @DataClass.Generated.Member
getSelectionCriteria()78     public @NonNull byte[] getSelectionCriteria() {
79         return mSelectionCriteria;
80     }
81 
82     @DataClass.Generated.Member
getExampleCount()83     public int getExampleCount() {
84         return mExampleCount;
85     }
86 
87     @DataClass.Generated.Member
getResumptionToken()88     public @Nullable byte[] getResumptionToken() {
89         return mResumptionToken;
90     }
91 
92     @Override
93     @DataClass.Generated.Member
equals(@ullable Object o)94     public boolean equals(@Nullable Object o) {
95         // You can override field equality logic by defining either of the methods like:
96         // boolean fieldNameEquals(ExampleConsumption other) { ... }
97         // boolean fieldNameEquals(FieldType otherValue) { ... }
98 
99         if (this == o) return true;
100         if (o == null || getClass() != o.getClass()) return false;
101         @SuppressWarnings("unchecked")
102         ExampleConsumption that = (ExampleConsumption) o;
103         //noinspection PointlessBooleanExpression
104         return true
105                 && java.util.Objects.equals(mCollectionName, that.mCollectionName)
106                 && java.util.Arrays.equals(mSelectionCriteria, that.mSelectionCriteria)
107                 && mExampleCount == that.mExampleCount
108                 && java.util.Arrays.equals(mResumptionToken, that.mResumptionToken);
109     }
110 
111     @Override
112     @DataClass.Generated.Member
hashCode()113     public int hashCode() {
114         // You can override field hashCode logic by defining methods like:
115         // int fieldNameHashCode() { ... }
116 
117         int _hash = 1;
118         _hash = 31 * _hash + java.util.Objects.hashCode(mCollectionName);
119         _hash = 31 * _hash + java.util.Arrays.hashCode(mSelectionCriteria);
120         _hash = 31 * _hash + mExampleCount;
121         _hash = 31 * _hash + java.util.Arrays.hashCode(mResumptionToken);
122         return _hash;
123     }
124 
125     @Override
126     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)127     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
128         // You can override field parcelling by defining methods like:
129         // void parcelFieldName(Parcel dest, int flags) { ... }
130 
131         byte flg = 0;
132         if (mResumptionToken != null) flg |= 0x8;
133         dest.writeByte(flg);
134         dest.writeString(mCollectionName);
135         dest.writeByteArray(mSelectionCriteria);
136         dest.writeInt(mExampleCount);
137         if (mResumptionToken != null) dest.writeByteArray(mResumptionToken);
138     }
139 
140     @Override
141     @DataClass.Generated.Member
describeContents()142     public int describeContents() {
143         return 0;
144     }
145 
146     /** @hide */
147     @SuppressWarnings({"unchecked", "RedundantCast"})
148     @DataClass.Generated.Member
ExampleConsumption(@onNull android.os.Parcel in)149     protected ExampleConsumption(@NonNull android.os.Parcel in) {
150         // You can override field unparcelling by defining methods like:
151         // static FieldType unparcelFieldName(Parcel in) { ... }
152 
153         byte flg = in.readByte();
154         String collectionName = in.readString();
155         byte[] selectionCriteria = in.createByteArray();
156         int exampleCount = in.readInt();
157         byte[] resumptionToken = (flg & 0x8) == 0 ? null : in.createByteArray();
158 
159         this.mCollectionName = collectionName;
160         AnnotationValidations.validate(NonNull.class, null, mCollectionName);
161         this.mSelectionCriteria = selectionCriteria;
162         AnnotationValidations.validate(NonNull.class, null, mSelectionCriteria);
163         this.mExampleCount = exampleCount;
164         this.mResumptionToken = resumptionToken;
165 
166         // onConstructed(); // You can define this method to get a callback
167     }
168 
169     @DataClass.Generated.Member
170     public static final @NonNull Parcelable.Creator<ExampleConsumption> CREATOR =
171             new Parcelable.Creator<ExampleConsumption>() {
172                 @Override
173                 public ExampleConsumption[] newArray(int size) {
174                     return new ExampleConsumption[size];
175                 }
176 
177                 @Override
178                 public ExampleConsumption createFromParcel(@NonNull android.os.Parcel in) {
179                     return new ExampleConsumption(in);
180                 }
181             };
182 
183     /** A builder for {@link ExampleConsumption} */
184     @SuppressWarnings("WeakerAccess")
185     @DataClass.Generated.Member
186     public static class Builder {
187 
188         private @NonNull String mCollectionName;
189         private @NonNull byte[] mSelectionCriteria;
190         private int mExampleCount;
191         private @Nullable byte[] mResumptionToken;
192 
193         private long mBuilderFieldsSet = 0L;
194 
Builder()195         public Builder() {}
196 
197         @DataClass.Generated.Member
setCollectionName(@onNull String value)198         public @NonNull Builder setCollectionName(@NonNull String value) {
199             checkNotUsed();
200             Preconditions.checkStringNotEmpty(value);
201             mBuilderFieldsSet |= 0x1;
202             mCollectionName = value;
203             return this;
204         }
205 
206         @DataClass.Generated.Member
setSelectionCriteria(@onNull byte... value)207         public @NonNull Builder setSelectionCriteria(@NonNull byte... value) {
208             checkNotUsed();
209             mBuilderFieldsSet |= 0x2;
210             mSelectionCriteria = value;
211             return this;
212         }
213 
214         @DataClass.Generated.Member
setExampleCount(int value)215         public @NonNull Builder setExampleCount(int value) {
216             checkNotUsed();
217             mBuilderFieldsSet |= 0x4;
218             mExampleCount = value;
219             return this;
220         }
221 
222         @DataClass.Generated.Member
setResumptionToken(@onNull byte... value)223         public @NonNull Builder setResumptionToken(@NonNull byte... value) {
224             checkNotUsed();
225             mBuilderFieldsSet |= 0x8;
226             mResumptionToken = value;
227             return this;
228         }
229 
230         /** Builds the instance. This builder should not be touched after calling this! */
build()231         public @NonNull ExampleConsumption build() {
232             checkNotUsed();
233             mBuilderFieldsSet |= 0x10; // Mark builder used
234 
235             ExampleConsumption o =
236                     new ExampleConsumption(
237                             mCollectionName, mSelectionCriteria, mExampleCount, mResumptionToken);
238             return o;
239         }
240 
checkNotUsed()241         private void checkNotUsed() {
242             if ((mBuilderFieldsSet & 0x10) != 0) {
243                 throw new IllegalStateException(
244                         "This Builder should not be reused. Use a new Builder instance instead");
245             }
246         }
247     }
248 
249     // @formatter:on
250     // End of generated code
251 
252 }
253