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

Include operator details in valid evaluation result #26

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static EvaluationResult empty() {
* @return EvaluationResult the created evaluation result, which is valid by default.
*/
public static EvaluationResult valid(Operator op) {
return new EvaluationResult(true, op.getOperator().getValue(), null, "", Collections.emptyList());
return new EvaluationResult(true, op.getOperator().getValue(), op, "", Collections.emptyList());
}

/**
Expand All @@ -78,19 +78,19 @@ public static EvaluationResult valid(Operator op) {
* @return EvaluationResult the created evaluation result, which is valid by default.
*/
public static EvaluationResult valid(Operator op, List<EvaluationResult> evaluationResults) {
return new EvaluationResult(true, op.getOperator().getValue(), null, "", evaluationResults);
return new EvaluationResult(true, op.getOperator().getValue(), op, "", evaluationResults);
}

/**
* Creates an EvaluationResult instance indicating an error in the evaluation process.
*
* @param rootCause the operator that caused the error.
* @param op the operator that caused the error.
* @param causeDescription the description of the error.
*
* @return EvaluationResult the created evaluation result, which is not valid by default.
*/
public static EvaluationResult withError(Operator rootCause, String causeDescription) {
return new EvaluationResult(false, rootCause.getOperator().getValue(), rootCause, causeDescription, new ArrayList<>());
public static EvaluationResult withError(Operator op, String causeDescription) {
return new EvaluationResult(false, op.getOperator().getValue(), op, causeDescription, new ArrayList<>());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static <T> Operator instantiate(ComparisonOperatorEnum operator, String j
case IN -> new InOperator<>(jsonPath, (List<?>) expectedValue);
case CT -> new ContainsOperator<>(jsonPath, expectedValue);
case NCT -> new NotContainsOperator<>(jsonPath, expectedValue);
default -> null;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.telekom.jsonfilter.operator.OperatorEnum;
import lombok.Getter;

@Getter
public enum ComparisonOperatorEnum implements OperatorEnum {

EQ("equal"),
Expand All @@ -18,10 +19,8 @@ public enum ComparisonOperatorEnum implements OperatorEnum {
GE("greater or equal"),
IN("in"),
CT("contains"),
EX("exists"),
NCT("not contains");

@Getter
private final String value;

ComparisonOperatorEnum(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
import java.util.ArrayList;
import java.util.List;

@Getter
public abstract class LogicOperator implements Operator {
@Getter
final LogicOperatorEnum operator;

@Getter
List<Operator> operators = new ArrayList<>();

protected LogicOperator(LogicOperatorEnum operator) {
Expand All @@ -34,7 +32,6 @@ public static Operator instantiate(LogicOperatorEnum operator, List<Operator> op
return switch (operator) {
case AND -> new AndOperator(operatorList);
case OR -> new OrOperator(operatorList);
default -> null;
};
}
}
Loading