TargetUtil { static public <V extends Number> Value<V> processValue(Target target, Value<V> value){ Number min = target.getMin(); Number max = target.getMax(); if(min != null || max != null){ value.restrict((min != null ? min : Double.NEGATIVE_INFINITY), (max != null ? max : Double.POSITIVE_INFINITY)); } value .multiply(target.getRescaleFactor()) .add(target.getRescaleConstant()); Target.CastInteger castInteger = target.getCastInteger(); if(castInteger == null){ return value; } switch(castInteger){ case ROUND: return value.round(); case CEILING: return value.ceiling(); case FLOOR: return value.floor(); default: throw new UnsupportedAttributeException(target, castInteger); } } private  TargetUtil(); static void computeResult(DataType dataType, Regression<?> regression); static void computeResult(DataType dataType, Classification<?, ?> classification); static void computeResult(DataType dataType, Vote vote); static Map<FieldName, ?> evaluateRegressionDefault(ValueFactory<V> valueFactory, TargetField targetField); static Map<FieldName, ?> evaluateRegression(TargetField targetField, Value<V> value); static Map<FieldName, ? extends Regression<V>> evaluateRegression(TargetField targetField, Regression<V> regression); static Value<V> evaluateRegressionInternal(TargetField targetField, Value<V> value); static Map<FieldName, ? extends Vote> evaluateVote(TargetField targetField, Vote vote); static Map<FieldName, ? extends Classification<?, V>> evaluateClassificationDefault(ValueFactory<V> valueFactory, TargetField targetField); static Map<FieldName, ? extends Classification<?, V>> evaluateClassification(TargetField targetField, Classification<?, V> classification); static Value<V> processValue(Target target, Value<V> value); static TargetValue getTargetValue(Target target, Object value);  }
@Test public void processValue(){ Target target = new Target() .setField(FieldName.create("amount")) .setRescaleFactor(3.14d) .setRescaleConstant(10d); FloatValue floatValue = new FloatValue((8f * 3.14f) + 10f); DoubleValue doubleValue = new DoubleValue((8d * 3.14d) + 10d); assertTrue(floatValue.floatValue() != doubleValue.floatValue()); assertTrue(floatValue.doubleValue() != doubleValue.doubleValue()); assertEquals(floatValue, TargetUtil.processValue(target, new FloatValue(8f))); assertEquals(doubleValue, TargetUtil.processValue(target, new DoubleValue(8d))); target.setCastInteger(Target.CastInteger.ROUND) .setMin(-10d) .setMax(10.5d); assertEquals(new FloatValue(35f), TargetUtil.processValue(target, new FloatValue(8f))); assertEquals(new DoubleValue(35d), TargetUtil.processValue(target, new DoubleValue(8d))); assertEquals(new FloatValue(43f), TargetUtil.processValue(target, new FloatValue(12.97f))); assertEquals(new DoubleValue(43d), TargetUtil.processValue(target, new DoubleValue(12.97d))); }