• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

burningwave / json / #7

25 Oct 2023 06:36AM UTC coverage: 45.756% (-3.2%) from 48.947%
#7

push

Roberto-Gentili
Releasing new version

372 of 813 relevant lines covered (45.76%)

0.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.01
/src/main/java/org/burningwave/json/Check.java
1
/*
2
 * This file is part of Burningwave JSON.
3
 *
4
 * Author: Roberto Gentili
5
 *
6
 * Hosted at: https://github.com/burningwave/json
7
 *
8
 * --
9
 *
10
 * The MIT License (MIT)
11
 *
12
 * Copyright (c) 2023 Roberto Gentili
13
 *
14
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
15
 * documentation files (the "Software"), to deal in the Software without restriction, including without
16
 * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17
 * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
18
 * conditions:
19
 *
20
 * The above copyright notice and this permission notice shall be included in all copies or substantial
21
 * portions of the Software.
22
 *
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24
 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25
 * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
27
 * OR OTHER DEALINGS IN THE SOFTWARE.
28
 */
29
package org.burningwave.json;
30

31
import java.util.ArrayList;
32
import java.util.Arrays;
33
import java.util.Collection;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.function.Consumer;
37
import java.util.function.Predicate;
38
import java.util.function.UnaryOperator;
39

40
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
41
import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema;
42
import com.fasterxml.jackson.module.jsonSchema.types.BooleanSchema;
43
import com.fasterxml.jackson.module.jsonSchema.types.IntegerSchema;
44
import com.fasterxml.jackson.module.jsonSchema.types.NumberSchema;
45
import com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema;
46
import com.fasterxml.jackson.module.jsonSchema.types.StringSchema;
47

