All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nepxion.discovery.plugin.strategy.condition.ExpressionStrategyResolver Maven / Gradle / Ivy

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.plugin.strategy.condition;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import java.util.Map; import org.springframework.expression.ExpressionParser; import org.springframework.expression.TypeComparator; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; public class ExpressionStrategyResolver { private static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser(); public static boolean eval(String expression, String key, Map map, TypeComparator typeComparator) { StandardEvaluationContext context = new StandardEvaluationContext(); context.setTypeComparator(typeComparator); context.setVariable(key, map); return eval(expression, context); } public static boolean eval(String expression, Map> map, TypeComparator typeComparator) { StandardEvaluationContext context = new StandardEvaluationContext(); context.setTypeComparator(typeComparator); for (Map.Entry> entry : map.entrySet()) { context.setVariable(entry.getKey(), entry.getValue()); } return eval(expression, context); } public static boolean eval(String expression, StandardEvaluationContext context) { try { Boolean result = EXPRESSION_PARSER.parseExpression(expression).getValue(context, Boolean.class); return result != null ? result.booleanValue() : false; } catch (Exception e) { return false; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy