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