Package com.dtolabs.rundeck.core.rules
Class Rules
- java.lang.Object
-
- com.dtolabs.rundeck.core.rules.Rules
-
public class Rules extends java.lang.ObjectCreate rules and a rule engine
-
-
Constructor Summary
Constructors Constructor Description Rules()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanapplyConditions(StateObj state, java.util.Set<Condition> runConditions, boolean operationAnd)static java.util.function.Function<? super Rule,java.util.Optional<StateObj>>applyRule(StateObj state)static java.util.Set<Condition>conditionSet(Condition... condition)static RuleconditionsRule(Condition condition, StateObj result)Create a rule: predicate(conditions) => new state(results)static RuleconditionsRule(Condition condition, java.lang.String key, java.lang.String value)Create a rule: predicate(conditions) => new state(results)static RuleconditionsRule(java.util.Set<Condition> conditions, StateObj results)Create a rule: predicate(conditions) => new state(results)static RuleconditionsRule(java.util.Set<Condition> conditions, java.lang.String key, java.lang.String value)Create a rule: predicate(conditions) => new state(results)static RuleconditionsRule(java.util.Set<Condition> conditions, java.util.Map<java.lang.String,java.lang.String> results)Create a rule: predicate(conditions) => new state(results)static RuleEnginecreateEngine()static RuleEnginecreateEngine(java.util.Set<Rule> ruleset)static ConditioneqCondition(java.lang.String key, java.lang.String value)Compare two numeric values.static ConditionequalsCondition(StateObj state)Create a condition when the given state is setstatic ConditionequalsCondition(java.lang.String key, java.lang.String value)Create a single state key equals value conditionstatic ConditiongtCondition(java.lang.String key, java.lang.String value)Compare two numeric values.static ConditionltCondition(java.lang.String key, java.lang.String value)Compare two numeric values.static ConditionmatchesCondition(java.lang.String key, boolean keyRegex, java.lang.String value, boolean valueRegex)Create a single match conditionstatic java.util.function.Predicate<? super Rule>ruleApplies(StateObj state)static booleanupdate(RuleEngine ruleEngine, MutableStateObj state)Update the state by evaluating the rules, and applying state changesstatic booleanupdate(RuleEngine ruleEngine, MutableStateObj state, StateObj readableState)Update the state by evaluating the rules, and applying state changes
-
-
-
Method Detail
-
createEngine
public static RuleEngine createEngine(java.util.Set<Rule> ruleset)
- Parameters:
ruleset- initial rules- Returns:
- new rule engine with the rules
-
createEngine
public static RuleEngine createEngine()
- Returns:
- new rule engine with no rules
-
equalsCondition
public static Condition equalsCondition(java.lang.String key, java.lang.String value)
Create a single state key equals value condition- Parameters:
key- keyvalue- value- Returns:
- new condition
-
equalsCondition
public static Condition equalsCondition(StateObj state)
Create a condition when the given state is set- Parameters:
state- state- Returns:
- new condition
-
conditionSet
public static java.util.Set<Condition> conditionSet(Condition... condition)
- Parameters:
condition-- Returns:
-
matchesCondition
public static Condition matchesCondition(java.lang.String key, boolean keyRegex, java.lang.String value, boolean valueRegex)
Create a single match condition- Parameters:
key- key name or regular expressionkeyRegex- true if the key is a regular expression key match, false for an equals matchvalue- value value stringvalueRegex- true if the value is a regular expression match, false for an equals match- Returns:
- new condition
-
conditionsRule
public static Rule conditionsRule(Condition condition, java.lang.String key, java.lang.String value)
Create a rule: predicate(conditions) => new state(results)- Parameters:
condition- single conditionkey- keyvalue- value- Returns:
- rule
-
conditionsRule
public static Rule conditionsRule(Condition condition, StateObj result)
Create a rule: predicate(conditions) => new state(results)- Parameters:
condition- single conditionresult- result- Returns:
- rule
-
conditionsRule
public static Rule conditionsRule(java.util.Set<Condition> conditions, java.lang.String key, java.lang.String value)
Create a rule: predicate(conditions) => new state(results)- Parameters:
conditions- conditionskey- keyvalue- value- Returns:
- rule
-
conditionsRule
public static Rule conditionsRule(java.util.Set<Condition> conditions, java.util.Map<java.lang.String,java.lang.String> results)
Create a rule: predicate(conditions) => new state(results)- Parameters:
conditions- conditionsresults- results- Returns:
- rule
-
conditionsRule
public static Rule conditionsRule(java.util.Set<Condition> conditions, StateObj results)
Create a rule: predicate(conditions) => new state(results)- Parameters:
conditions- conditionsresults- results- Returns:
- rule
-
applyConditions
public static boolean applyConditions(StateObj state, java.util.Set<Condition> runConditions, boolean operationAnd)
-
update
public static boolean update(RuleEngine ruleEngine, MutableStateObj state)
Update the state by evaluating the rules, and applying state changes- Parameters:
ruleEngine- rule enginestate- state- Returns:
- true if state was modified, false if no state change occured
-
update
public static boolean update(RuleEngine ruleEngine, MutableStateObj state, StateObj readableState)
Update the state by evaluating the rules, and applying state changes- Parameters:
ruleEngine- rule enginestate- statereadableState- optional additional state- Returns:
-
applyRule
public static java.util.function.Function<? super Rule,java.util.Optional<StateObj>> applyRule(StateObj state)
-
ltCondition
public static Condition ltCondition(java.lang.String key, java.lang.String value)
Compare two numeric values. If the value is'nt a valid float number, it will default to zero.- Parameters:
key-value-- Returns:
- new Condition
-
gtCondition
public static Condition gtCondition(java.lang.String key, java.lang.String value)
Compare two numeric values. If the value is'nt a valid float number, it will default to zero.- Parameters:
key-value-- Returns:
- new Condition
-
eqCondition
public static Condition eqCondition(java.lang.String key, java.lang.String value)
Compare two numeric values. If the value is'nt a valid float number, it will default to zero.- Parameters:
key-value-- Returns:
- new Condition
-
-