package gw.rating /** * Represents an operator used in a mathematical or conditional expression */ enum RateRoutineExecutionOperator { Blank("", null), Plus("+", TC_ADDITION), Minus("-", TC_SUBTRACTION), Multiply("*", TC_MULTIPLICATION), Divide("/", TC_DIVISION), Dot(".", null), AndOperator("and", TC_AND), OrOperator("or", TC_OR), EqualsEquals("==", TC_EQUAL), NotEquals("!=", TC_NOTEQUAL), LessThan("<", TC_LESSTHAN), LessOrEquals("<=", TC_LESSTHANOREQUAL), GreaterThan(">", TC_GREATERTHAN), GreaterOrEquals(">=", TC_GREATERTHANOREQUAL), InOperator("in", TC_IN), NotInOperator("notin", TC_NOTIN) var _symbol : String as readonly Symbol var _opType : CalcStepOperatorType as readonly CalcStepOperatorType private construct(symbolArg : String, opType : CalcStepOperatorType) { _symbol = symbolArg _opType = opType } // fastest way to do this conversion seems to be binary search. static var _sorted = RateRoutineExecutionOperator.AllValues.sortBy(\o -> o.CalcStepOperatorType.Code).toTypedArray() static function of(opTypeCode : String) : RateRoutineExecutionOperator { if (opTypeCode == null) return null var lo = 0 var hi = _sorted.length // last element to check is at (hi - 1) while (lo < hi) { var mid = (lo + hi) >>> 1 var c = opTypeCode.compareTo(_sorted[mid].CalcStepOperatorType.Code) if (c == 0) return _sorted[mid] else if (c < 0) { hi = mid } else { lo = mid + 1 } } return null } }