Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace own custom conditions with conditions4j #107

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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