Skip to content

Commit b8341cd

Browse files
committed
migrating notSchema to visitor model
1 parent f4e17fd commit b8341cd

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

core/src/main/java/org/everit/json/schema/NotSchema.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,8 @@ public Schema getMustNotMatch() {
4545
return mustNotMatch;
4646
}
4747

48-
@Override
49-
public void validate(final Object subject) {
50-
try {
51-
mustNotMatch.validate(subject);
52-
} catch (ValidationException e) {
53-
return;
54-
}
55-
throw failure("subject must not be valid against schema " + mustNotMatch, "not");
48+
@Override void accept(Visitor visitor) {
49+
visitor.visitNotSchema(this);
5650
}
5751

5852
@Override
@@ -69,10 +63,6 @@ public boolean equals(Object o) {
6963
}
7064
}
7165

72-
@Override void accept(Visitor visitor) {
73-
throw new UnsupportedOperationException("not yet implemented");
74-
}
75-
7666
@Override
7767
public int hashCode() {
7868
return Objects.hash(super.hashCode(), mustNotMatch);

core/src/main/java/org/everit/json/schema/ValidatingVisitor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ private static boolean isNull(Object obj) {
6464
failureReporter.failure("false schema always fails", "false");
6565
}
6666

67+
@Override void visitNotSchema(NotSchema notSchema) {
68+
Schema mustNotMatch = notSchema.getMustNotMatch();
69+
ValidationException failure = getFailureOfSchema(mustNotMatch, subject);
70+
if (failure == null) {
71+
failureReporter.failure("subject must not be valid against schema " + mustNotMatch, "not");
72+
}
73+
}
74+
6775
ValidationException getFailureOfSchema(Schema schema, Object input) {
6876
Object origSubject = this.subject;
6977
this.subject = input;

core/src/main/java/org/everit/json/schema/Visitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,7 @@ void visitEnumSchema(EnumSchema enumSchema) {
9999

100100
void visitFalseSchema(FalseSchema falseSchema) {
101101
}
102+
103+
void visitNotSchema(NotSchema notSchema) {
104+
}
102105
}

0 commit comments

Comments
 (0)