use of org.apache.sis.measure.NumberRange in project sis by apache.
the class Parameters method getValueDomain.
/**
* Returns the domain of valid values defined by the given descriptor, or {@code null} if none.
* This method performs the following operations:
*
* <ul>
* <li>If the given parameter is an instance of {@code DefaultParameterDescriptor},
* delegate to {@link DefaultParameterDescriptor#getValueDomain()}.</li>
* <li>Otherwise builds the range from the {@linkplain DefaultParameterDescriptor#getMinimumValue() minimum value},
* {@linkplain DefaultParameterDescriptor#getMaximumValue() maximum value} and, if the values are numeric, from
* the {@linkplain DefaultParameterDescriptor#getUnit() unit}.</li>
* </ul>
*
* @param descriptor the parameter descriptor, or {@code null}.
* @return the domain of valid values, or {@code null} if none.
*
* @see DefaultParameterDescriptor#getValueDomain()
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Range<?> getValueDomain(final ParameterDescriptor<?> descriptor) {
if (descriptor != null) {
if (descriptor instanceof DefaultParameterDescriptor<?>) {
return ((DefaultParameterDescriptor<?>) descriptor).getValueDomain();
}
final Class<?> valueClass = descriptor.getValueClass();
final Comparable<?> minimumValue = descriptor.getMinimumValue();
final Comparable<?> maximumValue = descriptor.getMaximumValue();
if ((minimumValue == null || valueClass.isInstance(minimumValue)) && (maximumValue == null || valueClass.isInstance(maximumValue))) {
if (Number.class.isAssignableFrom(valueClass)) {
final Unit<?> unit = descriptor.getUnit();
if (unit != null) {
return new MeasurementRange((Class) valueClass, (Number) minimumValue, true, (Number) maximumValue, true, unit);
} else if (minimumValue != null || maximumValue != null) {
return new NumberRange((Class) valueClass, (Number) minimumValue, true, (Number) maximumValue, true);
}
} else if (minimumValue != null || maximumValue != null) {
return new Range(valueClass, minimumValue, true, maximumValue, true);
}
}
}
return null;
}
use of org.apache.sis.measure.NumberRange in project sis by apache.
the class SpecialCasesTest method testPropertyInformation.
/**
* Tests {@link SpecialCases#information(int)}.
*/
@Test
public void testPropertyInformation() {
final ExtendedElementInformation info = accessor.information(accessor.indexOf("westBoundLongitude", true));
final InternationalString domain = info.getDomainValue();
assertInstanceOf("Expected numerical information about range.", NumberRange.class, domain);
final NumberRange<?> range = (NumberRange) domain;
assertEquals(-180, range.getMinDouble(), STRICT);
assertEquals(+180, range.getMaxDouble(), STRICT);
}
Aggregations