OdMethodFacade.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.definitions;

  18. import java.util.regex.Pattern;

  19. /** Facade in front of several orbit determination methods in CCSDS messages.
  20.  * @author Luc Maisonobe
  21.  * @since 11.0
  22.  */
  23. public class OdMethodFacade {

  24.     /** Pattern for splitting string specification in OCM files. */
  25.     private static final Pattern SPLITTER = Pattern.compile("\\p{Blank}*:\\p{Blank}*");

  26.     /** Name of the method. */
  27.     private final String name;

  28.     /** Method type (may be null). */
  29.     private final OdMethodType type;

  30.     /** Tool used for OD. */
  31.     private final String tool;

  32.     /** Simple constructor.
  33.      * @param name name of the method
  34.      * @param type method type (may be null)
  35.      * @param tool tool used for OD (may be null)
  36.      */
  37.     public OdMethodFacade(final String name, final OdMethodType type, final String tool) {
  38.         this.name = name;
  39.         this.type = type;
  40.         this.tool = tool;
  41.     }

  42.     /** Get the name of the method.
  43.      * @return name of the method
  44.      */
  45.     public String getName() {
  46.         return name;
  47.     }

  48.     /** Get the method type.
  49.      * @return method type
  50.      */
  51.     public OdMethodType getType() {
  52.         return type;
  53.     }

  54.     /** Get the tool used for OD.
  55.      * @return tool used for OD
  56.      */
  57.     public String getTool() {
  58.         return tool;
  59.     }

  60.     /** Parse a string from OCM.
  61.      * @param s string to parse
  62.      * @return OD method facade
  63.      */
  64.     public static OdMethodFacade parse(final String s) {
  65.         final String[] fields = SPLITTER.split(s);
  66.         if (fields.length == 2) {
  67.             // we have method and tool
  68.             OdMethodType type;
  69.             try {
  70.                 type = OdMethodType.valueOf(fields[0]);
  71.             } catch (IllegalArgumentException iae) {
  72.                 type = null;
  73.             }
  74.             return new OdMethodFacade(fields[0], type, fields[1]);
  75.         } else {
  76.             return new OdMethodFacade(s, null, null);
  77.         }
  78.     }

  79. }