Skip to content

Commit

Permalink
replace own custom conditions with conditions4j
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-toepfer committed Feb 20, 2024
1 parent c1b9599 commit f8d8528
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 500 deletions.
13 changes: 13 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@
</exclusions>
</dependency>

<dependency>
<groupId>io.github.sebastian-toepfer.common</groupId>
<artifactId>condition4j-api</artifactId>
</dependency>
<dependency>
<groupId>io.github.sebastian-toepfer.common</groupId>
<artifactId>condition4j-core</artifactId>
</dependency>
<dependency>
<groupId>io.github.sebastian-toepfer.common</groupId>
<artifactId>condition4j-json-p</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
*/
package io.github.sebastiantoepfer.jsonschema.core;

import io.github.sebastiantoepfer.common.condition4j.Fulfilable;
import io.github.sebastiantoepfer.jsonschema.Validator;
import io.github.sebastiantoepfer.jsonschema.core.codition.Condition;
import jakarta.json.JsonValue;
import java.util.Objects;

final class DefaultValidator implements Validator {

private final Condition<? super JsonValue> contraint;
private final Fulfilable<? super JsonValue> contraint;

public DefaultValidator(final Condition<? super JsonValue> contraint) {
public DefaultValidator(final Fulfilable<? super JsonValue> contraint) {
this.contraint = Objects.requireNonNull(contraint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*/
package io.github.sebastiantoepfer.jsonschema.core;

import io.github.sebastiantoepfer.common.condition4j.core.NoCondition;
import io.github.sebastiantoepfer.ddd.common.Media;
import io.github.sebastiantoepfer.jsonschema.JsonSubSchema;
import io.github.sebastiantoepfer.jsonschema.Validator;
import io.github.sebastiantoepfer.jsonschema.core.codition.NoCondition;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.JsonValue;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*/
package io.github.sebastiantoepfer.jsonschema.core;

import io.github.sebastiantoepfer.common.condition4j.core.UnfulfillableCondition;
import io.github.sebastiantoepfer.ddd.common.Media;
import io.github.sebastiantoepfer.jsonschema.JsonSubSchema;
import io.github.sebastiantoepfer.jsonschema.Validator;
import io.github.sebastiantoepfer.jsonschema.core.codition.UnfulfillableCondition;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.JsonValue;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;

import io.github.sebastiantoepfer.common.condition4j.Fulfilable;
import io.github.sebastiantoepfer.common.condition4j.core.AllOf;
import io.github.sebastiantoepfer.common.condition4j.core.PredicateCondition;
import io.github.sebastiantoepfer.jsonschema.Validator;
import io.github.sebastiantoepfer.jsonschema.core.codition.AllOfCondition;
import io.github.sebastiantoepfer.jsonschema.core.codition.ApplicatorBasedCondtion;
import io.github.sebastiantoepfer.jsonschema.core.codition.AssertionBasedCondition;
import io.github.sebastiantoepfer.jsonschema.core.codition.Condition;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.JsonValue;
import java.util.Collection;
Expand All @@ -46,22 +45,20 @@ public KeywordBasedValidator(final Collection<Keyword> keywords) {
.stream()
.map(KeywordBasedValidator::asContraint)
.flatMap(Optional::stream)
.collect(
collectingAndThen(toList(), constraints -> new DefaultValidator(new AllOfCondition<>(constraints)))
);
.collect(collectingAndThen(toList(), constraints -> new DefaultValidator(new AllOf<>(constraints))));
}

@Override
public boolean isValid(final JsonValue data) {
return validator.isValid(data);
}

private static Optional<Condition<JsonValue>> asContraint(final Keyword keyword) {
final Condition<JsonValue> result;
private static Optional<Fulfilable<JsonValue>> asContraint(final Keyword keyword) {
final Fulfilable<JsonValue> result;
if (keyword.hasCategory(Keyword.KeywordCategory.ASSERTION)) {
result = new AssertionBasedCondition(keyword.asAssertion());
result = new PredicateCondition<>(json -> keyword.asAssertion().isValidFor(json));
} else if (keyword.hasCategory(Keyword.KeywordCategory.APPLICATOR)) {
result = new ApplicatorBasedCondtion(keyword.asApplicator());
result = new PredicateCondition<>(json -> keyword.asApplicator().applyTo(json));
} else {
result = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*/
package io.github.sebastiantoepfer.jsonschema.core;

import io.github.sebastiantoepfer.common.condition4j.core.NoCondition;
import io.github.sebastiantoepfer.ddd.common.Media;
import io.github.sebastiantoepfer.jsonschema.JsonSubSchema;
import io.github.sebastiantoepfer.jsonschema.Validator;
import io.github.sebastiantoepfer.jsonschema.core.codition.NoCondition;
import io.github.sebastiantoepfer.jsonschema.keyword.Keyword;
import jakarta.json.JsonValue;
import java.util.Optional;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f8d8528

Please sign in to comment.