001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.marshall; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.lang.annotation.*; 022 023import org.apache.juneau.commons.*; 024 025/** 026 * Utility classes and methods for the {@link Items @Items} annotation. 027 * 028 */ 029@SuppressWarnings({ 030 "java:S100", // Builder and annotation members default_, enum_ and $ref mirror the JSON Schema keywords 031 "java:S116" // Field names match JSON Schema property names for API consistency 032}) 033public class ItemsAnnotation { 034 035 /** 036 * Prevents instantiation. 037 */ 038 private ItemsAnnotation() {} 039 040 /** 041 * Builder class. 042 * 043 * <h5 class='section'>See Also:</h5><ul> 044 * <li class='jm'>{@link MarshallingContext.Builder#annotations(Annotation...)} 045 * </ul> 046 */ 047 public static class Builder extends AnnotationObject.Builder { 048 049 private String[] description = {}; 050 private boolean emax; 051 private boolean emin; 052 private boolean exclusiveMaximum; 053 private boolean exclusiveMinimum; 054 private boolean ui; 055 private boolean uniqueItems; 056 private long maxItems = -1; 057 private long maxLength = -1; 058 private long maxi = -1; 059 private long maxl = -1; 060 private long minItems = -1; 061 private long minLength = -1; 062 private long mini = -1; 063 private long minl = -1; 064 private String $ref = ""; 065 private String cf = ""; 066 private String collectionFormat = ""; 067 private String f = ""; 068 private String format = ""; 069 private String max = ""; 070 private String maximum = ""; 071 private String min = ""; 072 private String minimum = ""; 073 private String mo = ""; 074 private String multipleOf = ""; 075 private String p = ""; 076 private String pattern = ""; 077 private String t = ""; 078 private String type = ""; 079 private String[] default_ = {}; 080 private String[] enum_ = {}; 081 private String[] df = {}; 082 private String[] e = {}; 083 private SubItems items = SubItemsAnnotation.DEFAULT; 084 085 /** 086 * Constructor. 087 */ 088 protected Builder() { 089 super(Items.class); 090 } 091 092 /** 093 * Sets the {@link Items#default_} property on this annotation. 094 * 095 * @param value The new value for this property. 096 * @return This object. 097 */ 098 public Builder default_(String...value) { 099 default_ = value; 100 return this; 101 } 102 103 /** 104 * Sets the {@link Items#enum_} property on this annotation. 105 * 106 * @param value The new value for this property. 107 * @return This object. 108 */ 109 public Builder enum_(String...value) { 110 enum_ = value; 111 return this; 112 } 113 114 /** 115 * Sets the {@link Items#$ref} property on this annotation. 116 * 117 * @param value The new value for this property. 118 * @return This object. 119 */ 120 public Builder $ref(String value) { 121 $ref = value; 122 return this; 123 } 124 125 /** 126 * Instantiates a new {@link Items @Items} object initialized with this builder. 127 * 128 * @return A new {@link Items @Items} object. 129 */ 130 public Items build() { 131 return new Object(this); 132 } 133 134 /** 135 * Sets the description property on this annotation. 136 * 137 * @param value The new value for this property. 138 * @return This object. 139 */ 140 public Builder description(String...value) { 141 description = value; 142 return this; 143 } 144 145 /** 146 * Sets the {@link Items#cf} property on this annotation. 147 * 148 * @param value The new value for this property. 149 * @return This object. 150 */ 151 public Builder cf(String value) { 152 cf = value; 153 return this; 154 } 155 156 /** 157 * Sets the {@link Items#collectionFormat} property on this annotation. 158 * 159 * @param value The new value for this property. 160 * @return This object. 161 */ 162 public Builder collectionFormat(String value) { 163 collectionFormat = value; 164 return this; 165 } 166 167 /** 168 * Sets the {@link Items#df} property on this annotation. 169 * 170 * @param value The new value for this property. 171 * @return This object. 172 */ 173 public Builder df(String...value) { 174 df = value; 175 return this; 176 } 177 178 /** 179 * Sets the {@link Items#e} property on this annotation. 180 * 181 * @param value The new value for this property. 182 * @return This object. 183 */ 184 public Builder e(String...value) { 185 e = value; 186 return this; 187 } 188 189 /** 190 * Sets the {@link Items#emax} property on this annotation. 191 * 192 * @param value The new value for this property. 193 * @return This object. 194 */ 195 public Builder emax(boolean value) { 196 emax = value; 197 return this; 198 } 199 200 /** 201 * Sets the {@link Items#emin} property on this annotation. 202 * 203 * @param value The new value for this property. 204 * @return This object. 205 */ 206 public Builder emin(boolean value) { 207 emin = value; 208 return this; 209 } 210 211 /** 212 * Sets the {@link Items#exclusiveMaximum} property on this annotation. 213 * 214 * @param value The new value for this property. 215 * @return This object. 216 */ 217 public Builder exclusiveMaximum(boolean value) { 218 exclusiveMaximum = value; 219 return this; 220 } 221 222 /** 223 * Sets the {@link Items#exclusiveMinimum} property on this annotation. 224 * 225 * @param value The new value for this property. 226 * @return This object. 227 */ 228 public Builder exclusiveMinimum(boolean value) { 229 exclusiveMinimum = value; 230 return this; 231 } 232 233 /** 234 * Sets the {@link Items#f} property on this annotation. 235 * 236 * @param value The new value for this property. 237 * @return This object. 238 */ 239 public Builder f(String value) { 240 f = value; 241 return this; 242 } 243 244 /** 245 * Sets the {@link Items#format} property on this annotation. 246 * 247 * @param value The new value for this property. 248 * @return This object. 249 */ 250 public Builder format(String value) { 251 format = value; 252 return this; 253 } 254 255 /** 256 * Sets the {@link Items#items} property on this annotation. 257 * 258 * @param value The new value for this property. 259 * @return This object. 260 */ 261 public Builder items(SubItems value) { 262 items = value; 263 return this; 264 } 265 266 /** 267 * Sets the {@link Items#max} property on this annotation. 268 * 269 * @param value The new value for this property. 270 * @return This object. 271 */ 272 public Builder max(String value) { 273 max = value; 274 return this; 275 } 276 277 /** 278 * Sets the {@link Items#maxi} property on this annotation. 279 * 280 * @param value The new value for this property. 281 * @return This object. 282 */ 283 public Builder maxi(long value) { 284 maxi = value; 285 return this; 286 } 287 288 /** 289 * Sets the {@link Items#maximum} property on this annotation. 290 * 291 * @param value The new value for this property. 292 * @return This object. 293 */ 294 public Builder maximum(String value) { 295 maximum = value; 296 return this; 297 } 298 299 /** 300 * Sets the {@link Items#maxItems} property on this annotation. 301 * 302 * @param value The new value for this property. 303 * @return This object. 304 */ 305 public Builder maxItems(long value) { 306 maxItems = value; 307 return this; 308 } 309 310 /** 311 * Sets the {@link Items#maxl} property on this annotation. 312 * 313 * @param value The new value for this property. 314 * @return This object. 315 */ 316 public Builder maxl(long value) { 317 maxl = value; 318 return this; 319 } 320 321 /** 322 * Sets the {@link Items#maxLength} property on this annotation. 323 * 324 * @param value The new value for this property. 325 * @return This object. 326 */ 327 public Builder maxLength(long value) { 328 maxLength = value; 329 return this; 330 } 331 332 /** 333 * Sets the {@link Items#min} property on this annotation. 334 * 335 * @param value The new value for this property. 336 * @return This object. 337 */ 338 public Builder min(String value) { 339 min = value; 340 return this; 341 } 342 343 /** 344 * Sets the {@link Items#mini} property on this annotation. 345 * 346 * @param value The new value for this property. 347 * @return This object. 348 */ 349 public Builder mini(long value) { 350 mini = value; 351 return this; 352 } 353 354 /** 355 * Sets the {@link Items#minimum} property on this annotation. 356 * 357 * @param value The new value for this property. 358 * @return This object. 359 */ 360 public Builder minimum(String value) { 361 minimum = value; 362 return this; 363 } 364 365 /** 366 * Sets the {@link Items#minItems} property on this annotation. 367 * 368 * @param value The new value for this property. 369 * @return This object. 370 */ 371 public Builder minItems(long value) { 372 minItems = value; 373 return this; 374 } 375 376 /** 377 * Sets the {@link Items#minl} property on this annotation. 378 * 379 * @param value The new value for this property. 380 * @return This object. 381 */ 382 public Builder minl(long value) { 383 minl = value; 384 return this; 385 } 386 387 /** 388 * Sets the {@link Items#minLength} property on this annotation. 389 * 390 * @param value The new value for this property. 391 * @return This object. 392 */ 393 public Builder minLength(long value) { 394 minLength = value; 395 return this; 396 } 397 398 /** 399 * Sets the {@link Items#mo} property on this annotation. 400 * 401 * @param value The new value for this property. 402 * @return This object. 403 */ 404 public Builder mo(String value) { 405 mo = value; 406 return this; 407 } 408 409 /** 410 * Sets the {@link Items#multipleOf} property on this annotation. 411 * 412 * @param value The new value for this property. 413 * @return This object. 414 */ 415 public Builder multipleOf(String value) { 416 multipleOf = value; 417 return this; 418 } 419 420 /** 421 * Sets the {@link Items#p} property on this annotation. 422 * 423 * @param value The new value for this property. 424 * @return This object. 425 */ 426 public Builder p(String value) { 427 p = value; 428 return this; 429 } 430 431 /** 432 * Sets the {@link Items#pattern} property on this annotation. 433 * 434 * @param value The new value for this property. 435 * @return This object. 436 */ 437 public Builder pattern(String value) { 438 pattern = value; 439 return this; 440 } 441 442 /** 443 * Sets the {@link Items#t} property on this annotation. 444 * 445 * @param value The new value for this property. 446 * @return This object. 447 */ 448 public Builder t(String value) { 449 t = value; 450 return this; 451 } 452 453 /** 454 * Sets the {@link Items#type} property on this annotation. 455 * 456 * @param value The new value for this property. 457 * @return This object. 458 */ 459 public Builder type(String value) { 460 type = value; 461 return this; 462 } 463 464 /** 465 * Sets the {@link Items#ui} property on this annotation. 466 * 467 * @param value The new value for this property. 468 * @return This object. 469 */ 470 public Builder ui(boolean value) { 471 ui = value; 472 return this; 473 } 474 475 /** 476 * Sets the {@link Items#uniqueItems} property on this annotation. 477 * 478 * @param value The new value for this property. 479 * @return This object. 480 */ 481 public Builder uniqueItems(boolean value) { 482 uniqueItems = value; 483 return this; 484 } 485 486 } 487 488 @SuppressWarnings({ 489 "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods 490 }) 491 private static class Object extends AnnotationObject implements Items { 492 493 private final String[] description; 494 private final boolean emax; 495 private final boolean emin; 496 private final boolean exclusiveMaximum; 497 private final boolean exclusiveMinimum; 498 private final boolean ui; 499 private final boolean uniqueItems; 500 private final long maxi; 501 private final long maxItems; 502 private final long maxl; 503 private final long maxLength; 504 private final long mini; 505 private final long minItems; 506 private final long minl; 507 private final long minLength; 508 private final String $ref; 509 private final String cf; 510 private final String collectionFormat; 511 private final String f; 512 private final String format; 513 private final String max; 514 private final String maximum; 515 private final String min; 516 private final String minimum; 517 private final String mo; 518 private final String multipleOf; 519 private final String p; 520 private final String pattern; 521 private final String t; 522 private final String type; 523 private final String[] default_; 524 private final String[] enum_; 525 private final String[] df; 526 private final String[] e; 527 private final SubItems items; 528 529 Object(ItemsAnnotation.Builder b) { 530 super(b); 531 description = cp(b.description); 532 $ref = b.$ref; 533 default_ = cp(b.default_); 534 enum_ = cp(b.enum_); 535 cf = b.cf; 536 collectionFormat = b.collectionFormat; 537 df = cp(b.df); 538 e = cp(b.e); 539 emax = b.emax; 540 emin = b.emin; 541 exclusiveMaximum = b.exclusiveMaximum; 542 exclusiveMinimum = b.exclusiveMinimum; 543 f = b.f; 544 format = b.format; 545 items = b.items; 546 max = b.max; 547 maxi = b.maxi; 548 maximum = b.maximum; 549 maxItems = b.maxItems; 550 maxl = b.maxl; 551 maxLength = b.maxLength; 552 min = b.min; 553 mini = b.mini; 554 minimum = b.minimum; 555 minItems = b.minItems; 556 minl = b.minl; 557 minLength = b.minLength; 558 mo = b.mo; 559 multipleOf = b.multipleOf; 560 p = b.p; 561 pattern = b.pattern; 562 t = b.t; 563 type = b.type; 564 ui = b.ui; 565 uniqueItems = b.uniqueItems; 566 } 567 568 @Override /* Overridden from Items */ 569 public String[] default_() { 570 return default_; 571 } 572 573 @Override /* Overridden from Items */ 574 public String[] enum_() { 575 return enum_; 576 } 577 578 @Override /* Overridden from Items */ 579 public String $ref() { 580 return $ref; 581 } 582 583 @Override /* Overridden from Items */ 584 public String cf() { 585 return cf; 586 } 587 588 @Override /* Overridden from Items */ 589 public String collectionFormat() { 590 return collectionFormat; 591 } 592 593 @Override /* Overridden from Items */ 594 public String[] df() { 595 return df; 596 } 597 598 @Override /* Overridden from Items */ 599 public String[] e() { 600 return e; 601 } 602 603 @Override /* Overridden from Items */ 604 public boolean emax() { 605 return emax; 606 } 607 608 @Override /* Overridden from Items */ 609 public boolean emin() { 610 return emin; 611 } 612 613 @Override /* Overridden from Items */ 614 public boolean exclusiveMaximum() { 615 return exclusiveMaximum; 616 } 617 618 @Override /* Overridden from Items */ 619 public boolean exclusiveMinimum() { 620 return exclusiveMinimum; 621 } 622 623 @Override /* Overridden from Items */ 624 public String f() { 625 return f; 626 } 627 628 @Override /* Overridden from Items */ 629 public String format() { 630 return format; 631 } 632 633 @Override /* Overridden from Items */ 634 public SubItems items() { 635 return items; 636 } 637 638 @Override /* Overridden from Items */ 639 public String max() { 640 return max; 641 } 642 643 @Override /* Overridden from Items */ 644 public long maxi() { 645 return maxi; 646 } 647 648 @Override /* Overridden from Items */ 649 public String maximum() { 650 return maximum; 651 } 652 653 @Override /* Overridden from Items */ 654 public long maxItems() { 655 return maxItems; 656 } 657 658 @Override /* Overridden from Items */ 659 public long maxl() { 660 return maxl; 661 } 662 663 @Override /* Overridden from Items */ 664 public long maxLength() { 665 return maxLength; 666 } 667 668 @Override /* Overridden from Items */ 669 public String min() { 670 return min; 671 } 672 673 @Override /* Overridden from Items */ 674 public long mini() { 675 return mini; 676 } 677 678 @Override /* Overridden from Items */ 679 public String minimum() { 680 return minimum; 681 } 682 683 @Override /* Overridden from Items */ 684 public long minItems() { 685 return minItems; 686 } 687 688 @Override /* Overridden from Items */ 689 public long minl() { 690 return minl; 691 } 692 693 @Override /* Overridden from Items */ 694 public long minLength() { 695 return minLength; 696 } 697 698 @Override /* Overridden from Items */ 699 public String mo() { 700 return mo; 701 } 702 703 @Override /* Overridden from Items */ 704 public String multipleOf() { 705 return multipleOf; 706 } 707 708 @Override /* Overridden from Items */ 709 public String p() { 710 return p; 711 } 712 713 @Override /* Overridden from Items */ 714 public String pattern() { 715 return pattern; 716 } 717 718 @Override /* Overridden from Items */ 719 public String t() { 720 return t; 721 } 722 723 @Override /* Overridden from Items */ 724 public String type() { 725 return type; 726 } 727 728 @Override /* Overridden from Items */ 729 public boolean ui() { 730 return ui; 731 } 732 733 @Override /* Overridden from Items */ 734 public boolean uniqueItems() { 735 return uniqueItems; 736 } 737 738 @Override /* Overridden from annotation */ 739 public String[] description() { 740 return description; 741 } 742 } 743 744 /** Default value */ 745 public static final Items DEFAULT = create().build(); 746 747 /** 748 * Instantiates a new builder for this class. 749 * 750 * @return A new builder object. 751 */ 752 public static Builder create() { 753 return new Builder(); 754 } 755 756 /** 757 * Returns <jk>true</jk> if the specified annotation contains all default values. 758 * 759 * @param a The annotation to check. Can be <jk>null</jk> (returns <jk>true</jk>). 760 * @return <jk>true</jk> if the specified annotation contains all default values. 761 */ 762 public static boolean empty(Items a) { 763 return a == null || DEFAULT.equals(a); 764 } 765}