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