Skip to content

Commit 361bdc4

Browse files
committed
Change evaluationPath from ArrayDeque back to NodePath
1 parent 9728204 commit 361bdc4

31 files changed

+168
-367
lines changed

src/main/java/com/networknt/schema/Error.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2525
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
2626
import com.networknt.schema.i18n.MessageFormatter;
27-
import com.networknt.schema.path.EvaluationPath;
2827
import com.networknt.schema.path.NodePath;
2928
import com.networknt.schema.utils.CachingSupplier;
3029
import com.networknt.schema.utils.Strings;
3130

3231
import java.text.MessageFormat;
33-
import java.util.ArrayDeque;
3432
import java.util.Arrays;
3533
import java.util.HashMap;
3634
import java.util.Map;
@@ -51,7 +49,7 @@
5149
public class Error {
5250
private final String keyword;
5351
@JsonSerialize(using = ToStringSerializer.class)
54-
private final EvaluationPath evaluationPath;
52+
private final NodePath evaluationPath;
5553
@JsonSerialize(using = ToStringSerializer.class)
5654
private final SchemaLocation schemaLocation;
5755
@JsonSerialize(using = ToStringSerializer.class)
@@ -63,7 +61,7 @@ public class Error {
6361
private final JsonNode instanceNode;
6462
private final JsonNode schemaNode;
6563

66-
Error(String keyword, EvaluationPath evaluationPath, SchemaLocation schemaLocation,
64+
Error(String keyword, NodePath evaluationPath, SchemaLocation schemaLocation,
6765
NodePath instanceLocation, Object[] arguments, Map<String, Object> details,
6866
String messageKey, Supplier<String> messageSupplier, JsonNode instanceNode, JsonNode schemaNode) {
6967
super();
@@ -96,7 +94,7 @@ public NodePath getInstanceLocation() {
9694
*
9795
* @return the evaluation path
9896
*/
99-
public EvaluationPath getEvaluationPath() {
97+
public NodePath getEvaluationPath() {
10098
return evaluationPath;
10199
}
102100

@@ -242,7 +240,7 @@ public static abstract class BuilderSupport<S> {
242240
public abstract S self();
243241

244242
protected String keyword;
245-
protected EvaluationPath evaluationPath;
243+
protected NodePath evaluationPath;
246244
protected SchemaLocation schemaLocation;
247245
protected NodePath instanceLocation;
248246
protected Object[] arguments;
@@ -311,16 +309,11 @@ public S schemaLocation(SchemaLocation schemaLocation) {
311309
* @param evaluationPath the evaluation path
312310
* @return the builder
313311
*/
314-
public S evaluationPath(EvaluationPath evaluationPath) {
312+
public S evaluationPath(NodePath evaluationPath) {
315313
this.evaluationPath = evaluationPath;
316314
return self();
317315
}
318316

319-
public S evaluationPath(ArrayDeque<Object> evaluationPath) {
320-
this.evaluationPath = new EvaluationPath(evaluationPath);
321-
return self();
322-
}
323-
324317
public S arguments(Object... arguments) {
325318
this.arguments = arguments;
326319
return self();
@@ -406,7 +399,7 @@ protected String getKeyword() {
406399
return keyword;
407400
}
408401

409-
protected EvaluationPath getEvaluationPath() {
402+
protected NodePath getEvaluationPath() {
410403
return evaluationPath;
411404
}
412405

src/main/java/com/networknt/schema/ExecutionContext.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,27 @@ public class ExecutionContext {
4343

4444
private final Map<NodePath, DiscriminatorState> discriminatorMapping = new HashMap<>();
4545

46-
final ArrayDeque<Object> evaluationPath = new ArrayDeque<>(64);
46+
NodePath evaluationPath;
4747
final ArrayDeque<Schema> evaluationSchema = new ArrayDeque<>(64);
4848
final ArrayDeque<Object> evaluationSchemaPath = new ArrayDeque<>(64);
4949

50-
public ArrayDeque<Object> getEvaluationPath() {
50+
public NodePath getEvaluationPath() {
5151
return evaluationPath;
5252
}
5353

54+
public void evaluationPathAddLast(String token) {
55+
this.evaluationPath = evaluationPath.append(token);
56+
}
57+
58+
public void evaluationPathAddLast(int token) {
59+
this.evaluationPath = evaluationPath.append(token);
60+
}
61+
62+
public void evaluationPathRemoveLast() {
63+
this.evaluationPath = evaluationPath.getParent();
64+
}
65+
66+
5467
public ArrayDeque<Schema> getEvaluationSchema() {
5568
return evaluationSchema;
5669
}

src/main/java/com/networknt/schema/Schema.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.fasterxml.jackson.databind.JsonNode;
3636
import com.networknt.schema.keyword.KeywordValidator;
3737
import com.networknt.schema.keyword.TypeValidator;
38-
import com.networknt.schema.path.EvaluationPath;
3938
import com.networknt.schema.path.NodePath;
4039
import com.networknt.schema.path.PathType;
4140
import com.networknt.schema.resource.ClasspathResourceLoader;
@@ -144,6 +143,7 @@ public void validate(ExecutionContext executionContext, JsonNode node) {
144143
* executionContext.evaluationPath.addLast(this.schemaLocation.getFragment().getElement(x));
145144
* }
146145
*/
146+
executionContext.evaluationPath = atRoot();
147147
validate(executionContext, node, node, atRoot());
148148
}
149149

@@ -421,7 +421,7 @@ public Schema getSubSchema(NodePath fragment) {
421421
.message("Reference {0} cannot be resolved")
422422
.instanceLocation(schemaLocation.getFragment())
423423
.schemaLocation(schemaLocation)
424-
.evaluationPath((EvaluationPath)null)
424+
.evaluationPath(null)
425425
.arguments(fragment).build();
426426
throw new InvalidSchemaRefException(error);
427427
}
@@ -537,7 +537,7 @@ private List<KeywordValidator> read(JsonNode schemaNode) {
537537
.message(
538538
"The value of a $recursiveAnchor must be a Boolean literal but is {0}")
539539
.instanceLocation(null)
540-
.evaluationPath((EvaluationPath) null)
540+
.evaluationPath(null)
541541
.schemaLocation(schemaPath)
542542
.arguments(nodeToUse.getNodeType().toString())
543543
.build();
@@ -622,12 +622,12 @@ public void validate(ExecutionContext executionContext, JsonNode jsonNode, JsonN
622622
try {
623623
int currentErrors = executionContext.getErrors().size();
624624
for (KeywordValidator v : validators) {
625-
executionContext.evaluationPath.addLast(v.getKeyword());
625+
executionContext.evaluationPathAddLast(v.getKeyword());
626626
executionContext.evaluationSchemaPath.addLast(v.getKeyword());
627627
try {
628628
v.validate(executionContext, jsonNode, rootNode, instanceLocation);
629629
} finally {
630-
executionContext.evaluationPath.removeLast();
630+
executionContext.evaluationPathRemoveLast();
631631
executionContext.evaluationSchemaPath.removeLast();
632632
}
633633
}
@@ -1498,6 +1498,7 @@ private <T> T walkAtNodeInternal(ExecutionContext executionContext, JsonNode nod
14981498
executionCustomizer.customize(executionContext, this.schemaContext);
14991499
}
15001500
// Walk through the schema.
1501+
executionContext.evaluationPath = atRoot();
15011502
walk(executionContext, node, rootNode, instanceLocation, validate);
15021503
return format.format(this, executionContext, this.schemaContext);
15031504
}
@@ -1525,12 +1526,12 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
15251526
if (executionContext.getWalkConfig().getKeywordWalkListenerRunner().runPreWalkListeners(executionContext,
15261527
validator.getKeyword(), node, rootNode, instanceLocation,
15271528
this, validator)) {
1528-
executionContext.evaluationPath.addLast(validator.getKeyword());
1529+
executionContext.evaluationPathAddLast(validator.getKeyword());
15291530
executionContext.evaluationSchemaPath.addLast(validator.getKeyword());
15301531
try {
15311532
validator.walk(executionContext, node, rootNode, instanceLocation, shouldValidateSchema);
15321533
} finally {
1533-
executionContext.evaluationPath.removeLast();
1534+
executionContext.evaluationPathRemoveLast();
15341535
executionContext.evaluationSchemaPath.removeLast();
15351536
}
15361537
}

src/main/java/com/networknt/schema/annotation/Annotation.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
*/
1616
package com.networknt.schema.annotation;
1717

18-
import java.util.ArrayDeque;
1918
import java.util.Objects;
2019

2120
import com.networknt.schema.SchemaLocation;
2221
import com.networknt.schema.keyword.Keyword;
23-
import com.networknt.schema.path.EvaluationPath;
2422
import com.networknt.schema.path.NodePath;
2523

2624
/**
@@ -30,11 +28,11 @@ public class Annotation {
3028
private final String keyword;
3129
private final NodePath instanceLocation;
3230
private final SchemaLocation schemaLocation;
33-
private final EvaluationPath evaluationPath;
31+
private final NodePath evaluationPath;
3432
private final Object value;
3533

3634
public Annotation(String keyword, NodePath instanceLocation, SchemaLocation schemaLocation,
37-
EvaluationPath evaluationPath, Object value) {
35+
NodePath evaluationPath, Object value) {
3836
super();
3937
this.keyword = keyword;
4038
this.instanceLocation = instanceLocation;
@@ -77,7 +75,7 @@ public SchemaLocation getSchemaLocation() {
7775
*
7876
* @return the evaluation path
7977
*/
80-
public EvaluationPath getEvaluationPath() {
78+
public NodePath getEvaluationPath() {
8179
return evaluationPath;
8280
}
8381

@@ -125,7 +123,7 @@ public static class Builder {
125123
private String keyword;
126124
private NodePath instanceLocation;
127125
private SchemaLocation schemaLocation;
128-
private EvaluationPath evaluationPath;
126+
private NodePath evaluationPath;
129127
private Object value;
130128

131129
public Builder keyword(Keyword keyword) {
@@ -148,16 +146,11 @@ public Builder schemaLocation(SchemaLocation schemaLocation) {
148146
return this;
149147
}
150148

151-
public Builder evaluationPath(EvaluationPath evaluationPath) {
149+
public Builder evaluationPath(NodePath evaluationPath) {
152150
this.evaluationPath = evaluationPath;
153151
return this;
154152
}
155153

156-
public Builder evaluationPath(ArrayDeque<Object> evaluationPath) {
157-
this.evaluationPath = new EvaluationPath(evaluationPath);
158-
return this;
159-
}
160-
161154
public Builder value(Object value) {
162155
this.value = value;
163156
return this;

src/main/java/com/networknt/schema/annotation/AnnotationPredicate.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import java.util.function.Predicate;
1919

2020
import com.networknt.schema.SchemaLocation;
21-
import com.networknt.schema.path.EvaluationPath;
2221
import com.networknt.schema.path.NodePath;
2322

2423
/**
2524
* A predicate for filtering annotations.
2625
*/
2726
public class AnnotationPredicate implements Predicate<Annotation> {
2827
final Predicate<NodePath> instanceLocationPredicate;
29-
final Predicate<EvaluationPath> evaluationPathPredicate;
28+
final Predicate<NodePath> evaluationPathPredicate;
3029
final Predicate<SchemaLocation> schemaLocationPredicate;
3130
final Predicate<String> keywordPredicate;
3231
final Predicate<Object> valuePredicate;
@@ -41,7 +40,7 @@ public class AnnotationPredicate implements Predicate<Annotation> {
4140
* @param valuePredicate for value
4241
*/
4342
protected AnnotationPredicate(Predicate<NodePath> instanceLocationPredicate,
44-
Predicate<EvaluationPath> evaluationPathPredicate, Predicate<SchemaLocation> schemaLocationPredicate,
43+
Predicate<NodePath> evaluationPathPredicate, Predicate<SchemaLocation> schemaLocationPredicate,
4544
Predicate<String> keywordPredicate, Predicate<Object> valuePredicate) {
4645
super();
4746
this.instanceLocationPredicate = instanceLocationPredicate;
@@ -74,7 +73,7 @@ public Predicate<NodePath> getInstanceLocationPredicate() {
7473
*
7574
* @return the predicate
7675
*/
77-
public Predicate<EvaluationPath> getEvaluationPathPredicate() {
76+
public Predicate<NodePath> getEvaluationPathPredicate() {
7877
return evaluationPathPredicate;
7978
}
8079

@@ -119,7 +118,7 @@ public static Builder builder() {
119118
*/
120119
public static class Builder {
121120
Predicate<NodePath> instanceLocationPredicate;
122-
Predicate<EvaluationPath> evaluationPathPredicate;
121+
Predicate<NodePath> evaluationPathPredicate;
123122
Predicate<SchemaLocation> schemaLocationPredicate;
124123
Predicate<String> keywordPredicate;
125124
Predicate<Object> valuePredicate;
@@ -129,7 +128,7 @@ public Builder instanceLocation(Predicate<NodePath> instanceLocationPredicate) {
129128
return this;
130129
}
131130

132-
public Builder evaluationPath(Predicate<EvaluationPath> evaluationPathPredicate) {
131+
public Builder evaluationPath(Predicate<NodePath> evaluationPathPredicate) {
133132
this.evaluationPathPredicate = evaluationPathPredicate;
134133
return this;
135134
}

src/main/java/com/networknt/schema/keyword/AllOfValidator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
6161
NodePath instanceLocation, boolean walk) {
6262
int schemaIndex = 0;
6363
for (Schema schema : this.schemas) {
64-
executionContext.getEvaluationPath().addLast(schemaIndex);
64+
executionContext.evaluationPathAddLast(schemaIndex);
6565
try {
6666
if (!walk) {
6767
schema.validate(executionContext, node, rootNode, instanceLocation);
6868
} else {
6969
schema.walk(executionContext, node, rootNode, instanceLocation, true);
7070
}
7171
} finally {
72-
executionContext.getEvaluationPath().removeLast();
72+
executionContext.evaluationPathRemoveLast();
7373
}
7474
schemaIndex++;
7575
}
@@ -85,11 +85,11 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
8585
int schemaIndex = 0;
8686
for (Schema schema : this.schemas) {
8787
// Walk through the schema
88-
executionContext.getEvaluationPath().addLast(schemaIndex);
88+
executionContext.evaluationPathAddLast(schemaIndex);
8989
try {
9090
schema.walk(executionContext, node, rootNode, instanceLocation, false);
9191
} finally {
92-
executionContext.getEvaluationPath().removeLast();
92+
executionContext.evaluationPathRemoveLast();
9393
}
9494
schemaIndex++;
9595
}

src/main/java/com/networknt/schema/keyword/AnyOfValidator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
8080
// If schema has type validator and node type doesn't match with schemaType then
8181
// ignore it
8282
// For union type, it is a must to call TypeValidator
83-
executionContext.getEvaluationPath().addLast(schemaIndex);
84-
executionContext.getEvaluationPath().addLast("type");
83+
executionContext.evaluationPathAddLast(schemaIndex);
84+
executionContext.evaluationPathAddLast("type");
8585
try {
8686

8787
if (typeValidator.getSchemaType() != JsonType.UNION && !typeValidator.equalsToSchemaType(node, executionContext)) {
@@ -94,19 +94,19 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
9494
continue;
9595
}
9696
} finally {
97-
executionContext.getEvaluationPath().removeLast();
98-
executionContext.getEvaluationPath().removeLast();
97+
executionContext.evaluationPathRemoveLast();
98+
executionContext.evaluationPathRemoveLast();
9999
}
100100
}
101-
executionContext.getEvaluationPath().addLast(schemaIndex);
101+
executionContext.evaluationPathAddLast(schemaIndex);
102102
try {
103103
if (!walk) {
104104
schema.validate(executionContext, node, rootNode, instanceLocation);
105105
} else {
106106
schema.walk(executionContext, node, rootNode, instanceLocation, true);
107107
}
108108
} finally {
109-
executionContext.getEvaluationPath().removeLast();
109+
executionContext.evaluationPathRemoveLast();
110110
}
111111
schemaIndex++;
112112

@@ -217,11 +217,11 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
217217
}
218218
int schemaIndex = 0;
219219
for (Schema schema : this.schemas) {
220-
executionContext.getEvaluationPath().addLast(schemaIndex);
220+
executionContext.evaluationPathAddLast(schemaIndex);
221221
try {
222222
schema.walk(executionContext, node, rootNode, instanceLocation, false);
223223
} finally {
224-
executionContext.getEvaluationPath().removeLast();
224+
executionContext.evaluationPathRemoveLast();
225225
}
226226
schemaIndex++;
227227
}

0 commit comments

Comments
 (0)