ExpressionUtil { static public FieldValue evaluateNormDiscrete(NormDiscrete normDiscrete, EvaluationContext context){ FieldValue value = context.evaluate(ensureField(normDiscrete)); if(FieldValueUtil.isMissing(value)){ return FieldValueUtil.create(TypeInfos.CATEGORICAL_DOUBLE, normDiscrete.getMapMissingTo()); } NormDiscrete.Method method = normDiscrete.getMethod(); switch(method){ case INDICATOR: { boolean equals = value.equals(normDiscrete); return (equals ? FieldValues.CATEGORICAL_DOUBLE_ONE : FieldValues.CATEGORICAL_DOUBLE_ZERO); } default: throw new UnsupportedAttributeException(normDiscrete, method); } } private  ExpressionUtil(); static FieldName ensureField(E hasField); static Expression ensureExpression(E hasExpression); static FieldValue evaluateExpressionContainer(E hasExpression, EvaluationContext context); static FieldValue evaluateTypedExpressionContainer(E hasTypedExpression, EvaluationContext context); static FieldValue evaluate(DerivedField derivedField, EvaluationContext context); static FieldValue evaluate(DefineFunction defineFunction, List<FieldValue> values, EvaluationContext context); static FieldValue evaluate(Expression expression, EvaluationContext context); static FieldValue evaluateConstant(Constant constant); static FieldValue evaluateFieldRef(FieldRef fieldRef, EvaluationContext context); static FieldValue evaluateNormContinuous(NormContinuous normContinuous, EvaluationContext context); static FieldValue evaluateNormDiscrete(NormDiscrete normDiscrete, EvaluationContext context); static FieldValue evaluateDiscretize(Discretize discretize, EvaluationContext context); static FieldValue evaluateMapValues(MapValues mapValues, EvaluationContext context); static FieldValue evaluateTextIndex(TextIndex textIndex, EvaluationContext context); static FieldValue evaluateApply(Apply apply, EvaluationContext context); @SuppressWarnings ( value = {"unchecked"} ) static FieldValue evaluateAggregate(Aggregate aggregate, EvaluationContext context); static FieldValue evaluateJavaExpression(JavaExpression javaExpression, EvaluationContext context); static boolean isEmptyContent(Object value);  }
@Test public void evaluateNormDiscrete(){ FieldName name = FieldName.create("x"); Double equals = 1d; Double notEquals = 0d; NormDiscrete stringThree = new NormDiscrete(name, "3"); assertEquals(equals, evaluate(stringThree, name, "3")); assertEquals(notEquals, evaluate(stringThree, name, "1")); stringThree.setMapMissingTo(5d); assertEquals(5d, evaluate(stringThree, name, null)); NormDiscrete integerThree = new NormDiscrete(name, "3"); assertEquals(equals, evaluate(integerThree, name, 3)); assertEquals(notEquals, evaluate(integerThree, name, 1)); NormDiscrete floatThree = new NormDiscrete(name, "3.0"); assertEquals(equals, evaluate(floatThree, name, 3f)); assertEquals(notEquals, evaluate(floatThree, name, 1f)); }