UserDefined.java

  1. /* Copyright 2002-2025 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.files.ccsds.ndm.odm;

  18. import java.util.Collections;
  19. import java.util.LinkedHashMap;
  20. import java.util.Map;

  21. import org.orekit.files.ccsds.section.CommentsContainer;

  22. /** Container for user defined data.
  23.  * <p>
  24.  * Beware that the Orekit getters and setters all rely on SI units. The parsers
  25.  * and writers take care of converting these SI units into CCSDS mandatory units.
  26.  * The {@link org.orekit.utils.units.Unit Unit} class provides useful
  27.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  28.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
  29.  * already use CCSDS units instead of the API SI units. The general-purpose
  30.  * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
  31.  * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
  32.  * (with an 's') also provide some predefined units. These predefined units and the
  33.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  34.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
  35.  * what the parsers and writers use for the conversions.
  36.  * </p>
  37.  * @author Luc Maisonobe
  38.  * @since 11.0
  39.  */
  40. public class UserDefined extends CommentsContainer {

  41.     /** Tag name for user defined parameters keys. */
  42.     public static final String USER_DEFINED_XML_TAG = "USER_DEFINED";

  43.     /** Attribute name for user defined parameters keys. */
  44.     public static final String USER_DEFINED_XML_ATTRIBUTE = "parameter";

  45.     /** Prefix for user defined parameters keys. */
  46.     public static final String USER_DEFINED_PREFIX = "USER_DEFINED_";

  47.     /** User defined parameters map. */
  48.     private final Map<String, String> map;

  49.     /** Create an empty data set.
  50.      */
  51.     public UserDefined() {
  52.         // we use a LinkedHashMap so we retrieve the parameters in the same order they are put in
  53.         map = new LinkedHashMap<>();
  54.     }

  55.     /** Get all user defined parameters.
  56.      * <p>
  57.      * The {@link #USER_DEFINED_PREFIX} has been stripped away from the keys.
  58.      * </p>
  59.      * @return unmodifiable view of the map containing all user defined parameters
  60.      */
  61.     public Map<String, String> getParameters() {
  62.         return Collections.unmodifiableMap(map);
  63.     }

  64.     /** Add a key/value entry.
  65.      * @param key parameter key, with the {@link #USER_DEFINED_PREFIX} stripped away
  66.      * @param value parameter value
  67.      */
  68.     public void addEntry(final String key, final String value) {
  69.         refuseFurtherComments();
  70.         map.put(key, value);
  71.     }

  72. }