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