Search in sources :

Example 1 with NumberRange

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;
}
Also used : NumberRange(org.apache.sis.measure.NumberRange) MeasurementRange(org.apache.sis.measure.MeasurementRange) NumberRange(org.apache.sis.measure.NumberRange) Range(org.apache.sis.measure.Range) MeasurementRange(org.apache.sis.measure.MeasurementRange)

Example 2 with NumberRange

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);
}
Also used : NumberRange(org.apache.sis.measure.NumberRange) ExtendedElementInformation(org.opengis.metadata.ExtendedElementInformation) InternationalString(org.opengis.util.InternationalString) Test(org.junit.Test)

Aggregations

NumberRange (org.apache.sis.measure.NumberRange)2 MeasurementRange (org.apache.sis.measure.MeasurementRange)1 Range (org.apache.sis.measure.Range)1 Test (org.junit.Test)1 ExtendedElementInformation (org.opengis.metadata.ExtendedElementInformation)1 InternationalString (org.opengis.util.InternationalString)1