Search in sources :

Example 1 with VisibleForTesting

use of org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting in project incubator-ratis by apache.

the class Assign method createExpression.

@VisibleForTesting
Expression createExpression(String val) {
    if (NUMBER_PATTERN.matcher(val).matches()) {
        return new DoubleValue(Double.parseDouble(val));
    } else if (Variable.PATTERN.matcher(val).matches()) {
        return new Variable(val);
    }
    Matcher binaryMatcher = BINARY_OPERATION_PATTERN.matcher(val);
    Matcher unaryMatcher = UNARY_OPERATION_PATTERN.matcher(val);
    if (binaryMatcher.matches()) {
        return createBinaryExpression(binaryMatcher);
    } else if (unaryMatcher.matches()) {
        return createUnaryExpression(unaryMatcher);
    } else {
        throw new IllegalArgumentException("Invalid expression " + val + " Try something like: 'a+b' or '2'");
    }
}
Also used : Variable(org.apache.ratis.examples.arithmetic.expression.Variable) DoubleValue(org.apache.ratis.examples.arithmetic.expression.DoubleValue) Matcher(java.util.regex.Matcher) VisibleForTesting(org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting)

Aggregations

Matcher (java.util.regex.Matcher)1 DoubleValue (org.apache.ratis.examples.arithmetic.expression.DoubleValue)1 Variable (org.apache.ratis.examples.arithmetic.expression.Variable)1 VisibleForTesting (org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting)1