-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
240 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/riot-core/src/main/java/com/redis/riot/core/Expression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.redis.riot.core; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import org.springframework.expression.EvaluationContext; | ||
import org.springframework.expression.common.TemplateParserContext; | ||
import org.springframework.expression.spel.standard.SpelExpressionParser; | ||
|
||
public class Expression { | ||
|
||
protected static final SpelExpressionParser PARSER = new SpelExpressionParser(); | ||
|
||
protected final org.springframework.expression.Expression spelExpression; | ||
|
||
public Expression(org.springframework.expression.Expression expression) { | ||
this.spelExpression = expression; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return spelExpression.getExpressionString(); | ||
} | ||
|
||
public <T> Predicate<T> predicate(EvaluationContext context) { | ||
return t -> spelExpression.getValue(context, t, Boolean.class); | ||
} | ||
|
||
public Object getValue(EvaluationContext context) { | ||
return spelExpression.getValue(context); | ||
} | ||
|
||
public Object getValue(EvaluationContext context, Object rootObject) { | ||
return spelExpression.getValue(context, rootObject); | ||
} | ||
|
||
public Long getLong(EvaluationContext context, Object rootObject) { | ||
return spelExpression.getValue(context, rootObject, Long.class); | ||
} | ||
|
||
public String getString(EvaluationContext context, Object rootObject) { | ||
return spelExpression.getValue(context, rootObject, String.class); | ||
} | ||
|
||
public static Expression parse(String expression) { | ||
return new Expression(PARSER.parseExpression(expression)); | ||
} | ||
|
||
public static TemplateExpression parseTemplate(String expression) { | ||
return new TemplateExpression(PARSER.parseExpression(expression, new TemplateParserContext())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.