Class Rules


  • public class Rules
    extends java.lang.Object
    Create rules and a rule engine
    • Constructor Detail

      • Rules

        public Rules()
    • 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 - key
        value - 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 expression
        keyRegex - true if the key is a regular expression key match, false for an equals match
        value - value value string
        valueRegex - 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 condition
        key - key
        value - value
        Returns:
        rule
      • conditionsRule

        public static Rule conditionsRule​(Condition condition,
                                          StateObj result)
        Create a rule: predicate(conditions) => new state(results)
        Parameters:
        condition - single condition
        result - 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 - conditions
        key - key
        value - 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 - conditions
        results - 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 - conditions
        results - 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 engine
        state - 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 engine
        state - state
        readableState - optional additional state
        Returns:
      • ruleApplies

        public static java.util.function.Predicate<? super Rule> ruleApplies​(StateObj state)
      • 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