UserDefined.java

  1. /* Copyright 2002-2024 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.  * @author Luc Maisonobe
  24.  * @since 11.0
  25.  */
  26. public class UserDefined extends CommentsContainer {

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

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

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

  33.     /** User defined parameters map. */
  34.     private final Map<String, String> map;

  35.     /** Create an empty data set.
  36.      */
  37.     public UserDefined() {
  38.         // we use a LinkedHashMap so we retrieve the parameters in the same order they are put in
  39.         map = new LinkedHashMap<>();
  40.     }

  41.     /** Get all user defined parameters.
  42.      * <p>
  43.      * The {@link #USER_DEFINED_PREFIX} has been stripped away from the keys.
  44.      * </p>
  45.      * @return unmodifiable view of the map containing all user defined parameters
  46.      */
  47.     public Map<String, String> getParameters() {
  48.         return Collections.unmodifiableMap(map);
  49.     }

  50.     /** Add a key/value entry.
  51.      * @param key parameter key, with the {@link #USER_DEFINED_PREFIX} stripped away
  52.      * @param value parameter value
  53.      */
  54.     public void addEntry(final String key, final String value) {
  55.         refuseFurtherComments();
  56.         map.put(key, value);
  57.     }

  58. }