48
@SuppressWarnings("unchecked")
49
public interface Check<S extends JsonSchema, T, O extends Check<S, T, O>> {
50

51
        public O execute(Consumer<Path.Validation.Context<S, T>> action);
52

53
        public default O checkMandatory() {
54
                return execute(pathValidationContext -> {
1✔
55
                        if (pathValidationContext.isFieldRequired() && pathValidationContext.getRawValue() == null) {
1✔
56
                                pathValidationContext.rejectValue("IS_NULL", "is null");
×
57
                        }
58
                });
1✔
59
        }
60

61
// All
62
        public static Group forAll() {
63
                return Group.of(
1✔
64
                        whenObject(null),
1✔
65
                        whenIndexedObject(null),
1✔
66
                        whenValue(null)
1✔
67
                );
68
        }
69

70
        public static <O> Group when(Predicate<Path.Validation.Context<JsonSchema, O>> predicate) {
71
                return Group.of(
×
72
                        whenObject((Predicate)predicate),
×
73
                        whenIndexedObject((Predicate)predicate),
×
74
                        whenValue((Predicate)predicate)
×
75
                );
76
        }
77

78
        public static Group whenPathStartsWith(String... pathSegments) {
79
                return Group.of(
×
80
                        whenObjectPathStartsWith(pathSegments),
×
81
                        whenIndexedObjectPathStartsWith(pathSegments),
×
82
                        whenValuePathStartsWith(pathSegments)
×
83
                );
84
        }
85

86
        public static Group whenPathEndsWith(String... pathSegments) {
87
                return Group.of(
×
88
                        whenObjectPathEndsWith(pathSegments),
×
89
                        whenIndexedObjectPathEndsWith(pathSegments),
×
90
                        whenValuePathEndsWith(pathSegments)
×
91
                );
92
        }
93

94
        public static Group whenPathContains(String... pathSegments) {
95
                return Group.of(
×
96
                        whenObjectPathContains(pathSegments),
×
97
                        whenIndexedObjectPathContains(pathSegments),
×
98
                        whenValuePathContains(pathSegments)
×
99
                );
100
        }
101

102
        public static Group whenPathEquals(String... pathSegments) {
103
                return Group.of(
×
104
                        whenObjectPathEquals(pathSegments),
×
105
                        whenIndexedObjectPathEquals(pathSegments),
×
106
                        whenValuePathEquals(pathSegments)
×
107
                );
108
        }
109

110
// Value
111
        public static LeafCheck<JsonSchema, Object> forAllValues() {
112
                return whenValue(null);
×
113
        }
114

115
        public static LeafCheck<JsonSchema, Object> whenValue(Predicate<Path.Validation.Context<JsonSchema, Object>> predicate) {
116
                return new LeafCheck<>(JsonSchema.class, predicate);
1✔
117
        }
118

119
        public static LeafCheck<JsonSchema, Object> whenValuePathStartsWith(String... pathSegments) {
120
                return new LeafCheck<>(
×
121
                        JsonSchema.class,
122
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
123
                 );
124
        }
125

126
        public static LeafCheck<JsonSchema, Object> whenValuePathEndsWith(String... pathSegments) {
127
                return new LeafCheck<>(
×
128
                        JsonSchema.class,
129
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
130
                 );
131
        }
132

133
        public static LeafCheck<JsonSchema, Object> whenValuePathContains(String... pathSegments) {
134
                return new LeafCheck<>(
×
135
                        JsonSchema.class,
136
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
137
                 );
138
        }
139

140
        public static LeafCheck<JsonSchema, Object> whenValuePathEquals(String... pathSegments) {
141
                return new LeafCheck<>(
×
142
                        JsonSchema.class,
143
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
144
                 );
145
        }
146

147
        // String
148
        public static LeafCheck<StringSchema, String> forAllStringValues() {
149
                return whenStringValue(null);
1✔
150
        }
151

152
        public static LeafCheck.OfString whenStringValue(Predicate<Path.Validation.Context<StringSchema,String>> predicate) {
153
                return new LeafCheck.OfString(predicate);
1✔
154
        }
155

156
        public static LeafCheck<StringSchema, String> whenStringValuePathStartsWith(String... pathSegments) {
157
                return new LeafCheck.OfString(
×
158
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
159
                 );
160
        }
161

162
        public static LeafCheck<StringSchema, String> whenStringValuePathEndsWith(String... pathSegments) {
163
                return new LeafCheck.OfString(
×
164
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
165
                 );
166
        }
167

168
        public static LeafCheck<StringSchema, String> whenStringValuePathContains(String... pathSegments) {
169
                return new LeafCheck.OfString(
×
170
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
171
                 );
172
        }
173

174
        public static LeafCheck<StringSchema, String> whenStringValuePathEquals(String... pathSegments) {
175
                return new LeafCheck.OfString(
×
176
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
177
                 );
178
        }
179

180
        // Integer
181
        public static LeafCheck<IntegerSchema, Integer> forAllIntegerValues() {
182
                return whenIntegerValue(null);
×
183
        }
184

185
        public static LeafCheck<IntegerSchema, Integer> whenIntegerValue(Predicate<Path.Validation.Context<IntegerSchema,Integer>> predicate) {
186
                return new LeafCheck<>(IntegerSchema.class, predicate);
×
187
        }
188

189
        public static LeafCheck<IntegerSchema, String> whenIntegerValuePathStartsWith(String... pathSegments) {
190
                return new LeafCheck<>(
×
191
                        IntegerSchema.class,
192
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
193
                 );
194
        }
195

196
        public static LeafCheck<IntegerSchema, String> whenIntegerValuePathEndsWith(String... pathSegments) {
197
                return new LeafCheck<>(
×
198
                        IntegerSchema.class,
199
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
200
                 );
201
        }
202

203
        public static LeafCheck<IntegerSchema, String> whenIntegerValuePathContains(String... pathSegments) {
204
                return new LeafCheck<>(
×
205
                        IntegerSchema.class,
206
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
207
                 );
208
        }
209

210
        public static LeafCheck<IntegerSchema, String> whenIntegerValuePathEquals(String... pathSegments) {
211
                return new LeafCheck<>(
×
212
                        IntegerSchema.class,
213
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
214
                 );
215
        }
216

217
        // Number
218
        public static LeafCheck<NumberSchema, Number> forAllNumberValues() {
219
                return whenNumberValue(null);
×
220
        }
221

222
        public static LeafCheck<NumberSchema, Number> whenNumberValue(Predicate<Path.Validation.Context<NumberSchema,Number>> predicate) {
223
                return new LeafCheck<>(NumberSchema.class, predicate);
×
224
        }
225

226
        public static LeafCheck<NumberSchema, String> whenNumberValuePathStartsWith(String... pathSegments) {
227
                return new LeafCheck<>(
×
228
                        NumberSchema.class,
229
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
230
                 );
231
        }
232

233
        public static LeafCheck<NumberSchema, String> whenNumberValuePathEndsWith(String... pathSegments) {
234
                return new LeafCheck<>(
×
235
                        NumberSchema.class,
236
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
237
                 );
238
        }
239

240
        public static LeafCheck<NumberSchema, String> whenNumberValuePathContains(String... pathSegments) {
241
                return new LeafCheck<>(
×
242
                        NumberSchema.class,
243
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
244
                 );
245
        }
246

247
        public static LeafCheck<NumberSchema, String> whenNumberValuePathEquals(String... pathSegments) {
248
                return new LeafCheck<>(
×
249
                        NumberSchema.class,
250
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
251
                 );
252
        }
253

254
        //Boolean
255
        public static LeafCheck<BooleanSchema, Boolean> forAllBooleanValues() {
256
                return whenBooleanValue(null);
×
257
        }
258

259
        public static LeafCheck<BooleanSchema, Boolean> whenBooleanValue(Predicate<Path.Validation.Context<BooleanSchema,Boolean>> predicate) {
260
                return new LeafCheck<>(BooleanSchema.class, predicate);
×
261
        }
262

263
        public static LeafCheck<BooleanSchema, String> whenBooleanValuePathStartsWith(String... pathSegments) {
264
                return new LeafCheck<>(
×
265
                        BooleanSchema.class,
266
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
267
                 );
268
        }
269

270
        public static LeafCheck<BooleanSchema, String> whenBooleanValuePathEndsWith(String... pathSegments) {
271
                return new LeafCheck<>(
×
272
                        BooleanSchema.class,
273
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
274
                 );
275
        }
276

277
        public static LeafCheck<BooleanSchema, String> whenBooleanValuePathEquals(String... pathSegments) {
278
                return new LeafCheck<>(
×
279
                        BooleanSchema.class,
280
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
281
                 );
282
        }
283

284
        public static LeafCheck<BooleanSchema, String> whenBooleanValuePathContains(String... pathSegments) {
285
                return new LeafCheck<>(
×
286
                        BooleanSchema.class,
287
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
288
                 );
289
        }
290

291
// Object
292
        public static ObjectCheck forAllObjects() {
293
                return whenObject(null);
×
294
        }
295

296
        public static ObjectCheck whenObject(Predicate<Path.Validation.Context<ObjectSchema, Map<String, Object>>> predicate) {
297
                return new ObjectCheck(predicate);
1✔
298
        }
299

300
        public static ObjectCheck whenObjectPathStartsWith(String... pathSegments) {
301
                return new ObjectCheck(
×
302
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
303
                 );
304
        }
305

306
        public static ObjectCheck whenObjectPathEndsWith(String... pathSegments) {
307
                return new ObjectCheck(
×
308
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
309
                 );
310
        }
311

312
        public static ObjectCheck whenObjectPathContains(String... pathSegments) {
313
                return new ObjectCheck(
×
314
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
315
                 );
316
        }
317

318
        public static ObjectCheck whenObjectPathEquals(String... pathSegments) {
319
                return new ObjectCheck(
×
320
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
321
                 );
322
        }
323

324
// Indexed objects
325
        public static <I> IndexedObjectCheck<I> forAllIndexedObjects() {
326
                return whenIndexedObject(null);
×
327
        }
328

329
        public static <I> IndexedObjectCheck<I> whenIndexedObject(Predicate<Path.Validation.Context<ArraySchema, List<I>>> predicate) {
330
                return new IndexedObjectCheck<>(null, predicate);
1✔
331
        }
332

333
        public static <I> IndexedObjectCheck<I> whenIndexedObjectPathStartsWith(String... pathSegments) {
334
                return new IndexedObjectCheck<>(
×
335
                        null,
336
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
337
                 );
338
        }
339

340
        public static <I> IndexedObjectCheck<I> whenIndexedObjectPathEndsWith(String... pathSegments) {
341
                return new IndexedObjectCheck<>(
×
342
                        null,
343
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
344
                 );
345
        }
346

347
        public static <I> IndexedObjectCheck<I> whenIndexedObjectPathContains(String... pathSegments) {
348
                return new IndexedObjectCheck<>(
×
349
                        null,
350
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
351
                 );
352
        }
353

354
        public static <I> IndexedObjectCheck<I> whenIndexedObjectPathEquals(String... pathSegments) {
355
                return new IndexedObjectCheck<>(
×
356
                        null,
357
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
358
                 );
359
        }
360

361
        // Indexed strings
362
        public static IndexedObjectCheck<String> forAllIndexedStrings() {
363
                return whenIndexedStrings(null);
×
364
        }
365

366
        public static IndexedObjectCheck<String> whenIndexedStrings(Predicate<Path.Validation.Context<ArraySchema, List<String>>> predicate) {
367
                return new IndexedObjectCheck<>(StringSchema.class, predicate);
×
368
        }
369

370
        public static IndexedObjectCheck<String> whenIndexedStringsPathStartsWith(String... pathSegments) {
371
                return new IndexedObjectCheck<>(
×
372
                        StringSchema.class,
373
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
374
                 );
375
        }
376

377
        public static IndexedObjectCheck<String> whenIndexedStringsPathEndsWith(String... pathSegments) {
378
                return new IndexedObjectCheck<>(
×
379
                        StringSchema.class,
380
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
381
                 );
382
        }
383

384
        public static IndexedObjectCheck<String> whenIndexedStringsPathContains(String... pathSegments) {
385
                return new IndexedObjectCheck<>(
×
386
                        StringSchema.class,
387
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
388
                 );
389
        }
390

391
        public static IndexedObjectCheck<String> whenIndexedStringsPathEquals(String... pathSegments) {
392
                return new IndexedObjectCheck<>(
×
393
                        StringSchema.class,
394
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
395
                 );
396
        }
397

398
        // Indexed integers
399
        public static IndexedObjectCheck<Integer> forAllIndexedIntegers() {
400
                return whenIndexedIntegers(null);
×
401
        }
402

403
        public static IndexedObjectCheck<Integer> whenIndexedIntegers(Predicate<Path.Validation.Context<ArraySchema, List<Integer>>> predicate) {
404
                return new IndexedObjectCheck<>(IntegerSchema.class, predicate);
×
405
        }
406

407
        public static IndexedObjectCheck<Integer> whenIndexedIntegersPathStartsWith(String... pathSegments) {
408
                return new IndexedObjectCheck<>(
×
409
                        IntegerSchema.class,
410
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
411
                 );
412
        }
413

414
        public static IndexedObjectCheck<Integer> whenIndexedIntegersPathEndsWith(String... pathSegments) {
415
                return new IndexedObjectCheck<>(
×
416
                        IntegerSchema.class,
417
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
418
                 );
419
        }
420

421
        public static IndexedObjectCheck<Integer> whenIndexedIntegersPathContains(String... pathSegments) {
422
                return new IndexedObjectCheck<>(
×
423
                        IntegerSchema.class,
424
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
425
                 );
426
        }
427

428
        public static IndexedObjectCheck<Integer> whenIndexedIntegersPathEquals(String... pathSegments) {
429
                return new IndexedObjectCheck<>(
×
430
                        IntegerSchema.class,
431
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
432
                 );
433
        }
434

435
        // Indexed numbers
436
        public static IndexedObjectCheck<Number> forAllIndexedNumbers() {
437
                return whenIndexedNumbers(null);
×
438
        }
439

440
        public static IndexedObjectCheck<Number> whenIndexedNumbers(Predicate<Path.Validation.Context<ArraySchema, List<Number>>> predicate) {
441
                return new IndexedObjectCheck<>(NumberSchema.class, predicate);
×
442
        }
443

444
        public static IndexedObjectCheck<Number> whenIndexedNumbersPathStartsWith(String... pathSegments) {
445
                return new IndexedObjectCheck<>(
×
446
                        NumberSchema.class,
447
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toStartsWithRegEx)
×
448
                 );
449
        }
