/** * Evaluates this holder. If this holds an explicit float then its value is returned as-is. * Otherwise, the given {@link ProcessingContext} is used to look up the value of the variable * that this type refers to. The result will either be an {@link FloatValue} or {@link NullValue} * <p> * If the variable cannot be successfully resolved or is of the wrong type then a runtime error * is recorded and a {@link NullValue} will be returned. */ public Value evaluate(final Expression expression, final ProcessingContext context) { if (isConstantFloat()) { return constantFloatValue; } else { final Value result = context.evaluateVariableValue(variableReferenceValue, VariableType.TEMPLATE, VariableType.OUTCOME); if (result.hasSignature(Signature.SINGLE_FLOAT)) { return result; } else { context.fireRuntimeError(expression, "Variable referenced by " + variableReferenceValue + " was expected to be a single float - returning NULL"); return NullValue.INSTANCE; } } }
@Override protected void validateThis(final ValidationContext context) { super.validateThis(context); final FloatOrVariableRef maxComputer = getMax(); final FloatOrVariableRef minComputer = getMin(); if (maxComputer.isConstantFloat() && minComputer.isConstantFloat()) { final double max = maxComputer.getConstantFloatValue().doubleValue(); final double min = minComputer.getConstantFloatValue().doubleValue(); if (max < min) { context.fireAttributeValidationError(getAttributes().get(ATTR_MAX_NAME), "Attribute " + ATTR_MAX_NAME + " (" + max + ") cannot be lower than " + ATTR_MIN_NAME + " (" + min + ")"); } } }
@Override protected void validateThis(final ValidationContext context) { super.validateThis(context); final Attribute<?> tolerancesAttr = getAttributes().get(ATTR_TOLERANCES_NAME); final List<FloatOrVariableRef> tolerances = getTolerances(); if (tolerances!=null && (tolerances.size()==0 || tolerances.size()>2)) { context.fireAttributeValidationError(tolerancesAttr, "Attribute " + ATTR_TOLERANCES_NAME + " must contain 1 or 2 floatOrVariableRefs when specified"); } final FloatOrVariableRef firstToleranceComputer = getFirstTolerance(); if (firstToleranceComputer!=null && firstToleranceComputer.isConstantFloat()) { final double firstToleranceValue = firstToleranceComputer.getConstantFloatValue().doubleValue(); if (firstToleranceValue <= 0) { context.fireAttributeValidationError(tolerancesAttr, "Attribute " + ATTR_TOLERANCES_NAME + " (" + firstToleranceValue + ") must be positive"); } } final FloatOrVariableRef secondToleranceComputer = getSecondTolerance(); if (secondToleranceComputer!=null && secondToleranceComputer.isConstantFloat()) { final double secondToleranceValue = secondToleranceComputer.getConstantFloatValue().doubleValue(); if (secondToleranceValue < 0) { context.fireAttributeValidationError(tolerancesAttr, "Attribute " + ATTR_TOLERANCES_NAME + " (" + getSecondTolerance() + ") must be positive if specified"); } } if (getToleranceMode() != null && getToleranceMode() != ToleranceMode.EXACT && tolerances==null) { context.fireAttributeValidationError(tolerancesAttr, "Attribute " + ATTR_TOLERANCES_NAME + " must be specified when toleranceMode is absolute or relative"); } }