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  
18  package org.orekit.files.ccsds.ndm.odm;
19  
20  import java.util.Collections;
21  import java.util.LinkedHashMap;
22  import java.util.Map;
23  
24  import org.orekit.files.ccsds.section.CommentsContainer;
25  
26  /** Container for user defined data.
27   * <p>
28   * Beware that the Orekit getters and setters all rely on SI units. The parsers
29   * and writers take care of converting these SI units into CCSDS mandatory units.
30   * The {@link org.orekit.utils.units.Unit Unit} class provides useful
31   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
32   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
33   * already use CCSDS units instead of the API SI units. The general-purpose
34   * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
35   * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
36   * (with an 's') also provide some predefined units. These predefined units and the
37   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
38   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
39   * what the parsers and writers use for the conversions.
40   * </p>
41   * @author Luc Maisonobe
42   * @since 11.0
43   */
44  public class UserDefined extends CommentsContainer {
45  
46      /** Tag name for user defined parameters keys. */
47      public static final String USER_DEFINED_XML_TAG = "USER_DEFINED";
48  
49      /** Attribute name for user defined parameters keys. */
50      public static final String USER_DEFINED_XML_ATTRIBUTE = "parameter";
51  
52      /** Prefix for user defined parameters keys. */
53      public static final String USER_DEFINED_PREFIX = "USER_DEFINED_";
54  
55      /** User defined parameters map. */
56      private final Map<String, String> map;
57  
58      /** Create an empty data set.
59       */
60      public UserDefined() {
61          // we use a LinkedHashMap so we retrieve the parameters in the same order they are put in
62          map = new LinkedHashMap<>();
63      }
64  
65      /** Get all user defined parameters.
66       * <p>
67       * The {@link #USER_DEFINED_PREFIX} has been stripped away from the keys.
68       * </p>
69       * @return unmodifiable view of the map containing all user defined parameters
70       */
71      public Map<String, String> getParameters() {
72          return Collections.unmodifiableMap(map);
73      }
74  
75      /** Add a key/value entry.
76       * @param key parameter key, with the {@link #USER_DEFINED_PREFIX} stripped away
77       * @param value parameter value
78       */
79      public void addEntry(final String key, final String value) {
80          refuseFurtherComments();
81          map.put(key, value);
82      }
83  
84  }
85