@@ -16,8 +16,6 @@ class ArraySchemaValidatingVisitor extends Visitor {
16
16
17
17
private final Object subject ;
18
18
19
- private final FailureReporter failureReporter ;
20
-
21
19
private final ValidatingVisitor owner ;
22
20
23
21
private JSONArray arraySubject ;
@@ -26,16 +24,15 @@ class ArraySchemaValidatingVisitor extends Visitor {
26
24
27
25
private int subjectLength ;
28
26
29
- public ArraySchemaValidatingVisitor (Object subject , ValidatingVisitor owner , FailureReporter failureReporter ) {
27
+ public ArraySchemaValidatingVisitor (Object subject , ValidatingVisitor owner ) {
30
28
this .subject = subject ;
31
29
this .owner = requireNonNull (owner , "owner cannot be null" );
32
- this .failureReporter = requireNonNull (failureReporter , "failureReporter cannot be null" );
33
30
}
34
31
35
32
@ Override void visitArraySchema (ArraySchema arraySchema ) {
36
33
if (!(subject instanceof JSONArray )) {
37
34
if (arraySchema .requiresArray ()) {
38
- failureReporter .failure (JSONArray .class , subject );
35
+ owner .failure (JSONArray .class , subject );
39
36
}
40
37
} else {
41
38
this .arraySubject = (JSONArray ) subject ;
@@ -47,13 +44,13 @@ public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner, Fai
47
44
48
45
@ Override void visitMinItems (Integer minItems ) {
49
46
if (minItems != null && subjectLength < minItems ) {
50
- failureReporter .failure ("expected minimum item count: " + minItems + ", found: " + subjectLength , "minItems" );
47
+ owner .failure ("expected minimum item count: " + minItems + ", found: " + subjectLength , "minItems" );
51
48
}
52
49
}
53
50
54
51
@ Override void visitMaxItems (Integer maxItems ) {
55
52
if (maxItems != null && maxItems < subjectLength ) {
56
- failureReporter .failure ("expected maximum item count: " + maxItems + ", found: " + subjectLength , "maxItems" );
53
+ owner .failure ("expected maximum item count: " + maxItems + ", found: " + subjectLength , "maxItems" );
57
54
}
58
55
}
59
56
@@ -66,7 +63,7 @@ public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner, Fai
66
63
Object item = arraySubject .get (i );
67
64
for (Object contained : uniques ) {
68
65
if (ObjectComparator .deepEquals (contained , item )) {
69
- failureReporter .failure ("array items are not unique" , "uniqueItems" );
66
+ owner .failure ("array items are not unique" , "uniqueItems" );
70
67
return ;
71
68
}
72
69
}
@@ -88,14 +85,14 @@ public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner, Fai
88
85
String idx = String .valueOf (index );
89
86
ifFails (itemSchema , subject )
90
87
.map (exc -> exc .prepend (idx ))
91
- .ifPresent (failureReporter ::failure );
88
+ .ifPresent (owner ::failure );
92
89
}
93
90
94
91
@ Override void visitAdditionalItems (boolean additionalItems ) {
95
92
List <Schema > itemSchemas = arraySchema .getItemSchemas ();
96
93
int itemSchemaCount = itemSchemas == null ? 0 : itemSchemas .size ();
97
94
if (itemSchemas != null && !additionalItems && subjectLength > itemSchemaCount ) {
98
- failureReporter .failure (format ("expected: [%d] array items, found: [%d]" , itemSchemaCount , subjectLength ), "items" );
95
+ owner .failure (format ("expected: [%d] array items, found: [%d]" , itemSchemaCount , subjectLength ), "items" );
99
96
}
100
97
}
101
98
@@ -116,7 +113,7 @@ private void validateItemsAgainstSchema(IntStream indices, IntFunction<Schema> s
116
113
String copyOfI = String .valueOf (i ); // i is not effectively final so we copy it
117
114
ifFails (schemaForIndex .apply (i ), arraySubject .get (i ))
118
115
.map (exc -> exc .prepend (copyOfI ))
119
- .ifPresent (failureReporter ::failure );
116
+ .ifPresent (owner ::failure );
120
117
}
121
118
}
122
119
@@ -134,6 +131,6 @@ private Optional<ValidationException> ifFails(Schema schema, Object input) {
134
131
return ;
135
132
}
136
133
}
137
- failureReporter .failure ("expected at least one array item to match 'contains' schema" , "contains" );
134
+ owner .failure ("expected at least one array item to match 'contains' schema" , "contains" );
138
135
}
139
136
}
0 commit comments