450

451
        public static IndexedObjectCheck<Number> whenIndexedNumbersPathEndsWith(String... pathSegments) {
452
                return new IndexedObjectCheck<>(
×
453
                        NumberSchema.class,
454
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toEndsWithRegEx)
×
455
                 );
456
        }
457

458
        public static IndexedObjectCheck<Number> whenIndexedNumbersPathContains(String... pathSegments) {
459
                return new IndexedObjectCheck<>(
×
460
                        NumberSchema.class,
461
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toContainsRegEx)
×
462
                 );
463
        }
464

465
        public static IndexedObjectCheck<Number> whenIndexedNumbersPathEquals(String... pathSegments) {
466
                return new IndexedObjectCheck<>(
×
467
                        NumberSchema.class,
468
                        Abst.buildPathPredicate(Path.of(pathSegments), Path.INSTANCE::toRegEx)
×
469
                 );
470
        }
471

472
        // Indexed boolean
473
        public static IndexedObjectCheck<Boolean> forAllIndexedBooleans() {
474
                return whenIndexedBooleans(null);
×
475
        }
476

477
        public static IndexedObjectCheck<Boolean> whenIndexedBooleans(Predicate<Path.Validation.Context<ArraySchema, List<Boolean>>> predicate) {
478
                return new IndexedObjectCheck<>(BooleanSchema.class, predicate);
×
479
        }
