1
2
3
4
5
6 package gov.nist.secauto.metaschema.schemagen.json.impl.builder;
7
8 import com.fasterxml.jackson.databind.node.ObjectNode;
9
10 import gov.nist.secauto.metaschema.core.model.IGroupable;
11 import gov.nist.secauto.metaschema.schemagen.json.IJsonGenerationState;
12
13 public class SingletonBuilder
14 extends AbstractCollectionBuilder<SingletonBuilder> {
15 private int minOccurrence = IGroupable.DEFAULT_GROUP_AS_MIN_OCCURS;
16
17 @Override
18 protected SingletonBuilder thisBuilder() {
19 return this;
20 }
21
22 @Override
23 public int getMinOccurrence() {
24 return minOccurrence;
25 }
26
27 @Override
28 public int getMaxOccurrence() {
29 return 1;
30 }
31
32 @Override
33 public SingletonBuilder minItems(int min) {
34 if (min < 0 || min > 1) {
35 throw new IllegalArgumentException(
36 String.format("The minimum value '%d' must be 0 or 1.", min));
37 }
38 minOccurrence = min;
39 return this;
40 }
41
42 @Override
43 public SingletonBuilder maxItems(int max) {
44 if (max != 1) {
45 throw new IllegalArgumentException(
46 String.format("The maximum value '%d' must be 1.", max));
47 }
48 return this;
49 }
50
51 @Override
52 public void build(
53 ObjectNode object,
54 IJsonGenerationState state) {
55 if (!getTypes().isEmpty()) {
56 buildInternal(object, state);
57 }
58 }
59 }