1   /* Copyright 2002-2026 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.errors;
18  
19  import java.io.Serial;
20  import java.util.List;
21  
22  import org.orekit.utils.ParameterDriver;
23  import org.orekit.utils.ParameterDriversProvider;
24  
25  /** Exception for unsupported {@link ParameterDriver} in a model implementing {@link ParameterDriversProvider}.
26   *
27   * @author Maxime Journot
28   * @author Luc Maisonobe
29   * @since 12.0
30   */
31  public class UnsupportedParameterException extends OrekitException {
32  
33      /** String for empty parameter drivers' list. */
34      public static final String NO_PARAMETER = "<none>";
35  
36      /** Comma separator for printing list of supported parameter drivers. */
37      public static final String COMMA_SEP = ", ";
38  
39      /** Serializable UID. */
40      @Serial
41      private static final long serialVersionUID =  -1363569710782876135L;
42  
43      /** Constructor.
44       *
45       * @param parameterName name of the parameter driver that is not supported by the model
46       * @param parameterDrivers list of the model's parameter drivers
47       */
48      public UnsupportedParameterException(final String parameterName, final List<ParameterDriver> parameterDrivers) {
49          super(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, parameterName, getSupportedNames(parameterDrivers));
50      }
51  
52      /** Builder for the supported parameters' names.
53       *
54       * @param parameterDrivers list of model parameter drivers
55       * @return supported parameter names as a String
56       */
57      private static String getSupportedNames(final List<ParameterDriver> parameterDrivers) {
58          final StringBuilder builder = new StringBuilder();
59          for (final ParameterDriver driver : parameterDrivers) {
60              if (builder.length() > 0) {
61                  builder.append(COMMA_SEP);
62              }
63              builder.append(driver.getName());
64          }
65          if (builder.length() == 0) {
66              builder.append(NO_PARAMETER);
67          }
68          return builder.toString();
69      }
70  }