• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 com.android.codegentest;
17 
18 import android.annotation.FloatRange;
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.Size;
23 import android.annotation.StringDef;
24 import android.annotation.StringRes;
25 import android.annotation.UserIdInt;
26 import android.companion.ICompanionDeviceManager;
27 import android.content.pm.PackageManager;
28 import android.net.LinkAddress;
29 import android.os.Binder;
30 import android.os.IBinder;
31 import android.os.Parcel;
32 import android.os.Parcelable;
33 import android.view.accessibility.AccessibilityNodeInfo;
34 
35 import com.android.internal.util.AnnotationValidations;
36 import com.android.internal.util.DataClass;
37 import com.android.internal.util.DataClass.Each;
38 import com.android.internal.util.Parcelling;
39 import com.android.internal.util.Preconditions;
40 
41 import java.io.PrintWriter;
42 import java.util.ArrayList;
43 import java.util.Date;
44 import java.util.List;
45 import java.util.Objects;
46 import java.util.regex.Pattern;
47 
48 /**
49  * Sample data class, showing off various code generation features.
50  *
51  * See javadoc on non-generated code for the explanation of the various features.
52  *
53  * See {@link SampleDataClassTest} for various invariants the generated code is expected to hold.
54  */
55 @DataClass(
56 //        genParcelable = true, // implied by `implements Parcelable`
57 //        genAidl = true,       // implied by `implements Parcelable`
58 //        genGetters = true,    // on by default
59 //        genConstDefs = true,  // implied by presence of constants with common prefix
60         genBuilder = true,      // on by default if optional fields present, but suppressed by
61                                 // genConstructor
62         genConstructor = true,  // on by default but normally suppressed by genBuilder
63         genEqualsHashCode = true,
64         genToString = true,
65         genForEachField = true,
66         genSetters = true
67 )
68 public final class SampleDataClass implements Parcelable {
69 
70     /**
71      * For any group of {@link int} or {@link String} constants like these, a corresponding
72      * {@link IntDef}/{@link StringDef} will get generated, with name based on common prefix
73      * by default.
74      *
75      * When {@link #SampleDataClass constructing} an instance, fields annotated with these
76      * annotations get automatically validated, with only provided constants being a valid value.
77      *
78      * @see StateName, the generated {@link StringDef}
79      * @see #mStateName annotated with {@link StateName}
80      */
81     public static final String STATE_NAME_UNDEFINED = "?";
82     public static final String STATE_NAME_ON = "on";
83     public static final String STATE_NAME_OFF = "off";
84 
85     /**
86      * Additionally, for any generated {@link IntDef} a corresponding static
87      * *ToString method will be also generated, and used in {@link #toString()}.
88      *
89      * @see #stateToString(int)
90      * @see #toString()
91      * @see State
92      */
93     public static final int STATE_ON = 1;
94     public static final int STATE_OFF = 0;
95     public static final int STATE_UNDEFINED
96             = PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
97 
98     /**
99      * {@link IntDef}s with values specified in hex("0x...") are considered to be
100      * {@link IntDef#flag flags}, while ones specified with regular int literals are considered
101      * not to be flags.
102      *
103      * This affects their string representation, e.g. see the difference in
104      * {@link #requestFlagsToString} vs {@link #stateToString}.
105      *
106      * This also affects the validation logic when {@link #SampleDataClass constructing}
107      * an instance, with any flag combination("|") being valid.
108      *
109      * You can customize the name of the generated {@link IntDef}/{@link StringDef} annotation
110      * by annotating each constant with the desired name before running the generation.
111      *
112      * Here the annotation is named {@link RequestFlags} instead of the default {@code Flags}.
113      */
114     public static final @RequestFlags int FLAG_MANUAL_REQUEST = 0x1;
115     public static final @RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST = 0x2;
116     public static final @RequestFlags int FLAG_AUGMENTED_REQUEST = 0x80000000;
117 
118 
119     /**
120      * Any property javadoc should go onto the field, and will be copied where appropriate,
121      * including getters, constructor parameters, builder setters, etc.
122      *
123      * <p>
124      * This allows to avoid the burden of maintaining copies of the same documentation
125      * pieces in multiple places for each field.
126      */
127     private int mNum;
128     /**
129      * Various javadoc features should work as expected when copied, e.g {@code code},
130      * {@link #mName links}, <a href="https://google.com">html links</a>, etc.
131      *
132      * @see #mNum2 ..and so should blocks at the bottom, e.g. {@code @see} blocks.
133      */
134     private int mNum2;
135     /**
136      * {@code @hide} javadoc annotation is also propagated, which can be used to adjust the
137      * desired public API surface.
138      *
139      * @see #getNum4() is hidden
140      * @see Builder#setNum4(int) also hidden
141      * @hide
142      */
143     private int mNum4;
144 
145     /**
146      * {@link Nullable} or {@link NonNull} annotation is required on all non-primitive fields.
147      */
148     private @Nullable String mName;
149     /**
150      * Fields with default value expressions ("mFoo = ...") are optional, and are automatically
151      * initialized to the provided default expression, unless explicitly set.
152      *
153      * When using a {@link Builder} optional fields are passed via a {@link Builder#setName2 setter}
154      * while mandatory fields are passed via {@link Builder#Builder constructor}.
155      */
156     private @NonNull String mName2 = "Bob";
157     /**
158      * Alternatively, when default value computation is expensive,
159      * {@link #defaultName4 defaultFieldName()} can be defined to compute the default value.
160      */
161     private @NonNull String mName4;
defaultName4()162     private static String defaultName4() {
163         // Expensive computation
164         return "Bob4";
165     }
166 
167     /**
168      * For parcelling, any field type supported by {@link Parcel} is supported out of the box.
169      * E.g. {@link Parcelable} subclasses, {@link String}, {@link int}, {@link boolean}, etc.
170      */
171     private @Nullable AccessibilityNodeInfo mOtherParcelable = null;
172     /**
173      * Additionally, support for parcelling other types can be added by implementing a
174      * {@link Parcelling}, and referencing it in the {@link DataClass.ParcelWith} field annotation.
175      *
176      * @see MyDateParcelling an example {@link Parcelling} implementation
177      */
178     @DataClass.ParcelWith(MyDateParcelling.class)
179     private @NonNull Date mDate = new Date(42 * 42);
180     /**
181      * If a {@link Parcelling} is fairly common, consider putting it in {@link Parcelling.BuiltIn}
182      * to encourage its reuse.
183      */
184     @DataClass.ParcelWith(Parcelling.BuiltIn.ForPattern.class)
185     private @NonNull Pattern mPattern = Pattern.compile("");
186 
187     /**
188      * For lists, when using a {@link Builder}, other than a regular
189      * {@link Builder#setLinkAddresses2(List) setter}, and additional
190      * {@link Builder#addLinkAddresses2(LinkAddress) add} method is generated for convenience.
191      */
192     private @NonNull List<LinkAddress> mLinkAddresses2 = new ArrayList<>();
193     /**
194      * For aesthetics, you may want to consider providing a singular version of the plural field
195      * name, which would be used for the {@link #mLinkAddresses2 above mentioned} "add" method.
196      *
197      * @see Builder#addLinkAddress(LinkAddress)
198      */
199     @DataClass.PluralOf("linkAddress")
200     private @NonNull ArrayList<LinkAddress> mLinkAddresses = new ArrayList<>();
201     /**
202      * For array fields, when using a {@link Builder}, vararg argument format is used for
203      * convenience.
204      *
205      * @see Builder#setLinkAddresses4(LinkAddress...)
206      */
207     private @Nullable LinkAddress[] mLinkAddresses4 = null;
208 
209     /**
210      * {@link IntDef}/{@link StringDef}-annotated fields propagate the annotation to
211      * getter/constructor/setter/builder parameters, making for a nicer api.
212      *
213      * @see #getStateName
214      * @see Builder#setStateName
215      */
216     private @StateName @NonNull String mStateName = STATE_NAME_UNDEFINED;
217     /**
218      * Fields annotated with {@link IntDef} annotations also get a proper {@link #toString()} value.
219      */
220     private @RequestFlags int mFlags;
221     /**
222      * Above is true for both {@link IntDef#flag flags} and enum-like {@link IntDef}s
223      */
224     private @State int mState = STATE_UNDEFINED;
225 
226 
227     /**
228      * Making a field public will suppress getter generation in favor of accessing it directly.
229      */
230     public @NonNull CharSequence charSeq = "";
231     /**
232      * Final fields suppress generating a setter (when setters are requested).
233      */
234     private final @Nullable LinkAddress[] mLinkAddresses5;
235     /**
236      * Transient fields are completely ignored and can be used for caching.
237      */
238     private transient LinkAddress[] mLinkAddresses6;
239     /**
240      * When using transient fields for caching it's often also a good idea to initialize them
241      * lazily.
242      *
243      * You can declare a special method like {@link #lazyInitTmpStorage()}, to let the
244      * {@link #getTmpStorage getter} lazily-initialize the value on demand.
245      */
246     transient int[] mTmpStorage;
lazyInitTmpStorage()247     private int[] lazyInitTmpStorage() {
248         return new int[100];
249     }
250 
251     /**
252      * Fields with certain annotations are automatically validated in constructor
253      *
254      * You can see overloads in {@link AnnotationValidations} for a list of currently
255      * supported ones.
256      *
257      * You can also extend support to your custom annotations by creating another corresponding
258      * overloads like
259      * {@link AnnotationValidations#validate(Class, UserIdInt, int)}.
260      *
261      * @see #SampleDataClass
262      */
263     private @StringRes int mStringRes = 0;
264     /**
265      * Validation annotations may also have parameters.
266      *
267      * Parameter values will be supplied to validation method as name-value pairs.
268      *
269      * @see AnnotationValidations#validate(Class, Size, int, String, int, String, int)
270      */
271     private @android.annotation.IntRange(from = 0, to = 6) int mDayOfWeek = 3;
272     /**
273      * Unnamed validation annotation parameter gets supplied to the validating method named as
274      * "value".
275      *
276      * Validation annotations following {@link Each} annotation, will be applied for each
277      * array/collection element instead.
278      *
279      * @see AnnotationValidations#validate(Class, Size, int, String, int)
280      */
281     @Size(2)
282     @NonNull
283     @Each @FloatRange(from = 0f)
284     private float[] mCoords = new float[] {0f, 0f};
285 
286 
287     /**
288      * Binder types are also supported
289      */
290     private @NonNull IBinder mToken = new Binder();
291     /**
292      * AIDL interface types are also supported
293      */
294     private @Nullable ICompanionDeviceManager mIPCInterface = null;
295 
296 
297     /**
298      * Manually declaring any method that would otherwise be generated suppresses its generation,
299      * allowing for fine-grained overrides of the generated behavior.
300      */
getLinkAddresses4()301     public LinkAddress[] getLinkAddresses4() {
302         //Suppress autogen
303         return null;
304     }
305 
306     /**
307      * Additionally, some methods like {@link #equals}, {@link #hashCode}, {@link #toString},
308      * {@link #writeToParcel}, {@link Parcelable.Creator#createFromParcel} allow you to define
309      * special methods to override their behavior on a per-field basis.
310      *
311      * See the generateted methods' descriptions for the detailed instructions of what the method
312      * signatures for such methods are expected to be.
313      *
314      * Here we use this to "fix" {@link Pattern} not implementing equals/hashCode.
315      *
316      * @see #equals
317      * @see #hashCode
318      */
patternEquals(Pattern other)319     private boolean patternEquals(Pattern other) {
320         return Objects.equals(mPattern.pattern(), other.pattern());
321     }
patternHashCode()322     private int patternHashCode() {
323         return Objects.hashCode(mPattern.pattern());
324     }
325 
326     /**
327      * Similarly, {@link #onConstructed()}, if defined, gets called at the end of constructing an
328      * instance.
329      *
330      * At this point all fields should be in place, so this is the right place to put any custom
331      * validation logic.
332      */
onConstructed()333     private void onConstructed() {
334         Preconditions.checkState(mNum2 == mNum4);
335     }
336 
337     /**
338      * {@link DataClass#genForEachField} can be used to generate a generic {@link #forEachField}
339      * utility, which can be used for various use-cases not covered out of the box.
340      * Callback passed to {@link #forEachField} will be called once per each property with its name
341      * and value.
342      *
343      * Here for example it's used to implement a typical dump method.
344      *
345      * Note that there are 2 {@link #forEachField} versions provided, one that treats each field
346      * value as an {@link Object}, thus boxing primitives if any, and one that additionally takes
347      * specialized callbacks for particular primitive field types used in given class.
348      *
349      * Some primitives like {@link Boolean}s and {@link Integer}s within [-128, 127] don't allocate
350      * when boxed, so it's up to you to decide which one to use for a given use-case.
351      */
dump(PrintWriter pw)352     public void dump(PrintWriter pw) {
353         forEachField((self, name, value) -> {
354             pw.append("  ").append(name).append(": ").append(String.valueOf(value)).append('\n');
355         });
356     }
357 
358 
359 
360     // Code below generated by codegen v1.0.23.
361     //
362     // DO NOT MODIFY!
363     // CHECKSTYLE:OFF Generated code
364     //
365     // To regenerate run:
366     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/tests/Codegen/src/com/android/codegentest/SampleDataClass.java
367     //
368     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
369     //   Settings > Editor > Code Style > Formatter Control
370     //@formatter:off
371 
372 
373     @IntDef(prefix = "STATE_", value = {
374         STATE_ON,
375         STATE_OFF,
376         STATE_UNDEFINED
377     })
378     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
379     @DataClass.Generated.Member
380     public @interface State {}
381 
382     @DataClass.Generated.Member
stateToString(@tate int value)383     public static String stateToString(@State int value) {
384         switch (value) {
385             case STATE_ON:
386                     return "STATE_ON";
387             case STATE_OFF:
388                     return "STATE_OFF";
389             case STATE_UNDEFINED:
390                     return "STATE_UNDEFINED";
391             default: return Integer.toHexString(value);
392         }
393     }
394 
395     @IntDef(flag = true, prefix = "FLAG_", value = {
396         FLAG_MANUAL_REQUEST,
397         FLAG_COMPATIBILITY_MODE_REQUEST,
398         FLAG_AUGMENTED_REQUEST
399     })
400     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
401     @DataClass.Generated.Member
402     public @interface RequestFlags {}
403 
404     @DataClass.Generated.Member
requestFlagsToString(@equestFlags int value)405     public static String requestFlagsToString(@RequestFlags int value) {
406         return com.android.internal.util.BitUtils.flagsToString(
407                 value, SampleDataClass::singleRequestFlagsToString);
408     }
409 
410     @DataClass.Generated.Member
singleRequestFlagsToString(@equestFlags int value)411     static String singleRequestFlagsToString(@RequestFlags int value) {
412         switch (value) {
413             case FLAG_MANUAL_REQUEST:
414                     return "FLAG_MANUAL_REQUEST";
415             case FLAG_COMPATIBILITY_MODE_REQUEST:
416                     return "FLAG_COMPATIBILITY_MODE_REQUEST";
417             case FLAG_AUGMENTED_REQUEST:
418                     return "FLAG_AUGMENTED_REQUEST";
419             default: return Integer.toHexString(value);
420         }
421     }
422 
423     @StringDef(prefix = "STATE_NAME_", value = {
424         STATE_NAME_UNDEFINED,
425         STATE_NAME_ON,
426         STATE_NAME_OFF
427     })
428     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
429     @DataClass.Generated.Member
430     public @interface StateName {}
431 
432     /**
433      * Creates a new SampleDataClass.
434      *
435      * @param num
436      *   Any property javadoc should go onto the field, and will be copied where appropriate,
437      *   including getters, constructor parameters, builder setters, etc.
438      *
439      *   <p>
440      *   This allows to avoid the burden of maintaining copies of the same documentation
441      *   pieces in multiple places for each field.
442      * @param num2
443      *   Various javadoc features should work as expected when copied, e.g {@code code},
444      *   {@link #mName links}, <a href="https://google.com">html links</a>, etc.
445      * @param num4
446      *   {@code @hide} javadoc annotation is also propagated, which can be used to adjust the
447      *   desired public API surface.
448      * @param name
449      *   {@link Nullable} or {@link NonNull} annotation is required on all non-primitive fields.
450      * @param name2
451      *   Fields with default value expressions ("mFoo = ...") are optional, and are automatically
452      *   initialized to the provided default expression, unless explicitly set.
453      *
454      *   When using a {@link Builder} optional fields are passed via a {@link Builder#setName2 setter}
455      *   while mandatory fields are passed via {@link Builder#Builder constructor}.
456      * @param name4
457      *   Alternatively, when default value computation is expensive,
458      *   {@link #defaultName4 defaultFieldName()} can be defined to compute the default value.
459      * @param otherParcelable
460      *   For parcelling, any field type supported by {@link Parcel} is supported out of the box.
461      *   E.g. {@link Parcelable} subclasses, {@link String}, {@link int}, {@link boolean}, etc.
462      * @param date
463      *   Additionally, support for parcelling other types can be added by implementing a
464      *   {@link Parcelling}, and referencing it in the {@link DataClass.ParcelWith} field annotation.
465      * @param pattern
466      *   If a {@link Parcelling} is fairly common, consider putting it in {@link Parcelling.BuiltIn}
467      *   to encourage its reuse.
468      * @param linkAddresses2
469      *   For lists, when using a {@link Builder}, other than a regular
470      *   {@link Builder#setLinkAddresses2(List) setter}, and additional
471      *   {@link Builder#addLinkAddresses2(LinkAddress) add} method is generated for convenience.
472      * @param linkAddresses
473      *   For aesthetics, you may want to consider providing a singular version of the plural field
474      *   name, which would be used for the {@link #mLinkAddresses2 above mentioned} "add" method.
475      * @param linkAddresses4
476      *   For array fields, when using a {@link Builder}, vararg argument format is used for
477      *   convenience.
478      * @param stateName
479      *   {@link IntDef}/{@link StringDef}-annotated fields propagate the annotation to
480      *   getter/constructor/setter/builder parameters, making for a nicer api.
481      * @param flags
482      *   Fields annotated with {@link IntDef} annotations also get a proper {@link #toString()} value.
483      * @param state
484      *   Above is true for both {@link IntDef#flag flags} and enum-like {@link IntDef}s
485      * @param charSeq
486      *   Making a field public will suppress getter generation in favor of accessing it directly.
487      * @param linkAddresses5
488      *   Final fields suppress generating a setter (when setters are requested).
489      * @param stringRes
490      *   Fields with certain annotations are automatically validated in constructor
491      *
492      *   You can see overloads in {@link AnnotationValidations} for a list of currently
493      *   supported ones.
494      *
495      *   You can also extend support to your custom annotations by creating another corresponding
496      *   overloads like
497      *   {@link AnnotationValidations#validate(Class, UserIdInt, int)}.
498      * @param dayOfWeek
499      *   Validation annotations may also have parameters.
500      *
501      *   Parameter values will be supplied to validation method as name-value pairs.
502      * @param coords
503      *   Unnamed validation annotation parameter gets supplied to the validating method named as
504      *   "value".
505      *
506      *   Validation annotations following {@link Each} annotation, will be applied for each
507      *   array/collection element instead.
508      * @param token
509      *   Binder types are also supported
510      * @param iPCInterface
511      *   AIDL interface types are also supported
512      */
513     @DataClass.Generated.Member
SampleDataClass( int num, int num2, int num4, @Nullable String name, @NonNull String name2, @NonNull String name4, @Nullable AccessibilityNodeInfo otherParcelable, @NonNull Date date, @NonNull Pattern pattern, @NonNull List<LinkAddress> linkAddresses2, @NonNull ArrayList<LinkAddress> linkAddresses, @Nullable LinkAddress[] linkAddresses4, @StateName @NonNull String stateName, @RequestFlags int flags, @State int state, @NonNull CharSequence charSeq, @Nullable LinkAddress[] linkAddresses5, @StringRes int stringRes, @android.annotation.IntRange(from = 0, to = 6) int dayOfWeek, @Size(2) @NonNull @FloatRange(from = 0f) float[] coords, @NonNull IBinder token, @Nullable ICompanionDeviceManager iPCInterface)514     public SampleDataClass(
515             int num,
516             int num2,
517             int num4,
518             @Nullable String name,
519             @NonNull String name2,
520             @NonNull String name4,
521             @Nullable AccessibilityNodeInfo otherParcelable,
522             @NonNull Date date,
523             @NonNull Pattern pattern,
524             @NonNull List<LinkAddress> linkAddresses2,
525             @NonNull ArrayList<LinkAddress> linkAddresses,
526             @Nullable LinkAddress[] linkAddresses4,
527             @StateName @NonNull String stateName,
528             @RequestFlags int flags,
529             @State int state,
530             @NonNull CharSequence charSeq,
531             @Nullable LinkAddress[] linkAddresses5,
532             @StringRes int stringRes,
533             @android.annotation.IntRange(from = 0, to = 6) int dayOfWeek,
534             @Size(2) @NonNull @FloatRange(from = 0f) float[] coords,
535             @NonNull IBinder token,
536             @Nullable ICompanionDeviceManager iPCInterface) {
537         this.mNum = num;
538         this.mNum2 = num2;
539         this.mNum4 = num4;
540         this.mName = name;
541         this.mName2 = name2;
542         AnnotationValidations.validate(
543                 NonNull.class, null, mName2);
544         this.mName4 = name4;
545         AnnotationValidations.validate(
546                 NonNull.class, null, mName4);
547         this.mOtherParcelable = otherParcelable;
548         this.mDate = date;
549         AnnotationValidations.validate(
550                 NonNull.class, null, mDate);
551         this.mPattern = pattern;
552         AnnotationValidations.validate(
553                 NonNull.class, null, mPattern);
554         this.mLinkAddresses2 = linkAddresses2;
555         AnnotationValidations.validate(
556                 NonNull.class, null, mLinkAddresses2);
557         this.mLinkAddresses = linkAddresses;
558         AnnotationValidations.validate(
559                 NonNull.class, null, mLinkAddresses);
560         this.mLinkAddresses4 = linkAddresses4;
561         this.mStateName = stateName;
562 
563         if (!(Objects.equals(mStateName, STATE_NAME_UNDEFINED))
564                 && !(Objects.equals(mStateName, STATE_NAME_ON))
565                 && !(Objects.equals(mStateName, STATE_NAME_OFF))) {
566             throw new java.lang.IllegalArgumentException(
567                     "stateName was " + mStateName + " but must be one of: "
568                             + "STATE_NAME_UNDEFINED(" + STATE_NAME_UNDEFINED + "), "
569                             + "STATE_NAME_ON(" + STATE_NAME_ON + "), "
570                             + "STATE_NAME_OFF(" + STATE_NAME_OFF + ")");
571         }
572 
573         AnnotationValidations.validate(
574                 NonNull.class, null, mStateName);
575         this.mFlags = flags;
576 
577         Preconditions.checkFlagsArgument(
578                 mFlags,
579                 FLAG_MANUAL_REQUEST
580                         | FLAG_COMPATIBILITY_MODE_REQUEST
581                         | FLAG_AUGMENTED_REQUEST);
582         this.mState = state;
583 
584         if (!(mState == STATE_ON)
585                 && !(mState == STATE_OFF)
586                 && !(mState == STATE_UNDEFINED)) {
587             throw new java.lang.IllegalArgumentException(
588                     "state was " + mState + " but must be one of: "
589                             + "STATE_ON(" + STATE_ON + "), "
590                             + "STATE_OFF(" + STATE_OFF + "), "
591                             + "STATE_UNDEFINED(" + STATE_UNDEFINED + ")");
592         }
593 
594         this.charSeq = charSeq;
595         AnnotationValidations.validate(
596                 NonNull.class, null, charSeq);
597         this.mLinkAddresses5 = linkAddresses5;
598         this.mStringRes = stringRes;
599         AnnotationValidations.validate(
600                 StringRes.class, null, mStringRes);
601         this.mDayOfWeek = dayOfWeek;
602         AnnotationValidations.validate(
603                 android.annotation.IntRange.class, null, mDayOfWeek,
604                 "from", 0,
605                 "to", 6);
606         this.mCoords = coords;
607         AnnotationValidations.validate(
608                 Size.class, null, mCoords.length,
609                 "value", 2);
610         AnnotationValidations.validate(
611                 NonNull.class, null, mCoords);
612         int coordsSize = mCoords.length;
613         for (int i = 0; i < coordsSize; i++) {
614             AnnotationValidations.validate(
615                     FloatRange.class, null, mCoords[i],
616                     "from", 0f);
617         }
618 
619         this.mToken = token;
620         AnnotationValidations.validate(
621                 NonNull.class, null, mToken);
622         this.mIPCInterface = iPCInterface;
623 
624         onConstructed();
625     }
626 
627     /**
628      * Any property javadoc should go onto the field, and will be copied where appropriate,
629      * including getters, constructor parameters, builder setters, etc.
630      *
631      * <p>
632      * This allows to avoid the burden of maintaining copies of the same documentation
633      * pieces in multiple places for each field.
634      */
635     @DataClass.Generated.Member
getNum()636     public int getNum() {
637         return mNum;
638     }
639 
640     /**
641      * Various javadoc features should work as expected when copied, e.g {@code code},
642      * {@link #mName links}, <a href="https://google.com">html links</a>, etc.
643      *
644      * @see #mNum2 ..and so should blocks at the bottom, e.g. {@code @see} blocks.
645      */
646     @DataClass.Generated.Member
getNum2()647     public int getNum2() {
648         return mNum2;
649     }
650 
651     /**
652      * {@code @hide} javadoc annotation is also propagated, which can be used to adjust the
653      * desired public API surface.
654      *
655      * @see #getNum4() is hidden
656      * @see Builder#setNum4(int) also hidden
657      * @hide
658      */
659     @DataClass.Generated.Member
getNum4()660     public int getNum4() {
661         return mNum4;
662     }
663 
664     /**
665      * {@link Nullable} or {@link NonNull} annotation is required on all non-primitive fields.
666      */
667     @DataClass.Generated.Member
getName()668     public @Nullable String getName() {
669         return mName;
670     }
671 
672     /**
673      * Fields with default value expressions ("mFoo = ...") are optional, and are automatically
674      * initialized to the provided default expression, unless explicitly set.
675      *
676      * When using a {@link Builder} optional fields are passed via a {@link Builder#setName2 setter}
677      * while mandatory fields are passed via {@link Builder#Builder constructor}.
678      */
679     @DataClass.Generated.Member
getName2()680     public @NonNull String getName2() {
681         return mName2;
682     }
683 
684     /**
685      * Alternatively, when default value computation is expensive,
686      * {@link #defaultName4 defaultFieldName()} can be defined to compute the default value.
687      */
688     @DataClass.Generated.Member
getName4()689     public @NonNull String getName4() {
690         return mName4;
691     }
692 
693     /**
694      * For parcelling, any field type supported by {@link Parcel} is supported out of the box.
695      * E.g. {@link Parcelable} subclasses, {@link String}, {@link int}, {@link boolean}, etc.
696      */
697     @DataClass.Generated.Member
getOtherParcelable()698     public @Nullable AccessibilityNodeInfo getOtherParcelable() {
699         return mOtherParcelable;
700     }
701 
702     /**
703      * Additionally, support for parcelling other types can be added by implementing a
704      * {@link Parcelling}, and referencing it in the {@link DataClass.ParcelWith} field annotation.
705      *
706      * @see MyDateParcelling an example {@link Parcelling} implementation
707      */
708     @DataClass.Generated.Member
getDate()709     public @NonNull Date getDate() {
710         return mDate;
711     }
712 
713     /**
714      * If a {@link Parcelling} is fairly common, consider putting it in {@link Parcelling.BuiltIn}
715      * to encourage its reuse.
716      */
717     @DataClass.Generated.Member
getPattern()718     public @NonNull Pattern getPattern() {
719         return mPattern;
720     }
721 
722     /**
723      * For lists, when using a {@link Builder}, other than a regular
724      * {@link Builder#setLinkAddresses2(List) setter}, and additional
725      * {@link Builder#addLinkAddresses2(LinkAddress) add} method is generated for convenience.
726      */
727     @DataClass.Generated.Member
getLinkAddresses2()728     public @NonNull List<LinkAddress> getLinkAddresses2() {
729         return mLinkAddresses2;
730     }
731 
732     /**
733      * For aesthetics, you may want to consider providing a singular version of the plural field
734      * name, which would be used for the {@link #mLinkAddresses2 above mentioned} "add" method.
735      *
736      * @see Builder#addLinkAddress(LinkAddress)
737      */
738     @DataClass.Generated.Member
getLinkAddresses()739     public @NonNull ArrayList<LinkAddress> getLinkAddresses() {
740         return mLinkAddresses;
741     }
742 
743     /**
744      * {@link IntDef}/{@link StringDef}-annotated fields propagate the annotation to
745      * getter/constructor/setter/builder parameters, making for a nicer api.
746      *
747      * @see #getStateName
748      * @see Builder#setStateName
749      */
750     @DataClass.Generated.Member
getStateName()751     public @StateName @NonNull String getStateName() {
752         return mStateName;
753     }
754 
755     /**
756      * Fields annotated with {@link IntDef} annotations also get a proper {@link #toString()} value.
757      */
758     @DataClass.Generated.Member
getFlags()759     public @RequestFlags int getFlags() {
760         return mFlags;
761     }
762 
763     /**
764      * Above is true for both {@link IntDef#flag flags} and enum-like {@link IntDef}s
765      */
766     @DataClass.Generated.Member
getState()767     public @State int getState() {
768         return mState;
769     }
770 
771     /**
772      * Final fields suppress generating a setter (when setters are requested).
773      */
774     @DataClass.Generated.Member
getLinkAddresses5()775     public @Nullable LinkAddress[] getLinkAddresses5() {
776         return mLinkAddresses5;
777     }
778 
779     /**
780      * Fields with certain annotations are automatically validated in constructor
781      *
782      * You can see overloads in {@link AnnotationValidations} for a list of currently
783      * supported ones.
784      *
785      * You can also extend support to your custom annotations by creating another corresponding
786      * overloads like
787      * {@link AnnotationValidations#validate(Class, UserIdInt, int)}.
788      *
789      * @see #SampleDataClass
790      */
791     @DataClass.Generated.Member
getStringRes()792     public @StringRes int getStringRes() {
793         return mStringRes;
794     }
795 
796     /**
797      * Validation annotations may also have parameters.
798      *
799      * Parameter values will be supplied to validation method as name-value pairs.
800      *
801      * @see AnnotationValidations#validate(Class, Size, int, String, int, String, int)
802      */
803     @DataClass.Generated.Member
getDayOfWeek()804     public @android.annotation.IntRange(from = 0, to = 6) int getDayOfWeek() {
805         return mDayOfWeek;
806     }
807 
808     /**
809      * Unnamed validation annotation parameter gets supplied to the validating method named as
810      * "value".
811      *
812      * Validation annotations following {@link Each} annotation, will be applied for each
813      * array/collection element instead.
814      *
815      * @see AnnotationValidations#validate(Class, Size, int, String, int)
816      */
817     @DataClass.Generated.Member
getCoords()818     public @Size(2) @NonNull @FloatRange(from = 0f) float[] getCoords() {
819         return mCoords;
820     }
821 
822     /**
823      * Binder types are also supported
824      */
825     @DataClass.Generated.Member
getToken()826     public @NonNull IBinder getToken() {
827         return mToken;
828     }
829 
830     /**
831      * AIDL interface types are also supported
832      */
833     @DataClass.Generated.Member
getIPCInterface()834     public @Nullable ICompanionDeviceManager getIPCInterface() {
835         return mIPCInterface;
836     }
837 
838     /**
839      * When using transient fields for caching it's often also a good idea to initialize them
840      * lazily.
841      *
842      * You can declare a special method like {@link #lazyInitTmpStorage()}, to let the
843      * {@link #getTmpStorage getter} lazily-initialize the value on demand.
844      */
845     @DataClass.Generated.Member
getTmpStorage()846     public int[] getTmpStorage() {
847         int[] tmpStorage = mTmpStorage;
848         if (tmpStorage == null) {
849             // You can mark field as volatile for thread-safe double-check init
850             tmpStorage = mTmpStorage = lazyInitTmpStorage();
851         }
852         return tmpStorage;
853     }
854 
855     /**
856      * Any property javadoc should go onto the field, and will be copied where appropriate,
857      * including getters, constructor parameters, builder setters, etc.
858      *
859      * <p>
860      * This allows to avoid the burden of maintaining copies of the same documentation
861      * pieces in multiple places for each field.
862      */
863     @DataClass.Generated.Member
setNum( int value)864     public @NonNull SampleDataClass setNum( int value) {
865         mNum = value;
866         return this;
867     }
868 
869     /**
870      * Various javadoc features should work as expected when copied, e.g {@code code},
871      * {@link #mName links}, <a href="https://google.com">html links</a>, etc.
872      *
873      * @see #mNum2 ..and so should blocks at the bottom, e.g. {@code @see} blocks.
874      */
875     @DataClass.Generated.Member
setNum2( int value)876     public @NonNull SampleDataClass setNum2( int value) {
877         mNum2 = value;
878         return this;
879     }
880 
881     /**
882      * {@code @hide} javadoc annotation is also propagated, which can be used to adjust the
883      * desired public API surface.
884      *
885      * @see #getNum4() is hidden
886      * @see Builder#setNum4(int) also hidden
887      * @hide
888      */
889     @DataClass.Generated.Member
setNum4( int value)890     public @NonNull SampleDataClass setNum4( int value) {
891         mNum4 = value;
892         return this;
893     }
894 
895     /**
896      * {@link Nullable} or {@link NonNull} annotation is required on all non-primitive fields.
897      */
898     @DataClass.Generated.Member
setName(@onNull String value)899     public @NonNull SampleDataClass setName(@NonNull String value) {
900         mName = value;
901         return this;
902     }
903 
904     /**
905      * Fields with default value expressions ("mFoo = ...") are optional, and are automatically
906      * initialized to the provided default expression, unless explicitly set.
907      *
908      * When using a {@link Builder} optional fields are passed via a {@link Builder#setName2 setter}
909      * while mandatory fields are passed via {@link Builder#Builder constructor}.
910      */
911     @DataClass.Generated.Member
setName2(@onNull String value)912     public @NonNull SampleDataClass setName2(@NonNull String value) {
913         mName2 = value;
914         AnnotationValidations.validate(
915                 NonNull.class, null, mName2);
916         return this;
917     }
918 
919     /**
920      * Alternatively, when default value computation is expensive,
921      * {@link #defaultName4 defaultFieldName()} can be defined to compute the default value.
922      */
923     @DataClass.Generated.Member
setName4(@onNull String value)924     public @NonNull SampleDataClass setName4(@NonNull String value) {
925         mName4 = value;
926         AnnotationValidations.validate(
927                 NonNull.class, null, mName4);
928         return this;
929     }
930 
931     /**
932      * For parcelling, any field type supported by {@link Parcel} is supported out of the box.
933      * E.g. {@link Parcelable} subclasses, {@link String}, {@link int}, {@link boolean}, etc.
934      */
935     @DataClass.Generated.Member
setOtherParcelable(@onNull AccessibilityNodeInfo value)936     public @NonNull SampleDataClass setOtherParcelable(@NonNull AccessibilityNodeInfo value) {
937         mOtherParcelable = value;
938         return this;
939     }
940 
941     /**
942      * Additionally, support for parcelling other types can be added by implementing a
943      * {@link Parcelling}, and referencing it in the {@link DataClass.ParcelWith} field annotation.
944      *
945      * @see MyDateParcelling an example {@link Parcelling} implementation
946      */
947     @DataClass.Generated.Member
setDate(@onNull Date value)948     public @NonNull SampleDataClass setDate(@NonNull Date value) {
949         mDate = value;
950         AnnotationValidations.validate(
951                 NonNull.class, null, mDate);
952         return this;
953     }
954 
955     /**
956      * If a {@link Parcelling} is fairly common, consider putting it in {@link Parcelling.BuiltIn}
957      * to encourage its reuse.
958      */
959     @DataClass.Generated.Member
setPattern(@onNull Pattern value)960     public @NonNull SampleDataClass setPattern(@NonNull Pattern value) {
961         mPattern = value;
962         AnnotationValidations.validate(
963                 NonNull.class, null, mPattern);
964         return this;
965     }
966 
967     /**
968      * For lists, when using a {@link Builder}, other than a regular
969      * {@link Builder#setLinkAddresses2(List) setter}, and additional
970      * {@link Builder#addLinkAddresses2(LinkAddress) add} method is generated for convenience.
971      */
972     @DataClass.Generated.Member
setLinkAddresses2(@onNull List<LinkAddress> value)973     public @NonNull SampleDataClass setLinkAddresses2(@NonNull List<LinkAddress> value) {
974         mLinkAddresses2 = value;
975         AnnotationValidations.validate(
976                 NonNull.class, null, mLinkAddresses2);
977         return this;
978     }
979 
980     /**
981      * For aesthetics, you may want to consider providing a singular version of the plural field
982      * name, which would be used for the {@link #mLinkAddresses2 above mentioned} "add" method.
983      *
984      * @see Builder#addLinkAddress(LinkAddress)
985      */
986     @DataClass.Generated.Member
setLinkAddresses(@onNull ArrayList<LinkAddress> value)987     public @NonNull SampleDataClass setLinkAddresses(@NonNull ArrayList<LinkAddress> value) {
988         mLinkAddresses = value;
989         AnnotationValidations.validate(
990                 NonNull.class, null, mLinkAddresses);
991         return this;
992     }
993 
994     /**
995      * For array fields, when using a {@link Builder}, vararg argument format is used for
996      * convenience.
997      *
998      * @see Builder#setLinkAddresses4(LinkAddress...)
999      */
1000     @DataClass.Generated.Member
setLinkAddresses4(@onNull LinkAddress... value)1001     public @NonNull SampleDataClass setLinkAddresses4(@NonNull LinkAddress... value) {
1002         mLinkAddresses4 = value;
1003         return this;
1004     }
1005 
1006     /**
1007      * {@link IntDef}/{@link StringDef}-annotated fields propagate the annotation to
1008      * getter/constructor/setter/builder parameters, making for a nicer api.
1009      *
1010      * @see #getStateName
1011      * @see Builder#setStateName
1012      */
1013     @DataClass.Generated.Member
setStateName(@tateName @onNull String value)1014     public @NonNull SampleDataClass setStateName(@StateName @NonNull String value) {
1015         mStateName = value;
1016 
1017         if (!(Objects.equals(mStateName, STATE_NAME_UNDEFINED))
1018                 && !(Objects.equals(mStateName, STATE_NAME_ON))
1019                 && !(Objects.equals(mStateName, STATE_NAME_OFF))) {
1020             throw new java.lang.IllegalArgumentException(
1021                     "stateName was " + mStateName + " but must be one of: "
1022                             + "STATE_NAME_UNDEFINED(" + STATE_NAME_UNDEFINED + "), "
1023                             + "STATE_NAME_ON(" + STATE_NAME_ON + "), "
1024                             + "STATE_NAME_OFF(" + STATE_NAME_OFF + ")");
1025         }
1026 
1027         AnnotationValidations.validate(
1028                 NonNull.class, null, mStateName);
1029         return this;
1030     }
1031 
1032     /**
1033      * Fields annotated with {@link IntDef} annotations also get a proper {@link #toString()} value.
1034      */
1035     @DataClass.Generated.Member
setFlags(@equestFlags int value)1036     public @NonNull SampleDataClass setFlags(@RequestFlags int value) {
1037         mFlags = value;
1038 
1039         Preconditions.checkFlagsArgument(
1040                 mFlags,
1041                 FLAG_MANUAL_REQUEST
1042                         | FLAG_COMPATIBILITY_MODE_REQUEST
1043                         | FLAG_AUGMENTED_REQUEST);
1044         return this;
1045     }
1046 
1047     /**
1048      * Above is true for both {@link IntDef#flag flags} and enum-like {@link IntDef}s
1049      */
1050     @DataClass.Generated.Member
setState(@tate int value)1051     public @NonNull SampleDataClass setState(@State int value) {
1052         mState = value;
1053 
1054         if (!(mState == STATE_ON)
1055                 && !(mState == STATE_OFF)
1056                 && !(mState == STATE_UNDEFINED)) {
1057             throw new java.lang.IllegalArgumentException(
1058                     "state was " + mState + " but must be one of: "
1059                             + "STATE_ON(" + STATE_ON + "), "
1060                             + "STATE_OFF(" + STATE_OFF + "), "
1061                             + "STATE_UNDEFINED(" + STATE_UNDEFINED + ")");
1062         }
1063 
1064         return this;
1065     }
1066 
1067     /**
1068      * Fields with certain annotations are automatically validated in constructor
1069      *
1070      * You can see overloads in {@link AnnotationValidations} for a list of currently
1071      * supported ones.
1072      *
1073      * You can also extend support to your custom annotations by creating another corresponding
1074      * overloads like
1075      * {@link AnnotationValidations#validate(Class, UserIdInt, int)}.
1076      *
1077      * @see #SampleDataClass
1078      */
1079     @DataClass.Generated.Member
setStringRes(@tringRes int value)1080     public @NonNull SampleDataClass setStringRes(@StringRes int value) {
1081         mStringRes = value;
1082         AnnotationValidations.validate(
1083                 StringRes.class, null, mStringRes);
1084         return this;
1085     }
1086 
1087     /**
1088      * Validation annotations may also have parameters.
1089      *
1090      * Parameter values will be supplied to validation method as name-value pairs.
1091      *
1092      * @see AnnotationValidations#validate(Class, Size, int, String, int, String, int)
1093      */
1094     @DataClass.Generated.Member
setDayOfWeek(@ndroid.annotation.IntRangefrom = 0, to = 6) int value)1095     public @NonNull SampleDataClass setDayOfWeek(@android.annotation.IntRange(from = 0, to = 6) int value) {
1096         mDayOfWeek = value;
1097         AnnotationValidations.validate(
1098                 android.annotation.IntRange.class, null, mDayOfWeek,
1099                 "from", 0,
1100                 "to", 6);
1101         return this;
1102     }
1103 
1104     /**
1105      * Unnamed validation annotation parameter gets supplied to the validating method named as
1106      * "value".
1107      *
1108      * Validation annotations following {@link Each} annotation, will be applied for each
1109      * array/collection element instead.
1110      *
1111      * @see AnnotationValidations#validate(Class, Size, int, String, int)
1112      */
1113     @DataClass.Generated.Member
setCoords(@ize2) @onNull @loatRangefrom = 0f) float... value)1114     public @NonNull SampleDataClass setCoords(@Size(2) @NonNull @FloatRange(from = 0f) float... value) {
1115         mCoords = value;
1116         AnnotationValidations.validate(
1117                 Size.class, null, mCoords.length,
1118                 "value", 2);
1119         AnnotationValidations.validate(
1120                 NonNull.class, null, mCoords);
1121         int coordsSize = mCoords.length;
1122         for (int i = 0; i < coordsSize; i++) {
1123             AnnotationValidations.validate(
1124                     FloatRange.class, null, mCoords[i],
1125                     "from", 0f);
1126         }
1127 
1128         return this;
1129     }
1130 
1131     /**
1132      * Binder types are also supported
1133      */
1134     @DataClass.Generated.Member
setToken(@onNull IBinder value)1135     public @NonNull SampleDataClass setToken(@NonNull IBinder value) {
1136         mToken = value;
1137         AnnotationValidations.validate(
1138                 NonNull.class, null, mToken);
1139         return this;
1140     }
1141 
1142     /**
1143      * AIDL interface types are also supported
1144      */
1145     @DataClass.Generated.Member
setIPCInterface(@onNull ICompanionDeviceManager value)1146     public @NonNull SampleDataClass setIPCInterface(@NonNull ICompanionDeviceManager value) {
1147         mIPCInterface = value;
1148         return this;
1149     }
1150 
1151     @Override
1152     @DataClass.Generated.Member
toString()1153     public String toString() {
1154         // You can override field toString logic by defining methods like:
1155         // String fieldNameToString() { ... }
1156 
1157         return "SampleDataClass { " +
1158                 "num = " + mNum + ", " +
1159                 "num2 = " + mNum2 + ", " +
1160                 "num4 = " + mNum4 + ", " +
1161                 "name = " + mName + ", " +
1162                 "name2 = " + mName2 + ", " +
1163                 "name4 = " + mName4 + ", " +
1164                 "otherParcelable = " + mOtherParcelable + ", " +
1165                 "date = " + mDate + ", " +
1166                 "pattern = " + mPattern + ", " +
1167                 "linkAddresses2 = " + mLinkAddresses2 + ", " +
1168                 "linkAddresses = " + mLinkAddresses + ", " +
1169                 "linkAddresses4 = " + java.util.Arrays.toString(mLinkAddresses4) + ", " +
1170                 "stateName = " + mStateName + ", " +
1171                 "flags = " + requestFlagsToString(mFlags) + ", " +
1172                 "state = " + stateToString(mState) + ", " +
1173                 "charSeq = " + charSeq + ", " +
1174                 "linkAddresses5 = " + java.util.Arrays.toString(mLinkAddresses5) + ", " +
1175                 "stringRes = " + mStringRes + ", " +
1176                 "dayOfWeek = " + mDayOfWeek + ", " +
1177                 "coords = " + java.util.Arrays.toString(mCoords) + ", " +
1178                 "token = " + mToken + ", " +
1179                 "iPCInterface = " + mIPCInterface +
1180         " }";
1181     }
1182 
1183     @Override
1184     @DataClass.Generated.Member
equals(@ullable Object o)1185     public boolean equals(@Nullable Object o) {
1186         // You can override field equality logic by defining either of the methods like:
1187         // boolean fieldNameEquals(SampleDataClass other) { ... }
1188         // boolean fieldNameEquals(FieldType otherValue) { ... }
1189 
1190         if (this == o) return true;
1191         if (o == null || getClass() != o.getClass()) return false;
1192         @SuppressWarnings("unchecked")
1193         SampleDataClass that = (SampleDataClass) o;
1194         //noinspection PointlessBooleanExpression
1195         return true
1196                 && mNum == that.mNum
1197                 && mNum2 == that.mNum2
1198                 && mNum4 == that.mNum4
1199                 && Objects.equals(mName, that.mName)
1200                 && Objects.equals(mName2, that.mName2)
1201                 && Objects.equals(mName4, that.mName4)
1202                 && Objects.equals(mOtherParcelable, that.mOtherParcelable)
1203                 && Objects.equals(mDate, that.mDate)
1204                 && patternEquals(that.mPattern)
1205                 && Objects.equals(mLinkAddresses2, that.mLinkAddresses2)
1206                 && Objects.equals(mLinkAddresses, that.mLinkAddresses)
1207                 && java.util.Arrays.equals(mLinkAddresses4, that.mLinkAddresses4)
1208                 && Objects.equals(mStateName, that.mStateName)
1209                 && mFlags == that.mFlags
1210                 && mState == that.mState
1211                 && Objects.equals(charSeq, that.charSeq)
1212                 && java.util.Arrays.equals(mLinkAddresses5, that.mLinkAddresses5)
1213                 && mStringRes == that.mStringRes
1214                 && mDayOfWeek == that.mDayOfWeek
1215                 && java.util.Arrays.equals(mCoords, that.mCoords)
1216                 && Objects.equals(mToken, that.mToken)
1217                 && Objects.equals(mIPCInterface, that.mIPCInterface);
1218     }
1219 
1220     @Override
1221     @DataClass.Generated.Member
hashCode()1222     public int hashCode() {
1223         // You can override field hashCode logic by defining methods like:
1224         // int fieldNameHashCode() { ... }
1225 
1226         int _hash = 1;
1227         _hash = 31 * _hash + mNum;
1228         _hash = 31 * _hash + mNum2;
1229         _hash = 31 * _hash + mNum4;
1230         _hash = 31 * _hash + Objects.hashCode(mName);
1231         _hash = 31 * _hash + Objects.hashCode(mName2);
1232         _hash = 31 * _hash + Objects.hashCode(mName4);
1233         _hash = 31 * _hash + Objects.hashCode(mOtherParcelable);
1234         _hash = 31 * _hash + Objects.hashCode(mDate);
1235         _hash = 31 * _hash + patternHashCode();
1236         _hash = 31 * _hash + Objects.hashCode(mLinkAddresses2);
1237         _hash = 31 * _hash + Objects.hashCode(mLinkAddresses);
1238         _hash = 31 * _hash + java.util.Arrays.hashCode(mLinkAddresses4);
1239         _hash = 31 * _hash + Objects.hashCode(mStateName);
1240         _hash = 31 * _hash + mFlags;
1241         _hash = 31 * _hash + mState;
1242         _hash = 31 * _hash + Objects.hashCode(charSeq);
1243         _hash = 31 * _hash + java.util.Arrays.hashCode(mLinkAddresses5);
1244         _hash = 31 * _hash + mStringRes;
1245         _hash = 31 * _hash + mDayOfWeek;
1246         _hash = 31 * _hash + java.util.Arrays.hashCode(mCoords);
1247         _hash = 31 * _hash + Objects.hashCode(mToken);
1248         _hash = 31 * _hash + Objects.hashCode(mIPCInterface);
1249         return _hash;
1250     }
1251 
1252     @DataClass.Generated.Member
forEachField( @onNull DataClass.PerIntFieldAction<SampleDataClass> actionInt, @NonNull DataClass.PerObjectFieldAction<SampleDataClass> actionObject)1253     void forEachField(
1254             @NonNull DataClass.PerIntFieldAction<SampleDataClass> actionInt,
1255             @NonNull DataClass.PerObjectFieldAction<SampleDataClass> actionObject) {
1256         actionInt.acceptInt(this, "num", mNum);
1257         actionInt.acceptInt(this, "num2", mNum2);
1258         actionInt.acceptInt(this, "num4", mNum4);
1259         actionObject.acceptObject(this, "name", mName);
1260         actionObject.acceptObject(this, "name2", mName2);
1261         actionObject.acceptObject(this, "name4", mName4);
1262         actionObject.acceptObject(this, "otherParcelable", mOtherParcelable);
1263         actionObject.acceptObject(this, "date", mDate);
1264         actionObject.acceptObject(this, "pattern", mPattern);
1265         actionObject.acceptObject(this, "linkAddresses2", mLinkAddresses2);
1266         actionObject.acceptObject(this, "linkAddresses", mLinkAddresses);
1267         actionObject.acceptObject(this, "linkAddresses4", mLinkAddresses4);
1268         actionObject.acceptObject(this, "stateName", mStateName);
1269         actionInt.acceptInt(this, "flags", mFlags);
1270         actionInt.acceptInt(this, "state", mState);
1271         actionObject.acceptObject(this, "charSeq", charSeq);
1272         actionObject.acceptObject(this, "linkAddresses5", mLinkAddresses5);
1273         actionInt.acceptInt(this, "stringRes", mStringRes);
1274         actionInt.acceptInt(this, "dayOfWeek", mDayOfWeek);
1275         actionObject.acceptObject(this, "coords", mCoords);
1276         actionObject.acceptObject(this, "token", mToken);
1277         actionObject.acceptObject(this, "iPCInterface", mIPCInterface);
1278     }
1279 
1280     /** @deprecated May cause boxing allocations - use with caution! */
1281     @Deprecated
1282     @DataClass.Generated.Member
forEachField(@onNull DataClass.PerObjectFieldAction<SampleDataClass> action)1283     void forEachField(@NonNull DataClass.PerObjectFieldAction<SampleDataClass> action) {
1284         action.acceptObject(this, "num", mNum);
1285         action.acceptObject(this, "num2", mNum2);
1286         action.acceptObject(this, "num4", mNum4);
1287         action.acceptObject(this, "name", mName);
1288         action.acceptObject(this, "name2", mName2);
1289         action.acceptObject(this, "name4", mName4);
1290         action.acceptObject(this, "otherParcelable", mOtherParcelable);
1291         action.acceptObject(this, "date", mDate);
1292         action.acceptObject(this, "pattern", mPattern);
1293         action.acceptObject(this, "linkAddresses2", mLinkAddresses2);
1294         action.acceptObject(this, "linkAddresses", mLinkAddresses);
1295         action.acceptObject(this, "linkAddresses4", mLinkAddresses4);
1296         action.acceptObject(this, "stateName", mStateName);
1297         action.acceptObject(this, "flags", mFlags);
1298         action.acceptObject(this, "state", mState);
1299         action.acceptObject(this, "charSeq", charSeq);
1300         action.acceptObject(this, "linkAddresses5", mLinkAddresses5);
1301         action.acceptObject(this, "stringRes", mStringRes);
1302         action.acceptObject(this, "dayOfWeek", mDayOfWeek);
1303         action.acceptObject(this, "coords", mCoords);
1304         action.acceptObject(this, "token", mToken);
1305         action.acceptObject(this, "iPCInterface", mIPCInterface);
1306     }
1307 
1308     @DataClass.Generated.Member
1309     static Parcelling<Date> sParcellingForDate =
1310             Parcelling.Cache.get(
1311                     MyDateParcelling.class);
1312     static {
1313         if (sParcellingForDate == null) {
1314             sParcellingForDate = Parcelling.Cache.put(
1315                     new MyDateParcelling());
1316         }
1317     }
1318 
1319     @DataClass.Generated.Member
1320     static Parcelling<Pattern> sParcellingForPattern =
1321             Parcelling.Cache.get(
1322                     Parcelling.BuiltIn.ForPattern.class);
1323     static {
1324         if (sParcellingForPattern == null) {
1325             sParcellingForPattern = Parcelling.Cache.put(
1326                     new Parcelling.BuiltIn.ForPattern());
1327         }
1328     }
1329 
1330     @Override
1331     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)1332     public void writeToParcel(@NonNull Parcel dest, int flags) {
1333         // You can override field parcelling by defining methods like:
1334         // void parcelFieldName(Parcel dest, int flags) { ... }
1335 
1336         long flg = 0;
1337         if (mName != null) flg |= 0x8;
1338         if (mOtherParcelable != null) flg |= 0x40;
1339         if (mLinkAddresses4 != null) flg |= 0x800;
1340         if (mLinkAddresses5 != null) flg |= 0x10000;
1341         if (mIPCInterface != null) flg |= 0x200000;
1342         dest.writeLong(flg);
1343         dest.writeInt(mNum);
1344         dest.writeInt(mNum2);
1345         dest.writeInt(mNum4);
1346         if (mName != null) dest.writeString(mName);
1347         dest.writeString(mName2);
1348         dest.writeString(mName4);
1349         if (mOtherParcelable != null) dest.writeTypedObject(mOtherParcelable, flags);
1350         sParcellingForDate.parcel(mDate, dest, flags);
1351         sParcellingForPattern.parcel(mPattern, dest, flags);
1352         dest.writeParcelableList(mLinkAddresses2, flags);
1353         dest.writeParcelableList(mLinkAddresses, flags);
1354         if (mLinkAddresses4 != null) dest.writeTypedArray(mLinkAddresses4, flags);
1355         dest.writeString(mStateName);
1356         dest.writeInt(mFlags);
1357         dest.writeInt(mState);
1358         dest.writeCharSequence(charSeq);
1359         if (mLinkAddresses5 != null) dest.writeTypedArray(mLinkAddresses5, flags);
1360         dest.writeInt(mStringRes);
1361         dest.writeInt(mDayOfWeek);
1362         dest.writeFloatArray(mCoords);
1363         dest.writeStrongBinder(mToken);
1364         if (mIPCInterface != null) dest.writeStrongInterface(mIPCInterface);
1365     }
1366 
1367     @Override
1368     @DataClass.Generated.Member
describeContents()1369     public int describeContents() { return 0; }
1370 
1371     /** @hide */
1372     @SuppressWarnings({"unchecked", "RedundantCast"})
1373     @DataClass.Generated.Member
SampleDataClass(@onNull Parcel in)1374     /* package-private */ SampleDataClass(@NonNull Parcel in) {
1375         // You can override field unparcelling by defining methods like:
1376         // static FieldType unparcelFieldName(Parcel in) { ... }
1377 
1378         long flg = in.readLong();
1379         int num = in.readInt();
1380         int num2 = in.readInt();
1381         int num4 = in.readInt();
1382         String name = (flg & 0x8) == 0 ? null : in.readString();
1383         String name2 = in.readString();
1384         String name4 = in.readString();
1385         AccessibilityNodeInfo otherParcelable = (flg & 0x40) == 0 ? null : (AccessibilityNodeInfo) in.readTypedObject(AccessibilityNodeInfo.CREATOR);
1386         Date date = sParcellingForDate.unparcel(in);
1387         Pattern pattern = sParcellingForPattern.unparcel(in);
1388         List<LinkAddress> linkAddresses2 = new ArrayList<>();
1389         in.readParcelableList(linkAddresses2, LinkAddress.class.getClassLoader());
1390         ArrayList<LinkAddress> linkAddresses = new ArrayList<>();
1391         in.readParcelableList(linkAddresses, LinkAddress.class.getClassLoader());
1392         LinkAddress[] linkAddresses4 = (flg & 0x800) == 0 ? null : (LinkAddress[]) in.createTypedArray(LinkAddress.CREATOR);
1393         String stateName = in.readString();
1394         int flags = in.readInt();
1395         int state = in.readInt();
1396         CharSequence _charSeq = (CharSequence) in.readCharSequence();
1397         LinkAddress[] linkAddresses5 = (flg & 0x10000) == 0 ? null : (LinkAddress[]) in.createTypedArray(LinkAddress.CREATOR);
1398         int stringRes = in.readInt();
1399         int dayOfWeek = in.readInt();
1400         float[] coords = in.createFloatArray();
1401         IBinder token = (IBinder) in.readStrongBinder();
1402         ICompanionDeviceManager iPCInterface = (flg & 0x200000) == 0 ? null : ICompanionDeviceManager.Stub.asInterface(in.readStrongBinder());
1403 
1404         this.mNum = num;
1405         this.mNum2 = num2;
1406         this.mNum4 = num4;
1407         this.mName = name;
1408         this.mName2 = name2;
1409         AnnotationValidations.validate(
1410                 NonNull.class, null, mName2);
1411         this.mName4 = name4;
1412         AnnotationValidations.validate(
1413                 NonNull.class, null, mName4);
1414         this.mOtherParcelable = otherParcelable;
1415         this.mDate = date;
1416         AnnotationValidations.validate(
1417                 NonNull.class, null, mDate);
1418         this.mPattern = pattern;
1419         AnnotationValidations.validate(
1420                 NonNull.class, null, mPattern);
1421         this.mLinkAddresses2 = linkAddresses2;
1422         AnnotationValidations.validate(
1423                 NonNull.class, null, mLinkAddresses2);
1424         this.mLinkAddresses = linkAddresses;
1425         AnnotationValidations.validate(
1426                 NonNull.class, null, mLinkAddresses);
1427         this.mLinkAddresses4 = linkAddresses4;
1428         this.mStateName = stateName;
1429 
1430         if (!(Objects.equals(mStateName, STATE_NAME_UNDEFINED))
1431                 && !(Objects.equals(mStateName, STATE_NAME_ON))
1432                 && !(Objects.equals(mStateName, STATE_NAME_OFF))) {
1433             throw new java.lang.IllegalArgumentException(
1434                     "stateName was " + mStateName + " but must be one of: "
1435                             + "STATE_NAME_UNDEFINED(" + STATE_NAME_UNDEFINED + "), "
1436                             + "STATE_NAME_ON(" + STATE_NAME_ON + "), "
1437                             + "STATE_NAME_OFF(" + STATE_NAME_OFF + ")");
1438         }
1439 
1440         AnnotationValidations.validate(
1441                 NonNull.class, null, mStateName);
1442         this.mFlags = flags;
1443 
1444         Preconditions.checkFlagsArgument(
1445                 mFlags,
1446                 FLAG_MANUAL_REQUEST
1447                         | FLAG_COMPATIBILITY_MODE_REQUEST
1448                         | FLAG_AUGMENTED_REQUEST);
1449         this.mState = state;
1450 
1451         if (!(mState == STATE_ON)
1452                 && !(mState == STATE_OFF)
1453                 && !(mState == STATE_UNDEFINED)) {
1454             throw new java.lang.IllegalArgumentException(
1455                     "state was " + mState + " but must be one of: "
1456                             + "STATE_ON(" + STATE_ON + "), "
1457                             + "STATE_OFF(" + STATE_OFF + "), "
1458                             + "STATE_UNDEFINED(" + STATE_UNDEFINED + ")");
1459         }
1460 
1461         this.charSeq = _charSeq;
1462         AnnotationValidations.validate(
1463                 NonNull.class, null, charSeq);
1464         this.mLinkAddresses5 = linkAddresses5;
1465         this.mStringRes = stringRes;
1466         AnnotationValidations.validate(
1467                 StringRes.class, null, mStringRes);
1468         this.mDayOfWeek = dayOfWeek;
1469         AnnotationValidations.validate(
1470                 android.annotation.IntRange.class, null, mDayOfWeek,
1471                 "from", 0,
1472                 "to", 6);
1473         this.mCoords = coords;
1474         AnnotationValidations.validate(
1475                 Size.class, null, mCoords.length,
1476                 "value", 2);
1477         AnnotationValidations.validate(
1478                 NonNull.class, null, mCoords);
1479         int coordsSize = mCoords.length;
1480         for (int i = 0; i < coordsSize; i++) {
1481             AnnotationValidations.validate(
1482                     FloatRange.class, null, mCoords[i],
1483                     "from", 0f);
1484         }
1485 
1486         this.mToken = token;
1487         AnnotationValidations.validate(
1488                 NonNull.class, null, mToken);
1489         this.mIPCInterface = iPCInterface;
1490 
1491         onConstructed();
1492     }
1493 
1494     @DataClass.Generated.Member
1495     public static final @NonNull Parcelable.Creator<SampleDataClass> CREATOR
1496             = new Parcelable.Creator<SampleDataClass>() {
1497         @Override
1498         public SampleDataClass[] newArray(int size) {
1499             return new SampleDataClass[size];
1500         }
1501 
1502         @Override
1503         public SampleDataClass createFromParcel(@NonNull Parcel in) {
1504             return new SampleDataClass(in);
1505         }
1506     };
1507 
1508     /**
1509      * A builder for {@link SampleDataClass}
1510      */
1511     @SuppressWarnings("WeakerAccess")
1512     @DataClass.Generated.Member
1513     public static final class Builder {
1514 
1515         private int mNum;
1516         private int mNum2;
1517         private int mNum4;
1518         private @Nullable String mName;
1519         private @NonNull String mName2;
1520         private @NonNull String mName4;
1521         private @Nullable AccessibilityNodeInfo mOtherParcelable;
1522         private @NonNull Date mDate;
1523         private @NonNull Pattern mPattern;
1524         private @NonNull List<LinkAddress> mLinkAddresses2;
1525         private @NonNull ArrayList<LinkAddress> mLinkAddresses;
1526         private @Nullable LinkAddress[] mLinkAddresses4;
1527         private @StateName @NonNull String mStateName;
1528         private @RequestFlags int mFlags;
1529         private @State int mState;
1530         private @NonNull CharSequence charSeq;
1531         private @Nullable LinkAddress[] mLinkAddresses5;
1532         private @StringRes int mStringRes;
1533         private @android.annotation.IntRange(from = 0, to = 6) int mDayOfWeek;
1534         private @Size(2) @NonNull @FloatRange(from = 0f) float[] mCoords;
1535         private @NonNull IBinder mToken;
1536         private @Nullable ICompanionDeviceManager mIPCInterface;
1537 
1538         private long mBuilderFieldsSet = 0L;
1539 
1540         /**
1541          * Creates a new Builder.
1542          *
1543          * @param num
1544          *   Any property javadoc should go onto the field, and will be copied where appropriate,
1545          *   including getters, constructor parameters, builder setters, etc.
1546          *
1547          *   <p>
1548          *   This allows to avoid the burden of maintaining copies of the same documentation
1549          *   pieces in multiple places for each field.
1550          * @param num2
1551          *   Various javadoc features should work as expected when copied, e.g {@code code},
1552          *   {@link #mName links}, <a href="https://google.com">html links</a>, etc.
1553          * @param num4
1554          *   {@code @hide} javadoc annotation is also propagated, which can be used to adjust the
1555          *   desired public API surface.
1556          * @param name
1557          *   {@link Nullable} or {@link NonNull} annotation is required on all non-primitive fields.
1558          * @param flags
1559          *   Fields annotated with {@link IntDef} annotations also get a proper {@link #toString()} value.
1560          * @param linkAddresses5
1561          *   Final fields suppress generating a setter (when setters are requested).
1562          */
Builder( int num, int num2, int num4, @Nullable String name, @RequestFlags int flags, @Nullable LinkAddress[] linkAddresses5)1563         public Builder(
1564                 int num,
1565                 int num2,
1566                 int num4,
1567                 @Nullable String name,
1568                 @RequestFlags int flags,
1569                 @Nullable LinkAddress[] linkAddresses5) {
1570             mNum = num;
1571             mNum2 = num2;
1572             mNum4 = num4;
1573             mName = name;
1574             mFlags = flags;
1575 
1576             Preconditions.checkFlagsArgument(
1577                     mFlags,
1578                     FLAG_MANUAL_REQUEST
1579                             | FLAG_COMPATIBILITY_MODE_REQUEST
1580                             | FLAG_AUGMENTED_REQUEST);
1581             mLinkAddresses5 = linkAddresses5;
1582         }
1583 
1584         /**
1585          * Any property javadoc should go onto the field, and will be copied where appropriate,
1586          * including getters, constructor parameters, builder setters, etc.
1587          *
1588          * <p>
1589          * This allows to avoid the burden of maintaining copies of the same documentation
1590          * pieces in multiple places for each field.
1591          */
1592         @DataClass.Generated.Member
setNum(int value)1593         public @NonNull Builder setNum(int value) {
1594             checkNotUsed();
1595             mBuilderFieldsSet |= 0x1;
1596             mNum = value;
1597             return this;
1598         }
1599 
1600         /**
1601          * Various javadoc features should work as expected when copied, e.g {@code code},
1602          * {@link #mName links}, <a href="https://google.com">html links</a>, etc.
1603          *
1604          * @see #mNum2 ..and so should blocks at the bottom, e.g. {@code @see} blocks.
1605          */
1606         @DataClass.Generated.Member
setNum2(int value)1607         public @NonNull Builder setNum2(int value) {
1608             checkNotUsed();
1609             mBuilderFieldsSet |= 0x2;
1610             mNum2 = value;
1611             return this;
1612         }
1613 
1614         /**
1615          * {@code @hide} javadoc annotation is also propagated, which can be used to adjust the
1616          * desired public API surface.
1617          *
1618          * @see #getNum4() is hidden
1619          * @see Builder#setNum4(int) also hidden
1620          * @hide
1621          */
1622         @DataClass.Generated.Member
setNum4(int value)1623         public @NonNull Builder setNum4(int value) {
1624             checkNotUsed();
1625             mBuilderFieldsSet |= 0x4;
1626             mNum4 = value;
1627             return this;
1628         }
1629 
1630         /**
1631          * {@link Nullable} or {@link NonNull} annotation is required on all non-primitive fields.
1632          */
1633         @DataClass.Generated.Member
setName(@onNull String value)1634         public @NonNull Builder setName(@NonNull String value) {
1635             checkNotUsed();
1636             mBuilderFieldsSet |= 0x8;
1637             mName = value;
1638             return this;
1639         }
1640 
1641         /**
1642          * Fields with default value expressions ("mFoo = ...") are optional, and are automatically
1643          * initialized to the provided default expression, unless explicitly set.
1644          *
1645          * When using a {@link Builder} optional fields are passed via a {@link Builder#setName2 setter}
1646          * while mandatory fields are passed via {@link Builder#Builder constructor}.
1647          */
1648         @DataClass.Generated.Member
setName2(@onNull String value)1649         public @NonNull Builder setName2(@NonNull String value) {
1650             checkNotUsed();
1651             mBuilderFieldsSet |= 0x10;
1652             mName2 = value;
1653             return this;
1654         }
1655 
1656         /**
1657          * Alternatively, when default value computation is expensive,
1658          * {@link #defaultName4 defaultFieldName()} can be defined to compute the default value.
1659          */
1660         @DataClass.Generated.Member
setName4(@onNull String value)1661         public @NonNull Builder setName4(@NonNull String value) {
1662             checkNotUsed();
1663             mBuilderFieldsSet |= 0x20;
1664             mName4 = value;
1665             return this;
1666         }
1667 
1668         /**
1669          * For parcelling, any field type supported by {@link Parcel} is supported out of the box.
1670          * E.g. {@link Parcelable} subclasses, {@link String}, {@link int}, {@link boolean}, etc.
1671          */
1672         @DataClass.Generated.Member
setOtherParcelable(@onNull AccessibilityNodeInfo value)1673         public @NonNull Builder setOtherParcelable(@NonNull AccessibilityNodeInfo value) {
1674             checkNotUsed();
1675             mBuilderFieldsSet |= 0x40;
1676             mOtherParcelable = value;
1677             return this;
1678         }
1679 
1680         /**
1681          * Additionally, support for parcelling other types can be added by implementing a
1682          * {@link Parcelling}, and referencing it in the {@link DataClass.ParcelWith} field annotation.
1683          *
1684          * @see MyDateParcelling an example {@link Parcelling} implementation
1685          */
1686         @DataClass.Generated.Member
setDate(@onNull Date value)1687         public @NonNull Builder setDate(@NonNull Date value) {
1688             checkNotUsed();
1689             mBuilderFieldsSet |= 0x80;
1690             mDate = value;
1691             return this;
1692         }
1693 
1694         /**
1695          * If a {@link Parcelling} is fairly common, consider putting it in {@link Parcelling.BuiltIn}
1696          * to encourage its reuse.
1697          */
1698         @DataClass.Generated.Member
setPattern(@onNull Pattern value)1699         public @NonNull Builder setPattern(@NonNull Pattern value) {
1700             checkNotUsed();
1701             mBuilderFieldsSet |= 0x100;
1702             mPattern = value;
1703             return this;
1704         }
1705 
1706         /**
1707          * For lists, when using a {@link Builder}, other than a regular
1708          * {@link Builder#setLinkAddresses2(List) setter}, and additional
1709          * {@link Builder#addLinkAddresses2(LinkAddress) add} method is generated for convenience.
1710          */
1711         @DataClass.Generated.Member
setLinkAddresses2(@onNull List<LinkAddress> value)1712         public @NonNull Builder setLinkAddresses2(@NonNull List<LinkAddress> value) {
1713             checkNotUsed();
1714             mBuilderFieldsSet |= 0x200;
1715             mLinkAddresses2 = value;
1716             return this;
1717         }
1718 
1719         /** @see #setLinkAddresses2 */
1720         @DataClass.Generated.Member
addLinkAddresses2(@onNull LinkAddress value)1721         public @NonNull Builder addLinkAddresses2(@NonNull LinkAddress value) {
1722             // You can refine this method's name by providing item's singular name, e.g.:
1723             // @DataClass.PluralOf("item")) mItems = ...
1724 
1725             if (mLinkAddresses2 == null) setLinkAddresses2(new ArrayList<>());
1726             mLinkAddresses2.add(value);
1727             return this;
1728         }
1729 
1730         /**
1731          * For aesthetics, you may want to consider providing a singular version of the plural field
1732          * name, which would be used for the {@link #mLinkAddresses2 above mentioned} "add" method.
1733          *
1734          * @see Builder#addLinkAddress(LinkAddress)
1735          */
1736         @DataClass.Generated.Member
setLinkAddresses(@onNull ArrayList<LinkAddress> value)1737         public @NonNull Builder setLinkAddresses(@NonNull ArrayList<LinkAddress> value) {
1738             checkNotUsed();
1739             mBuilderFieldsSet |= 0x400;
1740             mLinkAddresses = value;
1741             return this;
1742         }
1743 
1744         /** @see #setLinkAddresses */
1745         @DataClass.Generated.Member
addLinkAddress(@onNull LinkAddress value)1746         public @NonNull Builder addLinkAddress(@NonNull LinkAddress value) {
1747             if (mLinkAddresses == null) setLinkAddresses(new ArrayList<>());
1748             mLinkAddresses.add(value);
1749             return this;
1750         }
1751 
1752         /**
1753          * For array fields, when using a {@link Builder}, vararg argument format is used for
1754          * convenience.
1755          *
1756          * @see Builder#setLinkAddresses4(LinkAddress...)
1757          */
1758         @DataClass.Generated.Member
setLinkAddresses4(@onNull LinkAddress... value)1759         public @NonNull Builder setLinkAddresses4(@NonNull LinkAddress... value) {
1760             checkNotUsed();
1761             mBuilderFieldsSet |= 0x800;
1762             mLinkAddresses4 = value;
1763             return this;
1764         }
1765 
1766         /**
1767          * {@link IntDef}/{@link StringDef}-annotated fields propagate the annotation to
1768          * getter/constructor/setter/builder parameters, making for a nicer api.
1769          *
1770          * @see #getStateName
1771          * @see Builder#setStateName
1772          */
1773         @DataClass.Generated.Member
setStateName(@tateName @onNull String value)1774         public @NonNull Builder setStateName(@StateName @NonNull String value) {
1775             checkNotUsed();
1776             mBuilderFieldsSet |= 0x1000;
1777             mStateName = value;
1778             return this;
1779         }
1780 
1781         /**
1782          * Fields annotated with {@link IntDef} annotations also get a proper {@link #toString()} value.
1783          */
1784         @DataClass.Generated.Member
setFlags(@equestFlags int value)1785         public @NonNull Builder setFlags(@RequestFlags int value) {
1786             checkNotUsed();
1787             mBuilderFieldsSet |= 0x2000;
1788             mFlags = value;
1789             return this;
1790         }
1791 
1792         /**
1793          * Above is true for both {@link IntDef#flag flags} and enum-like {@link IntDef}s
1794          */
1795         @DataClass.Generated.Member
setState(@tate int value)1796         public @NonNull Builder setState(@State int value) {
1797             checkNotUsed();
1798             mBuilderFieldsSet |= 0x4000;
1799             mState = value;
1800             return this;
1801         }
1802 
1803         /**
1804          * Making a field public will suppress getter generation in favor of accessing it directly.
1805          */
1806         @DataClass.Generated.Member
setCharSeq(@onNull CharSequence value)1807         public @NonNull Builder setCharSeq(@NonNull CharSequence value) {
1808             checkNotUsed();
1809             mBuilderFieldsSet |= 0x8000;
1810             charSeq = value;
1811             return this;
1812         }
1813 
1814         /**
1815          * Final fields suppress generating a setter (when setters are requested).
1816          */
1817         @DataClass.Generated.Member
setLinkAddresses5(@onNull LinkAddress... value)1818         public @NonNull Builder setLinkAddresses5(@NonNull LinkAddress... value) {
1819             checkNotUsed();
1820             mBuilderFieldsSet |= 0x10000;
1821             mLinkAddresses5 = value;
1822             return this;
1823         }
1824 
1825         /**
1826          * Fields with certain annotations are automatically validated in constructor
1827          *
1828          * You can see overloads in {@link AnnotationValidations} for a list of currently
1829          * supported ones.
1830          *
1831          * You can also extend support to your custom annotations by creating another corresponding
1832          * overloads like
1833          * {@link AnnotationValidations#validate(Class, UserIdInt, int)}.
1834          *
1835          * @see #SampleDataClass
1836          */
1837         @DataClass.Generated.Member
setStringRes(@tringRes int value)1838         public @NonNull Builder setStringRes(@StringRes int value) {
1839             checkNotUsed();
1840             mBuilderFieldsSet |= 0x20000;
1841             mStringRes = value;
1842             return this;
1843         }
1844 
1845         /**
1846          * Validation annotations may also have parameters.
1847          *
1848          * Parameter values will be supplied to validation method as name-value pairs.
1849          *
1850          * @see AnnotationValidations#validate(Class, Size, int, String, int, String, int)
1851          */
1852         @DataClass.Generated.Member
setDayOfWeek(@ndroid.annotation.IntRangefrom = 0, to = 6) int value)1853         public @NonNull Builder setDayOfWeek(@android.annotation.IntRange(from = 0, to = 6) int value) {
1854             checkNotUsed();
1855             mBuilderFieldsSet |= 0x40000;
1856             mDayOfWeek = value;
1857             return this;
1858         }
1859 
1860         /**
1861          * Unnamed validation annotation parameter gets supplied to the validating method named as
1862          * "value".
1863          *
1864          * Validation annotations following {@link Each} annotation, will be applied for each
1865          * array/collection element instead.
1866          *
1867          * @see AnnotationValidations#validate(Class, Size, int, String, int)
1868          */
1869         @DataClass.Generated.Member
setCoords(@ize2) @onNull @loatRangefrom = 0f) float... value)1870         public @NonNull Builder setCoords(@Size(2) @NonNull @FloatRange(from = 0f) float... value) {
1871             checkNotUsed();
1872             mBuilderFieldsSet |= 0x80000;
1873             mCoords = value;
1874             return this;
1875         }
1876 
1877         /**
1878          * Binder types are also supported
1879          */
1880         @DataClass.Generated.Member
setToken(@onNull IBinder value)1881         public @NonNull Builder setToken(@NonNull IBinder value) {
1882             checkNotUsed();
1883             mBuilderFieldsSet |= 0x100000;
1884             mToken = value;
1885             return this;
1886         }
1887 
1888         /**
1889          * AIDL interface types are also supported
1890          */
1891         @DataClass.Generated.Member
setIPCInterface(@onNull ICompanionDeviceManager value)1892         public @NonNull Builder setIPCInterface(@NonNull ICompanionDeviceManager value) {
1893             checkNotUsed();
1894             mBuilderFieldsSet |= 0x200000;
1895             mIPCInterface = value;
1896             return this;
1897         }
1898 
1899         /** Builds the instance. This builder should not be touched after calling this! */
build()1900         public @NonNull SampleDataClass build() {
1901             checkNotUsed();
1902             mBuilderFieldsSet |= 0x400000; // Mark builder used
1903 
1904             if ((mBuilderFieldsSet & 0x10) == 0) {
1905                 mName2 = "Bob";
1906             }
1907             if ((mBuilderFieldsSet & 0x20) == 0) {
1908                 mName4 = defaultName4();
1909             }
1910             if ((mBuilderFieldsSet & 0x40) == 0) {
1911                 mOtherParcelable = null;
1912             }
1913             if ((mBuilderFieldsSet & 0x80) == 0) {
1914                 mDate = new Date(42 * 42);
1915             }
1916             if ((mBuilderFieldsSet & 0x100) == 0) {
1917                 mPattern = Pattern.compile("");
1918             }
1919             if ((mBuilderFieldsSet & 0x200) == 0) {
1920                 mLinkAddresses2 = new ArrayList<>();
1921             }
1922             if ((mBuilderFieldsSet & 0x400) == 0) {
1923                 mLinkAddresses = new ArrayList<>();
1924             }
1925             if ((mBuilderFieldsSet & 0x800) == 0) {
1926                 mLinkAddresses4 = null;
1927             }
1928             if ((mBuilderFieldsSet & 0x1000) == 0) {
1929                 mStateName = STATE_NAME_UNDEFINED;
1930             }
1931             if ((mBuilderFieldsSet & 0x4000) == 0) {
1932                 mState = STATE_UNDEFINED;
1933             }
1934             if ((mBuilderFieldsSet & 0x8000) == 0) {
1935                 charSeq = "";
1936             }
1937             if ((mBuilderFieldsSet & 0x20000) == 0) {
1938                 mStringRes = 0;
1939             }
1940             if ((mBuilderFieldsSet & 0x40000) == 0) {
1941                 mDayOfWeek = 3;
1942             }
1943             if ((mBuilderFieldsSet & 0x80000) == 0) {
1944                 mCoords = new float[] { 0f, 0f };
1945             }
1946             if ((mBuilderFieldsSet & 0x100000) == 0) {
1947                 mToken = new Binder();
1948             }
1949             if ((mBuilderFieldsSet & 0x200000) == 0) {
1950                 mIPCInterface = null;
1951             }
1952             SampleDataClass o = new SampleDataClass(
1953                     mNum,
1954                     mNum2,
1955                     mNum4,
1956                     mName,
1957                     mName2,
1958                     mName4,
1959                     mOtherParcelable,
1960                     mDate,
1961                     mPattern,
1962                     mLinkAddresses2,
1963                     mLinkAddresses,
1964                     mLinkAddresses4,
1965                     mStateName,
1966                     mFlags,
1967                     mState,
1968                     charSeq,
1969                     mLinkAddresses5,
1970                     mStringRes,
1971                     mDayOfWeek,
1972                     mCoords,
1973                     mToken,
1974                     mIPCInterface);
1975             return o;
1976         }
1977 
checkNotUsed()1978         private void checkNotUsed() {
1979             if ((mBuilderFieldsSet & 0x400000) != 0) {
1980                 throw new IllegalStateException(
1981                         "This Builder should not be reused. Use a new Builder instance instead");
1982             }
1983         }
1984     }
1985 
1986     @DataClass.Generated(
1987             time = 1616541539978L,
1988             codegenVersion = "1.0.23",
1989             sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/SampleDataClass.java",
1990             inputSignatures = "public static final  java.lang.String STATE_NAME_UNDEFINED\npublic static final  java.lang.String STATE_NAME_ON\npublic static final  java.lang.String STATE_NAME_OFF\npublic static final  int STATE_ON\npublic static final  int STATE_OFF\npublic static final  int STATE_UNDEFINED\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_MANUAL_REQUEST\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST\npublic static final @com.android.codegentest.SampleDataClass.RequestFlags int FLAG_AUGMENTED_REQUEST\nprivate  int mNum\nprivate  int mNum2\nprivate  int mNum4\nprivate @android.annotation.Nullable java.lang.String mName\nprivate @android.annotation.NonNull java.lang.String mName2\nprivate @android.annotation.NonNull java.lang.String mName4\nprivate @android.annotation.Nullable android.view.accessibility.AccessibilityNodeInfo mOtherParcelable\nprivate @com.android.internal.util.DataClass.ParcelWith(com.android.codegentest.MyDateParcelling.class) @android.annotation.NonNull java.util.Date mDate\nprivate @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForPattern.class) @android.annotation.NonNull java.util.regex.Pattern mPattern\nprivate @android.annotation.NonNull java.util.List<android.net.LinkAddress> mLinkAddresses2\nprivate @com.android.internal.util.DataClass.PluralOf(\"linkAddress\") @android.annotation.NonNull java.util.ArrayList<android.net.LinkAddress> mLinkAddresses\nprivate @android.annotation.Nullable android.net.LinkAddress[] mLinkAddresses4\nprivate @com.android.codegentest.SampleDataClass.StateName @android.annotation.NonNull java.lang.String mStateName\nprivate @com.android.codegentest.SampleDataClass.RequestFlags int mFlags\nprivate @com.android.codegentest.SampleDataClass.State int mState\npublic @android.annotation.NonNull java.lang.CharSequence charSeq\nprivate final @android.annotation.Nullable android.net.LinkAddress[] mLinkAddresses5\nprivate transient  android.net.LinkAddress[] mLinkAddresses6\ntransient  int[] mTmpStorage\nprivate @android.annotation.StringRes int mStringRes\nprivate @android.annotation.IntRange int mDayOfWeek\nprivate @android.annotation.Size @android.annotation.NonNull @com.android.internal.util.DataClass.Each @android.annotation.FloatRange float[] mCoords\nprivate @android.annotation.NonNull android.os.IBinder mToken\nprivate @android.annotation.Nullable android.companion.ICompanionDeviceManager mIPCInterface\nprivate static  java.lang.String defaultName4()\nprivate  int[] lazyInitTmpStorage()\npublic  android.net.LinkAddress[] getLinkAddresses4()\nprivate  boolean patternEquals(java.util.regex.Pattern)\nprivate  int patternHashCode()\nprivate  void onConstructed()\npublic  void dump(java.io.PrintWriter)\nclass SampleDataClass extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genBuilder=true, genConstructor=true, genEqualsHashCode=true, genToString=true, genForEachField=true, genSetters=true)")
1991     @Deprecated
__metadata()1992     private void __metadata() {}
1993 
1994 
1995     //@formatter:on
1996     // End of generated code
1997 
1998 }
1999