Java Code Examples for org.opengis.parameter.ParameterDescriptor#getMinimumValue()

The following examples show how to use org.opengis.parameter.ParameterDescriptor#getMinimumValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceParameter.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Compares this object with the given one for equality.
 *
 * @param  object  the object to compare with this reference system.
 * @param  mode    the strictness level of the comparison.
 * @return {@code true} if both objects are equal.
 */
@Override
public boolean equals(final Object object, final ComparisonMode mode) {
    if (object == this) {
        return true;
    }
    if (super.equals(object, mode) && object instanceof ParameterDescriptor<?>) {
        final ParameterDescriptor<?> that = (ParameterDescriptor<?>) object;
        if (that.getUnit()         == null &&
            that.getDefaultValue() == null &&
            that.getValueClass()   == getValueClass())
        {
            if (mode.isIgnoringMetadata()) {
                return Objects.equals(toString(getName()), toString(that.getName()));
                // super.equals(…) already compared 'getName()' in others mode.
            }
            return that.getMinimumOccurs() == getMinimumOccurs() &&
                   that.getMaximumOccurs() == getMaximumOccurs() &&
                   that.getValidValues()   == null &&
                   that.getMinimumValue()  == null &&
                   that.getMaximumValue()  == null;
        }
    }
    return false;
}
 
Example 2
Source File: MapProjection.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the given parameter value. This method duplicates the verification already
 * done by {@link org.apache.sis.parameter.DefaultParameterValue#setValue(Object, Unit)}.
 * But we check again because we have no guarantee that the parameters given by the user
 * were instances of {@code DefaultParameterValue}, or that the descriptor associated to
 * the user-specified {@code ParameterValue} has sufficient information.
 *
 * @param  descriptor  the descriptor that specify the parameter to validate.
 * @param  value       the parameter value in the units given by the descriptor.
 * @throws IllegalArgumentException if the given value is out of bounds.
 *
 * @see #createZeroConstant(ParameterBuilder)
 */
public static void validate(final ParameterDescriptor<? extends Number> descriptor, final double value)
        throws IllegalArgumentException
{
    if (!Double.isFinite(value)) {
        throw new IllegalArgumentException(Resources.format(Resources.Keys.IllegalParameterValue_2,
                descriptor.getName(), value));
    }
    final Comparable<? extends Number> min = descriptor.getMinimumValue();
    final Comparable<? extends Number> max = descriptor.getMaximumValue();
    final double minValue = (min instanceof Number) ? ((Number) min).doubleValue() : Double.NaN;
    final double maxValue = (max instanceof Number) ? ((Number) max).doubleValue() : Double.NaN;
    if (value < minValue || value > maxValue) {
        /*
         * RATIONAL: why we do not check the bounds if (min == max):
         * The only case when our descriptor have (min == max) is when a parameter can only be zero,
         * because of the way the map projection is defined (see e.g. Mercator1SP.LATITUDE_OF_ORIGIN).
         * But in some cases, it would be possible to deal with non-zero values, even if in principle
         * we should not. In such case we let the caller decides.
         *
         * Above check should be revisited if createZeroConstant(ParameterBuilder) is modified.
         */
        if (minValue != maxValue) {   // Compare as 'double' because we want (-0 == +0) to be true.
            throw new IllegalArgumentException(Errors.format(Errors.Keys.ValueOutOfRange_4,
                    descriptor.getName(), min, max, value));
        }
    }
}
 
Example 3
Source File: CustomCrsPanel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private static PropertyContainer createValueContainer(ParameterValueGroup valueGroup) {
    final PropertyContainer vc = new PropertyContainer();
    List<GeneralParameterDescriptor> descriptors = valueGroup.getDescriptor().descriptors();
    for (GeneralParameterDescriptor descriptor : descriptors) {
        final Class valueType;
        Set validValues = null;
        Comparable minValue = null;
        Comparable maxValue = null;
        if (descriptor instanceof ParameterDescriptor) {
            ParameterDescriptor parameterDescriptor = (ParameterDescriptor) descriptor;
            valueType = parameterDescriptor.getValueClass();
            validValues = parameterDescriptor.getValidValues();
            minValue = parameterDescriptor.getMinimumValue();
            maxValue = parameterDescriptor.getMaximumValue();
        } else {
            valueType = Double.TYPE;
        }

        final String paramName = descriptor.getName().getCode();
        final PropertyDescriptor vd = new PropertyDescriptor(paramName, valueType);
        final ParameterValue<?> parameterValue = valueGroup.parameter(paramName);
        if (parameterValue.getUnit() != null) {
            vd.setUnit(String.valueOf(parameterValue.getUnit()));
        }
        if (validValues != null) {
            vd.setValueSet(new ValueSet(validValues.toArray()));
        }
        if ( minValue instanceof Double && maxValue instanceof Double) {
            Double min = (Double) minValue;
            Double max = (Double) maxValue;
            vd.setValueRange(new ValueRange(min, max));
            if(parameterValue.getValue() == null) {
                parameterValue.setValue((min + max) / 2);
            }
        }

        vd.setDefaultConverter();
        final Property property = new Property(vd, new PropertyAccessor() {
            @Override
            public Object getValue() {
                return parameterValue.getValue();
            }

            @Override
            public void setValue(Object value) {
                parameterValue.setValue(value);
            }
        });
        vc.addProperty(property);
    }
    return vc;
}
 
Example 4
Source File: CC_GeneralOperationParameter.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}