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