UnsupportedParameterException.java

  1. /* Copyright 2002-2023 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. import java.util.List;

  19. import org.orekit.utils.ParameterDriver;
  20. import org.orekit.utils.ParameterDriversProvider;

  21. /** Exception for unsupported {@link ParameterDriver} in a model implementing {@link ParameterDriversProvider}.
  22.  *
  23.  * @author Maxime Journot
  24.  * @author Luc Maisonobe
  25.  * @since 12.0
  26.  */
  27. public class UnsupportedParameterException extends OrekitException {

  28.     /** String for empty parameter drivers' list. */
  29.     public static final String NO_PARAMETER = "<none>";

  30.     /** Comma separator for printing list of supported parameter drivers. */
  31.     public static final String COMMA_SEP = ", ";

  32.     /** Serializable UID. */
  33.     private static final long serialVersionUID =  -1363569710782876135L;

  34.     /** Constructor.
  35.      *
  36.      * @param parameterName name of the parameter driver that is not supported by the model
  37.      * @param parameterDrivers list of the model's parameter drivers
  38.      */
  39.     public UnsupportedParameterException(final String parameterName, final List<ParameterDriver> parameterDrivers) {
  40.         super(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, parameterName, getSupportedNames(parameterDrivers));
  41.     }

  42.     /** Builder for the supported parameters' names.
  43.      *
  44.      * @param parameterDrivers list of model parameter drivers
  45.      * @return supported parameter names as a String
  46.      */
  47.     private static String getSupportedNames(final List<ParameterDriver> parameterDrivers) {
  48.         final StringBuilder builder = new StringBuilder();
  49.         for (final ParameterDriver driver : parameterDrivers) {
  50.             if (builder.length() > 0) {
  51.                 builder.append(COMMA_SEP);
  52.             }
  53.             builder.append(driver.getName());
  54.         }
  55.         if (builder.length() == 0) {
  56.             builder.append(NO_PARAMETER);
  57.         }
  58.         return builder.toString();
  59.     }
  60. }