/** * Returns the parameter in this group for the specified name. The name can be a matrix element * if it uses the following syntax: <code>"elt_<var>row</var>_<var>col</var>"</code> where * {@code "elt_"} is the {@linkplain #prefix} for all matrix elements, and <var>row</var> and * <var>col</var> are row and column indices respectively. For example {@code "elt_2_1"} is the * element name for the value at line 2 and row 1. The row and column index are 0 based. * * @param name The case insensitive name of the parameter to search for. * @return The parameter for the given name. * @throws ParameterNotFoundException if there is no parameter for the given name. */ @Override @SuppressWarnings("unchecked") public final GeneralParameterDescriptor descriptor(final String name) throws ParameterNotFoundException { return descriptor( name, ((Number) numRow.getMaximumValue()).intValue(), ((Number) numCol.getMaximumValue()).intValue()); }
/** * Returns the parameter in this group for a matrix element at the specified index. row and * column indices are 0 based. Indices must be lower that the {@linkplain * ParameterDescriptor#getMaximumValue maximum values} given to the {@link #numRow} and {@link * #numCol} parameters. * * @param row The row indice. * @param column The column indice * @return The parameter descriptor for the specified matrix element. * @throws IndexOutOfBoundsException if {@code row} or {@code column} is out of bounds. */ @SuppressWarnings("unchecked") public final ParameterDescriptor<Double> descriptor(final int row, final int column) throws IndexOutOfBoundsException { return descriptor( row, column, ((Number) numRow.getMaximumValue()).intValue(), ((Number) numCol.getMaximumValue()).intValue()); }
/** * Called on a single {@linkplain ParameterValue parameter value}, or on elements of a parameter * value. This method ensures that {@linkplain ParameterDescriptor#getMinimumValue minimum * value}, {@linkplain ParameterDescriptor#getMaximumValue maximum value} and {@linkplain * ParameterDescriptor#getValidValues valid values} all think the provided value is okay. * * @param value The value to test. * @param descriptor The descriptor for the value. * @return true if parameter is valid. * @see Parameter#ensureValidValue */ private static boolean isValidValue( final Object value, final ParameterDescriptor<?> descriptor) { final Set<?> validValues = descriptor.getValidValues(); if (validValues != null && !validValues.contains(value)) { return false; } @SuppressWarnings("unchecked") // Type has been verified by the caller. final Comparable<Object> min = (Comparable) descriptor.getMinimumValue(); if (min != null && min.compareTo(value) > 0) { return false; } @SuppressWarnings("unchecked") final Comparable<Object> max = (Comparable) descriptor.getMaximumValue(); if (max != null && max.compareTo(value) < 0) { return false; } return true; }
/** * Constructs a descriptor with the same values than the specified one. This copy constructor * may be used in order to wraps an arbitrary implementation into a Geotools one. * * @param descriptor The descriptor to copy. * @since 2.2 */ public DefaultParameterDescriptor(final ParameterDescriptor<T> descriptor) { super(descriptor); valueClass = descriptor.getValueClass(); validValues = descriptor.getValidValues(); defaultValue = descriptor.getDefaultValue(); minimum = descriptor.getMinimumValue(); maximum = descriptor.getMaximumValue(); unit = descriptor.getUnit(); }
return false; c = descriptor.getMaximumValue(); if (c != null && !range.contains(c)) { return false;
final Comparable<Object> minimum = (Comparable) descriptor.getMinimumValue(); @SuppressWarnings("unchecked") final Comparable<Object> maximum = (Comparable) descriptor.getMaximumValue(); if ((minimum != null && minimum.compareTo(value) > 0) || (maximum != null && maximum.compareTo(value) < 0)) {
value = descriptor.getMaximumValue(); if (value != null) { table.write(formatValue(value));
@Override public Comparable<T> getMaximumValue() {return descriptor.getMaximumValue();} @Override public T getDefaultValue() {return descriptor.getDefaultValue();}
/** * Returns {@code true} if the given descriptor is restricted to a constant value. * This constraint exists in some pre-defined map projections. * * <div class="note"><b>Example:</b> * the <cite>"Latitude of natural origin"</cite> parameter of <cite>"Mercator (1SP)"</cite> projection * is provided for completeness, but should never be different than zero in this particular projection * (otherwise it would be a <cite>"Mercator (variant C)"</cite> projection). But if this parameter is * nevertheless provided, the SIS implementation will use it. From this point of view, SIS is tolerant * to non-zero value. * * <p>If the GML document declares explicitely a restricted parameter, maybe it intends to use it with * a non-zero value. Consequently the {@code merge(…)} method will not propagate this restriction.</p> * </div> */ private static boolean isRestricted(final ParameterDescriptor<?> descriptor) { final Comparable<?> min = descriptor.getMinimumValue(); if (min instanceof Number) { final Comparable<?> max = descriptor.getMaximumValue(); if (max instanceof Number) { // Compare as 'double' because we want (-0 == +0) to be true. return ((Number) min).doubleValue() == ((Number) max).doubleValue(); } } return false; }
/** * Returns {@code true} if the given descriptor is restricted to a constant value. * This constraint exists in some pre-defined map projections. * * <div class="note"><b>Example:</b> * the <cite>"Latitude of natural origin"</cite> parameter of <cite>"Mercator (1SP)"</cite> projection * is provided for completeness, but should never be different than zero in this particular projection * (otherwise it would be a <cite>"Mercator (variant C)"</cite> projection). But if this parameter is * nevertheless provided, the SIS implementation will use it. From this point of view, SIS is tolerant * to non-zero value. * * <p>If the GML document declares explicitly a restricted parameter, maybe it intends to use it with * a non-zero value. Consequently the {@code merge(…)} method will not propagate this restriction.</p> * </div> */ private static boolean isRestricted(final ParameterDescriptor<?> descriptor) { final Comparable<?> min = descriptor.getMinimumValue(); if (min instanceof Number) { final Comparable<?> max = descriptor.getMaximumValue(); if (max instanceof Number) { // Compare as 'double' because we want (-0 == +0) to be true. return ((Number) min).doubleValue() == ((Number) max).doubleValue(); } } return false; }
assertEquals("defaultValue", 0, descriptor.getDefaultValue()); assertNull("minimum", descriptor.getMinimumValue()); assertNull("maximum", descriptor.getMaximumValue()); assertNull("unit", descriptor.getUnit()); assertNull("validValues", descriptor.getValidValues()); assertNull("defaultValue", descriptor.getDefaultValue()); assertNull("minimum", descriptor.getMinimumValue()); assertNull("maximum", descriptor.getMaximumValue()); assertNull("validValues", descriptor.getValidValues()); try { assertNull("defaultValue", descriptor.getDefaultValue()); assertNull("minimum", descriptor.getMinimumValue()); assertNull("maximum", descriptor.getMaximumValue()); assertTrue("validValues", validValues.contains(AxisDirection.NORTH)); assertTrue("validValues", validValues.contains(AxisDirection.SOUTH));
assertEquals("Default", 1, ((double[]) param.getDefaultValue()).length); assertNull("Minimum", param.getMinimumValue()); assertNull("Maximum", param.getMaximumValue()); assertNull("Valid values", param.getValidValues()); assertLocalized("Remarks", param.getRemarks());
assertEquals("defaultValue", 12.0, dDescriptor.getDefaultValue().doubleValue(), 0.0); assertEquals("minimum", 4.0, dDescriptor.getMinimumValue()); assertEquals("maximum", 20.0, dDescriptor.getMaximumValue()); assertEquals("value", 12, parameter.intValue()); assertEquals("unit", SI.METRE, parameter.getUnit());
/** * Asserts the the given parameter forces its value to zero. * This test is mostly for {@link Equirectangular#LATITUDE_OF_ORIGIN}. */ private static void assertIsForcedToZero(final ParameterDescriptor<?> parameter) { assertEquals("minimumValue", -0.0, parameter.getMinimumValue()); assertEquals("maximumValue", +0.0, parameter.getMaximumValue()); } }
/** * Tests {@code DefaultParameterDescriptor} construction for {@link Double} type. */ @Test @SuppressWarnings("UnnecessaryBoxing") public void testDoubleType() { final ParameterDescriptor<Double> descriptor = create("Length measure", 4, 20, 12, Units.METRE); assertEquals("name", "Length measure", descriptor.getName().getCode()); assertEquals("unit", Units.METRE, descriptor.getUnit()); assertEquals("class", Double.class, descriptor.getValueClass()); assertEquals("defaultValue", Double.valueOf(12), descriptor.getDefaultValue()); assertEquals("minimum", Double.valueOf( 4), descriptor.getMinimumValue()); assertEquals("maximum", Double.valueOf(20), descriptor.getMaximumValue()); validate(descriptor); }
/** * Tests {@code DefaultParameterDescriptor} constructor * with valid and invalid minimum and maximum values. */ @Test @DependsOnMethod("testOptionalInteger") @SuppressWarnings("UnnecessaryBoxing") public void testRangeValidation() { try { create("Test range", 20, 4, 12); fail("minimum > maximum"); } catch (IllegalArgumentException exception) { assertEquals("Range [20 … 4] is not valid.", exception.getMessage()); } final ParameterDescriptor<Integer> descriptor = create("Test range", 4, 20, 12); assertEquals("name", "Test range", descriptor.getName().getCode()); assertEquals("valueClass", Integer.class, descriptor.getValueClass()); assertNull ("validValues", descriptor.getValidValues()); assertEquals("defaultValue", Integer.valueOf(12), descriptor.getDefaultValue()); assertEquals("minimumValue", Integer.valueOf( 4), descriptor.getMinimumValue()); assertEquals("maximumValue", Integer.valueOf(20), descriptor.getMaximumValue()); assertEquals("minimumOccurs", 1, descriptor.getMinimumOccurs()); assertEquals("maximumOccurs", 1, descriptor.getMaximumOccurs()); }
/** * Same verification than {@link #verifyMethodParameter(ParameterDescriptor, ParameterDescriptor)}, but stricter. * * @param expected a parameter descriptor containing the expected properties (except remarks). * @param remarks the expected remarks, or {@code null} for fetching this information from {@code expected}. * @param actual the parameter descriptor to verify. */ private static void verifyMethodParameter(final ParameterDescriptor<?> expected, final String remarks, final ParameterDescriptor<?> actual) { verifyMethodParameter(expected, actual); assertSame("name", expected.getName(), actual.getName()); assertSame("minimumValue", expected.getMinimumValue(), actual.getMinimumValue()); assertSame("maximumValue", expected.getMaximumValue(), actual.getMaximumValue()); assertSame("defaultValue", expected.getDefaultValue(), actual.getDefaultValue()); if (remarks != null) { assertEquals("remarks", remarks, actual.getRemarks().toString()); } else { assertSame("remarks", expected.getRemarks(), actual.getRemarks()); } } }
/** * Tests a descriptor for a parameter restricted to some values. * This is typically (but not necessarily) a code list parameter. */ @Test public void testEnumeration() { final String[] enumeration = {"Apple", "Orange", "りんご"}; final ParameterDescriptor<String> descriptor = create( "Enumeration param", String.class, enumeration, "Apple"); assertEquals ("name", "Enumeration param", descriptor.getName().getCode()); assertEquals ("valueClass", String.class, descriptor.getValueClass()); assertArrayEquals("validValues", enumeration, descriptor.getValidValues().toArray()); assertEquals ("defaultValue", "Apple", descriptor.getDefaultValue()); assertNull ("minimumValue", descriptor.getMinimumValue()); assertNull ("maximumValue", descriptor.getMaximumValue()); assertEquals ("minimumOccurs", 1, descriptor.getMinimumOccurs()); assertEquals ("maximumOccurs", 1, descriptor.getMaximumOccurs()); assertNull ("unit", descriptor.getUnit()); /* * Invalid operation: element not in the list of valid elements. */ try { DefaultParameterDescriptor<String> p = create("Enumeration param", String.class, enumeration, "Pear"); fail("Should not be allowed to create " + p); } catch (IllegalArgumentException e) { assertEquals("Parameter “Enumeration param” can not take the “Pear” value.", e.getMessage()); } }
/** * Tests various {@code create(…)} methods. */ @Test public void testCreate() { final ParameterBuilder builder = new ParameterBuilder(); ParameterDescriptor<Double> p = builder.addName("Test 1").create(0, Units.METRE); assertEquals("name", "Test 1", p.getName().getCode()); assertEquals("defaultValue", 0.0, p.getDefaultValue(), 0); assertNull ("minimumValue", p.getMinimumValue()); assertNull ("maximumValue", p.getMaximumValue()); assertEquals("unit", Units.METRE, p.getUnit()); p = builder.addName("Test 2").create(Double.NaN, Units.METRE); assertEquals("name", "Test 2", p.getName().getCode()); assertNull ("defaultValue", p.getDefaultValue()); assertNull ("minimumValue", p.getMinimumValue()); assertNull ("maximumValue", p.getMaximumValue()); assertEquals("unit", Units.METRE, p.getUnit()); p = builder.addName("Test 3").createBounded(1, 4, 3, Units.METRE); assertEquals("name", "Test 3", p.getName().getCode()); assertEquals("defaultValue", 3.0, p.getDefaultValue(), 0); assertEquals("minimumValue", 1.0, p.getMinimumValue()); assertEquals("maximumValue", 4.0, p.getMaximumValue()); assertEquals("unit", Units.METRE, p.getUnit()); }
/** * Tests the creation of a simple descriptor for an optional parameter without minimum or maximum value. */ @Test public void testOptionalInteger() { final ParameterDescriptor<Integer> descriptor = createSimpleOptional("Simple param", Integer.class); assertEquals("name", "Simple param", descriptor.getName().getCode()); assertEquals("valueClass", Integer.class, descriptor.getValueClass()); assertNull ("validValues", descriptor.getValidValues()); assertNull ("defaultValue", descriptor.getDefaultValue()); assertNull ("minimumValue", descriptor.getMinimumValue()); assertNull ("maximumValue", descriptor.getMaximumValue()); assertEquals("minimumOccurs", 0, descriptor.getMinimumOccurs()); assertEquals("maximumOccurs", 1, descriptor.getMaximumOccurs()); }