Class DefaultParameterValue<T>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Unit<?> unit
      The unit of measure for the value, or null if it does not apply.
      protected T value
      The value, or null if undefined.
    • Constructor Detail

      • DefaultParameterValue

        public DefaultParameterValue​(ParameterDescriptor<T> descriptor)
        Creates a parameter value from the specified descriptor. The value will be initialized to the default value, if any.
        Parameters:
        descriptor - the abstract definition of this parameter.
      • DefaultParameterValue

        public DefaultParameterValue​(ParameterValue<T> parameter)
        Creates a new instance initialized with the values from the specified parameter object. This is a shallow copy constructor, since the value contained in the given object is not cloned.
        Parameters:
        parameter - the parameter to copy values from.
        See Also:
        clone(), unmodifiable(Parameter­Value)
    • Method Detail

      • getUnit

        public Unit<?> getUnit()
        Returns the unit of measure of the parameter value. If the parameter value has no unit (for example because it is a String type), then this method returns null. Note that "no unit" does not mean "dimensionless".
        Implementation note for subclasses
        All getter methods which need unit information will invoke this get­Unit() method. Subclasses can override this method if they need to compute the unit dynamically.
        Specified by:
        get­Unit in interface Parameter­Value<T>
        Returns:
        the unit of measure, or null if none.
        See Also:
        double­Value(), double­Value­List(), get­Value()
      • getValue

        public T getValue()
        Returns the parameter value as an object. If no value has been set, then this method returns the default value (which may be null).
        Implementation note for subclasses
        All getter methods will invoke this get­Value() method. Subclasses can override this method if they need to compute the value dynamically.
        Specified by:
        get­Value in interface Parameter­Value<T>
        Returns:
        the parameter value as an object, or null if no value has been set and there is no default value.
        See Also:
        set­Value(Object), Parameters​.get­Value(Parameter­Descriptor)
      • setValue

        public void setValue​(Object newValue)
                      throws InvalidParameterValueException
        Sets the parameter value as an object. The object type is typically (but not limited to) Double, double[], Integer, int[], Boolean, String or URI. If the given value is null, then this parameter is set to the default value. If the given value is not an instance of the expected type, then this method may perform automatically a type conversion (for example from Float to Double or from Path to URI) if such conversion can be done without information lost.
        Specified by:
        set­Value in interface Parameter­Value<T>
        Parameters:
        new­Value - the parameter value, or null to restore the default.
        Throws:
        Invalid­Parameter­Value­Exception - if the type of value is inappropriate for this parameter, or if the value is illegal for some other reason (for example the value is numeric and out of range).
        See Also:
        get­Value()
      • setValue

        public void setValue​(int newValue)
                      throws InvalidParameterValueException
        Sets the parameter value as an integer. This method automatically wraps the given integer in an object of the type specified by the descriptor if that conversion can be done without information lost.
        Specified by:
        set­Value in interface Parameter­Value<T>
        Parameters:
        new­Value - the parameter value.
        Throws:
        Invalid­Parameter­Value­Exception - if the integer type is inappropriate for this parameter, or if the value is illegal for some other reason (for example a value out of range).
        See Also:
        int­Value()
      • setValue

        public void setValue​(double[] newValues,
                             Unit<?> unit)
                      throws InvalidParameterValueException
        Sets the parameter value as an array of floating point and their associated unit.
        Specified by:
        set­Value in interface Parameter­Value<T>
        Parameters:
        new­Values - the parameter values.
        unit - the unit for the specified value.
        Throws:
        Invalid­Parameter­Value­Exception - if the floating point array type is inappropriate for this parameter, or if the value is illegal for some other reason (for example a value out of range).
      • setValue

        protected void setValue​(Object newValue,
                                Unit<?> unit)
                         throws InvalidParameterValueException
        Sets the parameter value and its associated unit. If the given value is null, then this parameter is set to the default value. Otherwise the given value shall be an instance of the class expected by the descriptor.
        • This method does not perform any type conversion. Type conversion, if desired, should be applied by the public set­Value(…) methods before to invoke this protected method.
        • This method does not clone the given value. In particular, references to int[] and double[] arrays are stored as-is.
        Implementation note for subclasses
        This method is invoked by all setter methods in this class, thus providing a single point that subclasses can override if they want to perform more processing on the value before its storage, or to be notified about value changes.
        Parameters:
        new­Value - the parameter value, or null to restore the default.
        unit - the unit associated to the new parameter value, or null.
        Throws:
        Invalid­Parameter­Value­Exception - if the type of value is inappropriate for this parameter, or if the value is illegal for some other reason (for example the value is numeric and out of range).
        See Also:
        validate(Object)
      • validate

        protected void validate​(T newValue)
                         throws InvalidParameterValueException
        Invoked by set­Value(Object, Unit) after the basic verifications have been done and before the value is stored. Subclasses can override this method for performing additional verifications.
        Unit of measurement
        If the user specified a unit of measurement, then the value given to this method has been converted to the unit specified by the descriptor, for easier comparisons against standardized values. This converted value may be different than the value to be stored in this Parameter­Value, since the later value will be stored in the unit specified by the user.
        Standard validations
        The checks for value class, for value domain and for valid values are performed before this method is invoked. The default implementation of this method does nothing.
        Parameters:
        new­Value - the value converted to the unit of measurement specified by the descriptor.
        Throws:
        Invalid­Parameter­Value­Exception - if the given value is invalid for implementation-specific reasons.
      • equals

        public boolean equals​(Object object,
                              ComparisonMode mode)
        Compares the specified object with this parameter for equality. The strictness level is controlled by the second argument.
        Specified by:
        equals in interface Lenient­Comparable
        Parameters:
        object - the object to compare to this.
        mode - the strictness level of the comparison.
        Returns:
        true if both objects are equal according the given comparison mode.
      • equals

        public final boolean equals​(Object object)
        Compares the specified object with this parameter for equality. This method is implemented as below:
        return equals(other, ComparisonMode.STRICT);
        Subclasses shall override equals(Object, Comparison­Mode) instead than this method.
        Specified by:
        equals in interface Lenient­Comparable
        Overrides:
        equals in class Object
        Parameters:
        object - the object to compare to this.
        Returns:
        true if both objects are equal.
      • hashCode

        public int hashCode()
        Returns a hash value for this parameter. This value does not need to be the same in past or future versions of this class.
        Overrides:
        hash­Code in class Object
        Returns:
        the hash code value.
      • unmodifiable

        public static <T> DefaultParameterValue<T> unmodifiable​(ParameterValue<T> parameter)
        Returns an unmodifiable implementation of the given parameter value. This method shall be used only with: If the parameter value implements the Cloneable interface and has a public clone() method, then that value will be cloned every time the get­Value() method is invoked. The value is not cloned by this method however; it is caller's responsibility to not modify the value of the given parameter instance after this method call.
        Instances sharing
        If this method is invoked more than once with equal descriptor, value and unit, then this method will return the same Default­Parameter­Value instance on a best effort basis.
        Rational: the same parameter value is often used in many different coordinate operations. For example all Universal Transverse Mercator (UTM) projections use the same scale factor (0.9996) and false easting (500000 metres).
        Type Parameters:
        T - the type of the value stored in the given parameter.
        Parameters:
        parameter - the parameter to make unmodifiable, or null.
        Returns:
        a unmodifiable implementation of the given parameter, or null if the given parameter was null.
        Since:
        0.6
        See Also:
        Parameters​.unmodifiable(Parameter­Value­Group)
      • formatTo

        protected String formatTo​(Formatter formatter)
        Formats this parameter as a Well Known Text Parameter[…] element. Example:
        Parameter["False easting", 0.0, LengthUnit["metre", 1]]
        Unit of measurement
        The units of measurement were never specified in WKT 1 format, and are optional in WKT 2 format. If the units are not specified, then they are inferred from the context. Typically, parameter values that are lengths are given in the unit for the projected CRS axes while parameter values that are angles are given in the unit for the base geographic CRS.
        Example: The snippet below show WKT representations of the map projection parameters of a projected CRS (most other elements are omitted). The map projection uses a "Latitude of natural origin" parameters which is set to 52 grads, as defined in the UNIT[…] element of the enclosing CRS. A similar rule applies to “False easting” and “False northing” parameters, which are in kilometres in this example.

        WKT 1:

        PROJCS[…,
          GEOGCS[…,
            UNIT[“grad”, 0.015707963267948967]],       // Unit for all angles
          PROJECTION[“Lambert_Conformal_Conic_1SP”]
          PARAMETER[“latitude_of_origin”, 52.0],       // In grads
          PARAMETER[“scale_factor”, 0.99987742],
          PARAMETER[“false_easting”, 600.0],           // In kilometres
          PARAMETER[“false_northing”, 2200.0],         // In kilometres
          UNIT[“kilometre”, 1000]]                     // Unit for all lengths

        WKT 2:

        ProjectedCRS[…
          BaseGeodCRS[…
            AngleUnit[“grad”, 0.015707963267948967]],
          Conversion[“Lambert zone II”,
            Method[“Lambert Conic Conformal (1SP)”],
            Parameter[“Latitude of natural origin”, 52.0],
            Parameter[“Scale factor at natural origin”, 0.99987742],
            Parameter[“False easting”, 600.0],
            Parameter[“False northing”, 2200.0]],
          CS[“Cartesian”, 2],
            LengthUnit[“kilometre”, 1000]]
        Specified by:
        format­To in class Formattable­Object
        Parameters:
        formatter - the formatter where to format the inner content of this WKT element.
        Returns:
        "Parameter" or "Parameter­File".
        See Also:
        WKT 2 specification §17.2.4