@@ -39,7 +39,9 @@ public DefaultValidator(Function<String, Schema> refResolver) {
3939
4040 @ Override
4141 public void validate (Object value , Schema schema , String pointer ) {
42- if (value == null && schema .types ().contains (TypeName .NULL )) return ;
42+ if (value == null && schema .types ().contains (TypeName .NULL )) {
43+ return ;
44+ }
4345
4446 switch (schema ) {
4547 case RefSchema r -> validate (value , refResolver .apply (r .pointer ()), pointer );
@@ -68,15 +70,21 @@ private void validateBoolean(Object value, String pointer) {
6870 private void validateString (Object value , StringSchema s , String pointer ) {
6971 require (value instanceof String , pointer , "type" , "expected string" );
7072 String str = (String ) value ;
71- if (s .minLength () != null && str .length () < s .minLength ())
73+ if (s .minLength () != null && str .length () < s .minLength ()) {
7274 fail (pointer , "minLength" , "string shorter than " + s .minLength (), str );
73- if (s .maxLength () != null && str .length () > s .maxLength ())
75+ }
76+ if (s .maxLength () != null && str .length () > s .maxLength ()) {
7477 fail (pointer , "maxLength" , "string longer than " + s .maxLength (), str );
75- if (s .pattern () != null && !Pattern .compile (s .pattern ()).matcher (str ).matches ())
78+ }
79+ if (s .pattern () != null && !Pattern .compile (s .pattern ()).matcher (str ).matches ()) {
7680 fail (pointer , "pattern" , "does not match pattern " + s .pattern (), str );
77- if (s .enumValues () != null && !s .enumValues ().contains (str ))
81+ }
82+ if (s .enumValues () != null && !s .enumValues ().contains (str )) {
7883 fail (pointer , "enum" , "value not in enum" , str );
79- if (s .format () != null ) validateStringFormat (str , s .format (), pointer );
84+ }
85+ if (s .format () != null ) {
86+ validateStringFormat (str , s .format (), pointer );
87+ }
8088 }
8189
8290 private void validateStringFormat (String str , String format , String pointer ) {
@@ -108,8 +116,9 @@ private void validateStringFormat(String str, String format, String pointer) {
108116
109117 private void validateInteger (Object value , IntegerSchema s , String pointer ) {
110118 long n ;
111- if (value instanceof Number num ) n = num .longValue ();
112- else if (value instanceof String str ) {
119+ if (value instanceof Number num ) {
120+ n = num .longValue ();
121+ } else if (value instanceof String str ) {
113122 try {
114123 n = Long .parseLong (str );
115124 } catch (NumberFormatException e ) {
@@ -121,22 +130,28 @@ else if (value instanceof String str) {
121130 return ;
122131 }
123132
124- if (s .minimum () != null && n < s .minimum ())
133+ if (s .minimum () != null && n < s .minimum ()) {
125134 fail (pointer , "minimum" , "integer below minimum " + s .minimum (), n );
126- if (s .maximum () != null && n > s .maximum ())
135+ }
136+ if (s .maximum () != null && n > s .maximum ()) {
127137 fail (pointer , "maximum" , "integer above maximum " + s .maximum (), n );
128- if (s .exclusiveMinimum () != null && n <= s .exclusiveMinimum ())
138+ }
139+ if (s .exclusiveMinimum () != null && n <= s .exclusiveMinimum ()) {
129140 fail (pointer , "exclusiveMinimum" , "integer not greater than " + s .exclusiveMinimum (), n );
130- if (s .exclusiveMaximum () != null && n >= s .exclusiveMaximum ())
141+ }
142+ if (s .exclusiveMaximum () != null && n >= s .exclusiveMaximum ()) {
131143 fail (pointer , "exclusiveMaximum" , "integer not less than " + s .exclusiveMaximum (), n );
132- if (s .multipleOf () != null && n % s .multipleOf () != 0 )
144+ }
145+ if (s .multipleOf () != null && n % s .multipleOf () != 0 ) {
133146 fail (pointer , "multipleOf" , "not a multiple of " + s .multipleOf (), n );
147+ }
134148 }
135149
136150 private void validateNumber (Object value , NumberSchema s , String pointer ) {
137151 double n ;
138- if (value instanceof Number num ) n = num .doubleValue ();
139- else if (value instanceof String str ) {
152+ if (value instanceof Number num ) {
153+ n = num .doubleValue ();
154+ } else if (value instanceof String str ) {
140155 try {
141156 n = Double .parseDouble (str );
142157 } catch (NumberFormatException e ) {
@@ -148,16 +163,21 @@ else if (value instanceof String str) {
148163 return ;
149164 }
150165
151- if (s .minimum () != null && n < s .minimum ().doubleValue ())
166+ if (s .minimum () != null && n < s .minimum ().doubleValue ()) {
152167 fail (pointer , "minimum" , "number below minimum " + s .minimum (), n );
153- if (s .maximum () != null && n > s .maximum ().doubleValue ())
168+ }
169+ if (s .maximum () != null && n > s .maximum ().doubleValue ()) {
154170 fail (pointer , "maximum" , "number above maximum " + s .maximum (), n );
155- if (s .exclusiveMinimum () != null && n <= s .exclusiveMinimum ().doubleValue ())
171+ }
172+ if (s .exclusiveMinimum () != null && n <= s .exclusiveMinimum ().doubleValue ()) {
156173 fail (pointer , "exclusiveMinimum" , "number not greater than " + s .exclusiveMinimum (), n );
157- if (s .exclusiveMaximum () != null && n >= s .exclusiveMaximum ().doubleValue ())
174+ }
175+ if (s .exclusiveMaximum () != null && n >= s .exclusiveMaximum ().doubleValue ()) {
158176 fail (pointer , "exclusiveMaximum" , "number not less than " + s .exclusiveMaximum (), n );
159- if (s .multipleOf () != null && (n / s .multipleOf ().doubleValue ()) % 1 != 0 )
177+ }
178+ if (s .multipleOf () != null && (n / s .multipleOf ().doubleValue ()) % 1 != 0 ) {
160179 fail (pointer , "multipleOf" , "not a multiple of " + s .multipleOf (), n );
180+ }
161181 }
162182
163183 @ SuppressWarnings ("unchecked" )
@@ -173,10 +193,12 @@ private void validateObject(Object value, ObjectSchema s, String pointer) {
173193 "required property missing" );
174194 }
175195
176- if (s .minProperties () != null && map .size () < s .minProperties ())
196+ if (s .minProperties () != null && map .size () < s .minProperties ()) {
177197 fail (pointer , "minProperties" , "fewer than " + s .minProperties () + " properties" , map .size ());
178- if (s .maxProperties () != null && map .size () > s .maxProperties ())
198+ }
199+ if (s .maxProperties () != null && map .size () > s .maxProperties ()) {
179200 fail (pointer , "maxProperties" , "more than " + s .maxProperties () + " properties" , map .size ());
201+ }
180202
181203 for (var entry : map .entrySet ()) {
182204 String childPointer = pointer + "/" + entry .getKey ();
@@ -203,17 +225,23 @@ private void validateArray(Object value, ArraySchema s, String pointer) {
203225 require (value instanceof Iterable , pointer , "type" , "expected array" );
204226 Iterable <?> it = (Iterable <?>) value ;
205227 List <Object > elements = new ArrayList <>();
206- for (Object o : it ) elements .add (o );
228+ for (Object o : it ) {
229+ elements .add (o );
230+ }
207231
208- if (s .minItems () != null && elements .size () < s .minItems ())
232+ if (s .minItems () != null && elements .size () < s .minItems ()) {
209233 fail (pointer , "minItems" , "fewer than " + s .minItems () + " items" , elements .size ());
210- if (s .maxItems () != null && elements .size () > s .maxItems ())
234+ }
235+ if (s .maxItems () != null && elements .size () > s .maxItems ()) {
211236 fail (pointer , "maxItems" , "more than " + s .maxItems () + " items" , elements .size ());
237+ }
212238
213239 if (s .uniqueItems ()) {
214240 Set <Object > seen = new HashSet <>();
215241 for (Object e : elements ) {
216- if (!seen .add (e )) fail (pointer , "uniqueItems" , "duplicate item" , e );
242+ if (!seen .add (e )) {
243+ fail (pointer , "uniqueItems" , "duplicate item" , e );
244+ }
217245 }
218246 }
219247
0 commit comments