001/* 002 * GeoAPI - Java interfaces for OGC/ISO standards 003 * Copyright © 2003-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.List; 021import org.opengis.metadata.Identifier; 022import org.opengis.annotation.UML; 023 024import static org.opengis.annotation.Obligation.*; 025import static org.opengis.annotation.Specification.*; 026 027 028/** 029 * A group of related parameter values. 030 * The same group can be repeated more than once in an 031 * {@linkplain org.opengis.referencing.operation.CoordinateOperation coordinate operation} 032 * or higher level {@code ParameterValueGroup}, if those instances contain different values 033 * of one or more {@link ParameterValue}s which suitably distinguish among those groups. 034 * 035 * <p>The methods adapted from the ISO 19111 standard are {@link #getDescriptor()} and {@link #values()}. 036 * Other methods (except {@link #clone()}) are convenience methods:</p> 037 * 038 * <ul> 039 * <li>{@link #parameter(String)} searches for a single parameter value of the given name.</li> 040 * <li>{@link #groups(String)} searches for all groups of the given name.</li> 041 * <li>{@link #addGroup(String)} for creating a new subgroup and adding it to the list of subgroups.</li> 042 * </ul> 043 * 044 * <h2>Design note:</h2> 045 * There is no <code>parameter<b><u>s</u></b>(String)</code> method returning a list of parameter values 046 * because the ISO 19111 standard fixes the {@link ParameterValue} 047 * {@linkplain ParameterDescriptor#getMaximumOccurs() maximum occurrence} to 1. 048 * 049 * @author OGC Topic 2 (for abstract model and documentation) 050 * @author Martin Desruisseaux (IRD, Geomatys) 051 * @author Jody Garnett (Refractions Research) 052 * @version 3.1 053 * @since 1.0 054 * 055 * @see ParameterDescriptorGroup 056 * @see ParameterValue 057 */ 058@UML(identifier="ParameterValueGroup", specification=ISO_19111) 059public interface ParameterValueGroup extends GeneralParameterValue { 060 /** 061 * Returns the abstract definition of this group of parameters. 062 * 063 * @return the abstract definition of this group of parameters. 064 * 065 * @departure rename 066 * The ISO name was "{@code group}". GeoAPI uses "{@code descriptor}" instead in 067 * order to override the {@code getDescriptor()} generic method provided in the parent 068 * interface. In addition the "descriptor" name makes more apparent that this method returns 069 * an abstract definition of parameters - not their actual values - and is consistent with 070 * usage in other Java libraries like the <cite>Java Advanced Imaging</cite> library. 071 */ 072 @Override 073 @UML(identifier="group", obligation=MANDATORY, specification=ISO_19111) 074 ParameterDescriptorGroup getDescriptor(); 075 076 /** 077 * Returns all values in this group. The returned list may or may not be unmodifiable; 078 * this is implementation-dependent. However, if some aspects of this list are modifiable, 079 * then any modification shall be reflected back into this {@code ParameterValueGroup}. 080 * More specifically: 081 * 082 * <ul> 083 * <li>If the list supports the {@link List#add(Object) add} operation, then it should 084 * ensure that the added {@linkplain GeneralParameterValue general parameter value} 085 * is valid and can be added to this group. 086 * An {@link InvalidParameterCardinalityException} (or any other appropriate exception) 087 * shall be thrown if it is not the case.</li> 088 * <li>The list may also supports the {@link List#remove(Object) remove} operation as a 089 * way to remove parameter created by the {@link #parameter(String)} method.</li> 090 * </ul> 091 * 092 * @return the values in this group. 093 */ 094 @UML(identifier="parameterValue", obligation=MANDATORY, specification=ISO_19111) 095 List<GeneralParameterValue> values(); 096 097 /** 098 * Returns the value in this group for the specified {@linkplain Identifier#getCode() identifier code}. 099 * This method performs the following choice: 100 * 101 * <ul> 102 * <li>If this group contains a parameter value of the given name, then that parameter is returned.</li> 103 * <li>Otherwise if a {@linkplain ParameterDescriptorGroup#descriptor(String) descriptor} of the given name 104 * exists, then a new {@code ParameterValue} instance is {@linkplain ParameterDescriptor#createValue() 105 * created}, added to this group and returned.</li> 106 * <li>Otherwise a {@code ParameterNotFoundException} is thrown.</li> 107 * </ul> 108 * 109 * <p>This convenience method provides a way to get and set parameter values by name. 110 * For example, the following idiom fetches a floating point value for the {@code "False northing"} parameter:</p> 111 * 112 * <blockquote><code> 113 * double northing = <b>parameter</b>("False northing").{@linkplain ParameterValue#doubleValue() doubleValue}(); 114 * </code></blockquote> 115 * 116 * The following idiom sets a floating point value for the {@code "False easting"} parameter: 117 * 118 * <blockquote><code> 119 * <b>parameter</b>("False easting").{@linkplain ParameterValue#setValue(double) setValue}(500000.0); 120 * </code></blockquote> 121 * 122 * This method does not search recursively in subgroups. This is because more than one 123 * subgroup may exist for the same {@linkplain ParameterDescriptorGroup descriptor}. 124 * The user have to {@linkplain #groups(String) query all subgroups} and select explicitly 125 * the appropriate one to use. 126 * 127 * @param name the case insensitive {@linkplain Identifier#getCode() identifier code} 128 * of the parameter to search for. 129 * @return the parameter value for the given identifier code. 130 * @throws ParameterNotFoundException if there is no parameter value for the given identifier code. 131 * 132 * @departure easeOfUse 133 * This method is not part of the ISO specification. It has been added in an attempt to make 134 * this interface easier to use. 135 */ 136 ParameterValue<?> parameter(String name) throws ParameterNotFoundException; 137 138 /** 139 * Returns all subgroups with the specified name. 140 * Groups are listed in the order they were added by calls to {@link #addGroup(String)}. 141 * 142 * <p>This method does not create new groups: if the requested group is optional (i.e. 143 * <code>{@linkplain ParameterDescriptor#getMinimumOccurs() minimumOccurs} == 0</code>) 144 * and no value were defined previously, then this method returns an empty list.</p> 145 * 146 * @param name the case insensitive {@linkplain Identifier#getCode() identifier code} 147 * of the parameter group to search for. 148 * @return the list of all parameter group for the given identifier code, in insertion order. 149 * @throws ParameterNotFoundException if no {@linkplain ParameterDescriptorGroup descriptor} 150 * was found for the given name. 151 * 152 * @departure easeOfUse 153 * This method is not part of the ISO specification. It has been added for ease of use. 154 */ 155 List<ParameterValueGroup> groups(String name) throws ParameterNotFoundException; 156 157 /** 158 * Creates a new subgroup of the specified name, and adds it to the list of subgroups. 159 * The specified name shall be the {@linkplain Identifier#getCode() identifier code} of 160 * a {@linkplain ParameterDescriptorGroup descriptor group} which is a child of this group. 161 * 162 * <p>There is no {@code removeGroup(String)} method. To remove a group, users can inspect 163 * the {@link #groups(String)} or {@link #values()} list, decide which occurrences to remove 164 * if there is many of them for the same name, and whether to iterate recursively into sub-groups or not.</p> 165 * 166 * @param name the case insensitive {@linkplain Identifier#getCode() identifier code} of the 167 * parameter group to create. 168 * @return a newly created parameter group for the given identifier code. 169 * @throws ParameterNotFoundException if no {@linkplain ParameterDescriptorGroup descriptor} 170 * was found for the given name. 171 * @throws InvalidParameterCardinalityException if this parameter group already contains the 172 * {@linkplain ParameterDescriptorGroup#getMaximumOccurs() maximum number of occurences} 173 * of subgroups of the given name. 174 * @throws IllegalStateException if the group cannot be added for another reason. 175 * 176 * @departure easeOfUse 177 * This method is not part of the ISO specification. It has been added for ease of use. 178 */ 179 ParameterValueGroup addGroup(String name) throws ParameterNotFoundException, 180 InvalidParameterCardinalityException, IllegalStateException; 181 182 /** 183 * Returns a copy of this group of parameter values. 184 * Included parameter values and subgroups are cloned recursively. 185 * 186 * @return a copy of this group of parameter values. 187 */ 188 @Override 189 ParameterValueGroup clone(); 190}