Search in sources :

Example 1 with RealRange

use of org.openforis.idm.model.RealRange in project collect by openforis.

the class RealRangeValidator method evaluate.

@Override
public ValidationResultFlag evaluate(RealRangeAttribute node) {
    RealRange range = node.getValue();
    if (range != null) {
        Double from = range.getFrom();
        Double to = range.getTo();
        if (!(from == null || to == null)) {
            boolean valid = to >= from;
            return ValidationResultFlag.valueOf(valid);
        }
    }
    return ValidationResultFlag.OK;
}
Also used : RealRange(org.openforis.idm.model.RealRange)

Example 2 with RealRange

use of org.openforis.idm.model.RealRange in project collect by openforis.

the class JSONValueParser method parseRealRange.

public RealRange parseRealRange(RangeAttributeDefinition attrDef, String value) {
    Map<String, Object> map = parseJSONToMap(value);
    if (map == null) {
        return null;
    }
    Double from = getDouble(map, RealRange.FROM_FIELD);
    Double to = getDouble(map, RealRange.TO_FIELD);
    if (to == null) {
        to = from;
    }
    Integer unitId = getInteger(map, RealRange.UNIT_ID_FIELD);
    Unit unit = attrDef.getActualUnit(unitId);
    return new RealRange(from, to, unit);
}
Also used : RealRange(org.openforis.idm.model.RealRange) Unit(org.openforis.idm.metamodel.Unit)

Example 3 with RealRange

use of org.openforis.idm.model.RealRange in project collect by openforis.

the class ComparisonExpressionTest method testGtLtWrongOnRange.

@Test
public void testGtLtWrongOnRange() throws InvalidExpressionException {
    monthlyConsumption.setValue(new RealRange(0.0, 15.0));
    monthlyConsumption.updateSummaryInfo();
    Assert.assertFalse(evaluateExpression(energySource, "monthly_consumption > 10 and monthly_consumption < 14.5"));
}
Also used : RealRange(org.openforis.idm.model.RealRange) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 4 with RealRange

use of org.openforis.idm.model.RealRange in project collect by openforis.

the class ComparisonExpressionTest method testGtLtOnRange.

@Test
public void testGtLtOnRange() throws InvalidExpressionException {
    monthlyConsumption.setValue(new RealRange(11.0, 13.0));
    monthlyConsumption.updateSummaryInfo();
    Assert.assertTrue(evaluateExpression(energySource, "monthly_consumption > 10 and monthly_consumption < 14.5"));
}
Also used : RealRange(org.openforis.idm.model.RealRange) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 5 with RealRange

use of org.openforis.idm.model.RealRange in project collect by openforis.

the class ComparisonExpressionTest method testGteqLtOnRange.

@Test
public void testGteqLtOnRange() throws InvalidExpressionException {
    monthlyConsumption.setValue(new RealRange(10.1, 13.0));
    monthlyConsumption.updateSummaryInfo();
    Assert.assertTrue(evaluateExpression(energySource, "monthly_consumption >= 10.1 and monthly_consumption < 14.5"));
}
Also used : RealRange(org.openforis.idm.model.RealRange) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Aggregations

RealRange (org.openforis.idm.model.RealRange)6 Test (org.junit.Test)3 AbstractTest (org.openforis.idm.AbstractTest)3 Unit (org.openforis.idm.metamodel.Unit)2 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)1 IntegerRange (org.openforis.idm.model.IntegerRange)1 IntegerRangeAttribute (org.openforis.idm.model.IntegerRangeAttribute)1