use of org.openforis.idm.model.IntegerRangeAttribute in project collect by openforis.
the class AttributeValueUtils method extractNormalizedValue.
private static Object extractNormalizedValue(NumericRangeAttribute<?, ?> attr) {
NumericRange<?> value = attr.getValue();
RangeAttributeDefinition defn = attr.getDefinition();
List<Unit> units = defn.getUnits();
if (units != null && units.size() > 1) {
Unit unit = attr.getUnit();
Unit defaultUnit = defn.getDefaultUnit();
if (unit != null && defaultUnit != null && unit != defaultUnit) {
Number from = value.getFrom();
Number to = value.getTo();
NumericRange<?> normalizedValue;
if (attr instanceof IntegerRangeAttribute) {
int normalizedFrom = getNormalizedValue(from, unit, defaultUnit).intValue();
int normalizedTo = getNormalizedValue(to, unit, defaultUnit).intValue();
normalizedValue = new IntegerRange(normalizedFrom, normalizedTo, defaultUnit);
} else {
double normalizedFrom = getNormalizedValue(from, unit, defaultUnit).doubleValue();
double normalizedTo = getNormalizedValue(to, unit, defaultUnit).doubleValue();
normalizedValue = new RealRange(normalizedFrom, normalizedTo, defaultUnit);
}
return normalizedValue;
} else {
return value;
}
} else {
return value;
}
}
Aggregations