Skip to content

Commit 8a9fd70

Browse files
committed
Minor optimizations
1 parent 8927433 commit 8a9fd70

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ public AllOfValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
4242
public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) {
4343
debug(logger, node, rootNode, at);
4444

45-
int size = schemas.size();
4645
Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>();
4746

48-
for (int i = 0; i < size; i++) {
49-
errors.addAll(schemas.get(i).validate(node, rootNode, at));
47+
for (JsonSchema schema : schemas) {
48+
errors.addAll(schema.validate(node, rootNode, at));
5049
}
5150

5251
return Collections.unmodifiableSet(errors);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ public AnyOfValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
4242
public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) {
4343
debug(logger, node, rootNode, at);
4444

45-
int size = schemas.size();
4645
Set<ValidationMessage> allErrors = new LinkedHashSet<ValidationMessage>();
4746

48-
for (int i = 0; i < size; i++) {
49-
Set<ValidationMessage> errors = schemas.get(i).validate(node, rootNode, at);
47+
for (JsonSchema schema : schemas) {
48+
Set<ValidationMessage> errors = schema.validate(node, rootNode, at);
5049
if (errors.isEmpty()) {
5150
return errors;
5251
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
4141

4242
Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>();
4343

44-
for (String key : schemas.keySet()) {
45-
JsonSchema propertySchema = schemas.get(key);
46-
JsonNode propertyNode = node.get(key);
44+
for (Map.Entry<String, JsonSchema> entry : schemas.entrySet()) {
45+
JsonSchema propertySchema = entry.getValue();
46+
JsonNode propertyNode = node.get(entry.getKey());
4747

4848
if (propertyNode != null) {
49-
errors.addAll(propertySchema.validate(propertyNode, rootNode, at + "." + key));
49+
errors.addAll(propertySchema.validate(propertyNode, rootNode, at + "." + entry.getKey()));
5050
}
5151
}
5252

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
4444
if (unique) {
4545
Set<JsonNode> set = new HashSet<JsonNode>();
4646
for (JsonNode n : node) {
47-
set.add(n);
48-
}
49-
50-
if (set.size() < node.size()) {
51-
return Collections.singleton(buildValidationMessage(at));
47+
if (!set.add(n)) {
48+
return Collections.singleton(buildValidationMessage(at));
49+
}
5250
}
5351
}
5452

0 commit comments

Comments
 (0)