Search in sources :

Example 1 with ExtendedElementInformation

use of org.opengis.metadata.ExtendedElementInformation 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)

Example 2 with ExtendedElementInformation

use of org.opengis.metadata.ExtendedElementInformation in project sis by apache.

the class PropertyInformationTest method testGetDomainValue.

/**
 * Tests {@link PropertyInformation#getDomainValue()} with a non-null range.
 *
 * @throws NoSuchMethodException if the {@code getMaxRelativeHumidity()} or other method has not been found.
 */
@Test
@SuppressWarnings("UnnecessaryBoxing")
public void testGetDomainValue() throws NoSuchMethodException {
    final ExtendedElementInformation information = new PropertyInformation<>(HardCodedCitations.ISO_19115, "maxRelativeHumidity", EnvironmentalRecord.class.getMethod("getMaxRelativeHumidity"), Double.class, DefaultEnvironmentalRecord.class.getMethod("getMaxRelativeHumidity").getAnnotation(ValueRange.class));
    final InternationalString domainValue = information.getDomainValue();
    assertNotNull(domainValue);
    assertEquals("[0.0 … 100.0]", domainValue.toString());
    assertEquals("[0 … 100]", domainValue.toString(Locale.ENGLISH));
    assertEquals("[0 … 100]", domainValue.toString(Locale.FRENCH));
    assertInstanceOf("Specific to SIS implementation.", Range.class, domainValue);
    assertEquals("getMinValue()", Double.valueOf(0), ((Range) domainValue).getMinValue());
    assertEquals("getMaxValue()", Double.valueOf(100), ((Range) domainValue).getMaxValue());
}
Also used : ValueRange(org.apache.sis.measure.ValueRange) ExtendedElementInformation(org.opengis.metadata.ExtendedElementInformation) InternationalString(org.opengis.util.InternationalString) EnvironmentalRecord(org.opengis.metadata.acquisition.EnvironmentalRecord) DefaultEnvironmentalRecord(org.apache.sis.metadata.iso.acquisition.DefaultEnvironmentalRecord) Test(org.junit.Test)

Example 3 with ExtendedElementInformation

use of org.opengis.metadata.ExtendedElementInformation in project sis by apache.

the class PropertyAccessor method information.

/**
 * Returns the information for the property at the given index.
 * The information are created when first needed.
 *
 * @param  index  the index of the property for which to get the information.
 * @return the information for the property at the given index, or {@code null} if the index is out of bounds.
 *
 * @see PropertyInformation
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
final synchronized ExtendedElementInformation information(final int index) {
    ExtendedElementInformation[] informations = this.informations;
    if (informations == null) {
        this.informations = informations = new PropertyInformation<?>[standardCount];
    }
    if (index < 0 || index >= informations.length) {
        return null;
    }
    ExtendedElementInformation information = informations[index];
    if (information == null) {
        final Class<?> elementType = elementTypes[index];
        final String name = name(index, KeyNamePolicy.UML_IDENTIFIER);
        final Method getter = getters[index];
        final ValueRange range;
        try {
            range = implementation.getMethod(getter.getName(), (Class<?>[]) null).getAnnotation(ValueRange.class);
        } catch (NoSuchMethodException error) {
            /*
                 * Should never happen, since the implementation class
                 * implements the interface where the getter come from.
                 */
            throw new AssertionError(error);
        }
        information = new PropertyInformation<>(standard, name, getter, elementType, range);
        informations[index] = information;
    }
    return information;
}
Also used : ValueRange(org.apache.sis.measure.ValueRange) ExtendedElementInformation(org.opengis.metadata.ExtendedElementInformation) Method(java.lang.reflect.Method)

Aggregations

ExtendedElementInformation (org.opengis.metadata.ExtendedElementInformation)3 ValueRange (org.apache.sis.measure.ValueRange)2 Test (org.junit.Test)2 InternationalString (org.opengis.util.InternationalString)2 Method (java.lang.reflect.Method)1 NumberRange (org.apache.sis.measure.NumberRange)1 DefaultEnvironmentalRecord (org.apache.sis.metadata.iso.acquisition.DefaultEnvironmentalRecord)1 EnvironmentalRecord (org.opengis.metadata.acquisition.EnvironmentalRecord)1