Skip to content

Commit

Permalink
isConditionTrue(condition, map)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoltauFintel committed Dec 29, 2023
1 parent b6cd790 commit 78c6a27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ allprojects {
apply plugin: 'jacoco'
apply plugin: 'org.owasp.dependencycheck'

version = '3.0.0-a002-SNAPSHOT'
version = '3.0.0-a003-SNAPSHOT'
group = 'org.jxls'

repositories {
Expand Down
13 changes: 7 additions & 6 deletions jxls/src/main/java/org/jxls/expression/ExpressionEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,29 @@ public interface ExpressionEvaluator {
String getExpression();

/**
* Evaluates if getExpression() is true
* Evaluates if getExpression() is true.
* @param context data access
* @return expression result (true or false)
* @throws JxlsException if return value is not a Boolean or null
*/
default boolean isConditionTrue(Context context) {
return isConditionTrue(context.toMap());
return isConditionTrue(getExpression(), context.toMap());
}

/**
* Evaluates if getExpression() is true. Call this method only if you have no Context.
* @param condition -
* @param data -
* @return expression result (true or false)
* @throws JxlsException if return value is not a Boolean or null
*/
default boolean isConditionTrue(Map<String, Object> data) {
Object conditionResult = evaluate(data);
default boolean isConditionTrue(String condition, Map<String, Object> data) {
Object conditionResult = evaluate(condition, data);
if (conditionResult instanceof Boolean b) {
return Boolean.TRUE.equals(b);
} else if (conditionResult == null) {
throw new JxlsException("Result of condition \"" + getExpression() + "\" is null");
throw new JxlsException("Result of condition \"" + condition + "\" is null");
}
throw new JxlsException("Result of condition \"" + getExpression() + "\" is not a Boolean");
throw new JxlsException("Result of condition \"" + condition + "\" is not a Boolean");
}
}

0 comments on commit 78c6a27

Please sign in to comment.