480

481
        public static IndexedObjectCheck<Boolean> whenIndexedBooleansPathStartsWith(String path) {
482
                return new IndexedObjectCheck<>(
×
483
                        BooleanSchema.class,
484
                        Abst.buildPathPredicate(path, Path.INSTANCE::toStartsWithRegEx)
×
485
                 );
486
        }
487

488
        public static IndexedObjectCheck<Boolean> whenIndexedBooleansPathEndsWith(String path) {
489
                return new IndexedObjectCheck<>(
×
490
                        BooleanSchema.class,
491
                        Abst.buildPathPredicate(path, Path.INSTANCE::toEndsWithRegEx)
×
492
                 );
493
        }
494

495
        public static IndexedObjectCheck<Boolean> whenIndexedBooleansPathContains(String path) {
496
                return new IndexedObjectCheck<>(
×
497
                        BooleanSchema.class,
498
                        Abst.buildPathPredicate(path, Path.INSTANCE::toContainsRegEx)
×
499
                 );
500
        }
501

502
        public static IndexedObjectCheck<Boolean> whenIndexedBooleansPathEquals(String path) {
503
                return new IndexedObjectCheck<>(
×
504
                        BooleanSchema.class,
505
                        Abst.buildPathPredicate(path, Path.INSTANCE::toRegEx)
×
506
                 );
507
        }
