001/*
002 *    GeoAPI - Java interfaces for OGC/ISO standards
003 *    Copyright © 2004-2023 Open Geospatial Consortium, Inc.
004 *    http://www.geoapi.org
005 *
006 *    Licensed under the Apache License, Version 2.0 (the "License");
007 *    you may not use this file except in compliance with the License.
008 *    You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *    Unless required by applicable law or agreed to in writing, software
013 *    distributed under the License is distributed on an "AS IS" BASIS,
014 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 *    See the License for the specific language governing permissions and
016 *    limitations under the License.
017 */
018package org.opengis.parameter;
019
020import java.util.Set;
021import javax.measure.Unit;
022import org.opengis.util.TypeName;
023import org.opengis.util.CodeList;
024import org.opengis.annotation.UML;
025
026import static org.opengis.annotation.Obligation.*;
027import static org.opengis.annotation.Specification.*;
028
029
030/**
031 * The definition of a parameter used by an operation method.
032 * Most parameter values are numeric, but other types of parameter values are possible.
033 * A parameter descriptor contains the following properties:
034 * <ul>
035 *   <li>The parameter {@linkplain #getName() name}.</li>
036 *   <li>The {@linkplain #getValueClass() class of values}. This is usually {@link Double}, {@code double[]},
037 *       {@link Integer}, {@code int[]}, {@link Boolean}, {@link String} or {@link java.net.URI}.</li>
038 *   <li>Whether this parameter is optional or mandatory. This is specified by the {@linkplain #getMinimumOccurs()
039 *       minimum occurrences} number, which can be 0 or 1 respectively.</li>
040 *   <li>The {@linkplain #getDefaultValue() default value} and its {@linkplain #getUnit() unit of measurement}.</li>
041 *   <li>The domain of values, as a {@linkplain #getMinimumValue() minimum value}, {@linkplain #getMaximumValue()
042 *       maximum value} or an enumeration of {@linkplain #getValidValues() valid values}.</li>
043 * </ul>
044 *
045 * @param  <T>  the type of parameter values.
046 *
047 * @departure rename
048 *   GeoAPI uses a name which contains the "{@code Descriptor}" word for consistency with other
049 *   libraries in Java (e.g. {@code ParameterListDescriptor} in Java Advanced Imaging).
050 *
051 * @author  OGC Topic 2 (for abstract model and documentation)
052 * @author  Martin Desruisseaux (IRD, Geomatys)
053 * @author  Jody Garnett (Refractions Research)
054 * @version 3.1
055 * @since   2.0
056 *
057 * @see ParameterValue
058 * @see ParameterDescriptorGroup
059 */
060@UML(identifier="OperationParameter", specification=ISO_19111)
061public interface ParameterDescriptor<T> extends GeneralParameterDescriptor {
062    /**
063     * Returns the name that describes the type of parameter values.
064     * This is closely related to the {@link Class} returned by {@link #getValueClass()}:
065     *
066     * <ul>
067     *   <li>If the value class is a collection (e.g. {@link java.util.List} or array),
068     *       then this method returns the type of <em>elements</em> in the collection.</li>
069     *   <li>Otherwise this method returns the value class using the mapping documented in {@link TypeName} javadoc
070     *       or using an implementation-dependent mapping.</li>
071     * </ul>
072     *
073     * {@code TypeName} is used for encoding parameters in XML or JSON documents,
074     * while {@link #getValueClass()} is used for programmatic purposes.
075     *
076     * @return the type name of value component(s) in this parameter.
077     *
078     * @since 3.1
079     */
080    @UML(identifier="DQM_Parameter.valueType", obligation=MANDATORY, specification=ISO_19157)
081    TypeName getValueType();
082
083    /**
084     * Returns the class that describes the type of parameter values.
085     * This is usually (but not restricted to) {@link Boolean}, {@link Integer}, {@link Double}, {@link String}
086     * or {@link java.net.URI} when the parameter contains a single value.
087     * If the parameter can contain multiple values, then the class may be {@code int[]}, {@code double[]},
088     * {@link java.util.List}, {@link Set} or {@link java.util.Map}.
089     *
090     * @return the type of parameter values.
091     */
092    @UML(identifier="GC_ParameterInfo.type", obligation=MANDATORY, specification=OGC_01004)
093    Class<T> getValueClass();
094
095    /**
096     * Returns the set of allowed values when these are restricted to some finite set or returns
097     * {@code null} otherwise. The returned set usually contains {@linkplain CodeList code list}
098     * or enumeration elements.
099     *
100     * <div class="note"><b>Note:</b>
101     * it is not necessary to provide this property when all values from the code list or enumeration are allowed.
102     * </div>
103     *
104     * @return a finite set of valid values (usually from a {@code CodeList}),
105     *         or {@code null} if it does not apply or if there is no restriction.
106     *
107     * @departure extension
108     *   This method is not part of ISO specification. It is provided as a complement of information.
109     */
110    default Set<T> getValidValues() {
111        return null;                    // Really null, not an empty collection, because we mean "no restriction".
112    }
113
114    /**
115     * Returns the minimum parameter value.
116     * If there is no minimum value, or if the minimum value is inappropriate for the
117     * {@linkplain #getValueClass() value class}, then this method returns {@code null}.
118     *
119     * @return the minimum parameter value (often an instance of {@link Double}), or {@code null}.
120     *
121     * @see #getMaximumValue()
122     * @see #getUnit()
123     */
124    @UML(identifier="GC_ParameterInfo.minimumValue", obligation=OPTIONAL, specification=OGC_01004)
125    default Comparable<T> getMinimumValue() {
126        return null;
127    }
128
129    /**
130     * Returns the maximum parameter value.
131     * If there is no maximum value, or if the maximum value is inappropriate for the
132     * {@linkplain #getValueClass() value class}, then this method returns {@code null}.
133     *
134     * @return the maximum parameter value (often an instance of {@link Double}), or {@code null}.
135     *
136     * @see #getMinimumValue()
137     * @see #getUnit()
138     */
139    @UML(identifier="GC_ParameterInfo.maximumValue", obligation=OPTIONAL, specification=OGC_01004)
140    default Comparable<T> getMaximumValue() {
141        return null;
142    }
143
144    /**
145     * Returns the default value for the parameter.
146     * If there is no default value, then this method returns {@code null}.
147     *
148     * @return the default value, or {@code null} in none.
149     *
150     * @see #getUnit()
151     */
152    @UML(identifier="GC_ParameterInfo.defaultValue", obligation=OPTIONAL, specification=OGC_01004)
153    default T getDefaultValue() {
154        return null;
155    }
156
157    /**
158     * Returns the unit of measurement for the minimum, maximum and default values.
159     * This attribute applies only if the value is of numeric type
160     * (usually an instance of {@link Double}).
161     *
162     * @return the unit for numeric value, or {@code null} if it does not apply to the value type.
163     *
164     * @departure extension
165     *   This method is not part of ISO specification. It is provided as a complement of information.
166     *
167     * @see #getMinimumValue()
168     * @see #getMaximumValue()
169     * @see #getDefaultValue()
170     */
171    default Unit<?> getUnit() {
172        return null;
173    }
174
175    /**
176     * Creates a new instance of parameter value initialized with the default value.
177     * While not a requirement, the {@linkplain ParameterValue#getDescriptor() parameter value descriptor}
178     * for the created parameter value will typically be {@code this} descriptor instance.
179     *
180     * @return a new parameter value initialized to the default value.
181     *
182     * @departure extension
183     *   This method is not part of the ISO specification.
184     *   It is provided in GeoAPI as a kind of factory method.
185     *
186     * @see #getDefaultValue()
187     */
188    @Override
189    ParameterValue<T> createValue();
190}