示例#1
0
 private void attemptParse()
 {
     if (formula == "")
     {
         // an empty formula results in an empty rule list with an empty default value
         this.result = new RuleList(new List <Rule>(), "");
     }
     else if (formula[0] != FormulaElement.Symbol.FORMULA_ROOT)
     {
         // a constant results in an empty rule list with the constant as default value
         this.result = new RuleList(new List <Rule>(), formula);
     }
     else
     {
         try {
             RuleList ruleList = new RuleList(new List <Rule>(), "");
             parseRecursively(formula.Substring(1), ruleList);
             this.result = ruleList;
         } catch (FormatException fe) {
             parseException = fe;
         } catch (Exception e) {
             parseException = new FormatException("Unknown exception while parsing", e);
         }
     }
 }
示例#2
0
 private void parseRecursively(String formula, RuleList ruleList)
 {
     if (!formula.StartsWith(FormulaElement.Function.IF))
     {
         // arrived at the default value, resulting in a rule with condition True
         ruleList.DefaultValue = formula;
     }
     else
     {
         // get and check the arguments, parse recursively
         List <String> ifArguments = getArguments(formula);
         if (ifArguments.Count != 3)
         {
             throw new FormatException("The IF call [" + formula + "] doesn't have three arguments.");
         }
         // TODO check first two arguments validity
         ruleList.Rules.Add(new Rule(ifArguments[0], ifArguments[1]));
         parseRecursively(ifArguments[2], ruleList);
     }
 }
示例#3
0
        public override bool Equals(System.Object other)
        {
            if (other == null)
            {
                return(false);
            }

            RuleList otherRL = other as RuleList;

            if (otherRL == null)
            {
                return(false);
            }

            if (otherRL.Rules.Count != this.Rules.Count)
            {
                return(false);
            }

            Rule thisRule, otherRule;

            for (int i = 0; i < rules.Count; i++)
            {
                thisRule  = this.Rules[i];
                otherRule = otherRL.Rules[i];
                if (!thisRule.Condition.Equals(otherRule.Condition) ||
                    !thisRule.Value.Equals(otherRule.Value))
                {
                    return(false);
                }
            }

            if (!this.DefaultValue.Equals(otherRL.DefaultValue))
            {
                return(false);
            }

            return(true);
        }
 public RuleListFormulaComposer(RuleList ruleList)
 {
     this.ruleList = ruleList;
 }