508

509
        abstract class Abst<S extends JsonSchema, T, C extends Abst<S, T, C>> implements Check<S, T, C> {
510
                Class<S> schemaClass;
511
                Predicate<Path.Validation.Context<S,T>> predicate;
512
                Consumer<Path.Validation.Context<S,T>> action;
513

514
                Abst(Class<S> jsonSchemaClass, Predicate<Path.Validation.Context<S,T>> predicate) {
1✔
515
                        this.schemaClass = jsonSchemaClass;
1✔
516
                        this.predicate = buildBasicPredicate(jsonSchemaClass);
1✔
517
                        if (predicate != null) {
1✔
518
                                this.predicate = this.predicate.and(predicate);
×
519
                        }
520
                }
1✔
521

522
                Predicate<Path.Validation.Context<S,T>> buildBasicPredicate(Class<? extends JsonSchema> jsonSchemaClass) {
523
                        return pathValidationContext -> jsonSchemaClass.isInstance(pathValidationContext.jsonSchema);
1✔
524
                }
525

526
                static <S extends JsonSchema, T> Predicate<Path.Validation.Context<S,T>> buildPathPredicate(String path, UnaryOperator<String> pathProcessor) {
527
                        String pathRegEx = pathProcessor != null ?
×
528
                                                pathProcessor.apply(path) : path;
×
529
                        return new Path.Predicate<Path.Validation.Context<S,T>>(path, pathRegEx) {
×
530
                                @Override
531
                                public boolean test(Path.Validation.Context<S, T> pathValidationContext) {
532
                                        return pathValidationContext.path.matches(pathRegEx);
×
533
                                }
534

535
                        };
536
                }
537

538
                @Override
539
                public synchronized C execute(Consumer<Path.Validation.Context<S,T>> action) {
540
                        if (this.action != null) {
1✔
541
                                this.action = this.action.andThen(action);
×
542
                        } else {
543
                                this.action = action;
1✔
544
                        }
545
                        return (C)this;
1✔
546
                }
547

548
        }
549

550
        public static class Group implements Check<JsonSchema, Object, Group> {
551
                Collection<Check<?, ?, ?>> items;
552

553
                public Group(Check<?, ?, ?>... items) {
1✔
554
                        this.items = new ArrayList<>(Arrays.asList(items));
1✔
555
                }
1✔
556

557
                public static Check.Group of(Check<?, ?, ?>... items) {
558
                        return new Check.Group(items);
1✔
559
                }
560

561
                @Override
562
                public Check.Group execute(Consumer<Path.Validation.Context<JsonSchema, Object>> action) {
563
                        for (Check<?, ?, ?> item : this.items) {
1✔
564
                                ((Abst<?, ?, ?>)item).action = (Consumer)action;
1✔
565
                        }
1✔
566
                        return this;
1✔
567
                }
568

569

570
        }
571

572
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc