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  
19  import java.util.regex.Pattern;
20  
21  /** Facade in front of several orbit determination methods in CCSDS messages.
22   * @author Luc Maisonobe
23   * @since 11.0
24   */
25  public class OdMethodFacade {
26  
27      /** Pattern for splitting string specification in OCM files. */
28      private static final Pattern SPLITTER = Pattern.compile("\\p{Blank}*:\\p{Blank}*");
29  
30      /** Name of the method. */
31      private final String name;
32  
33      /** Method type (may be null). */
34      private final OdMethodType type;
35  
36      /** Tool used for OD. */
37      private final String tool;
38  
39      /** Simple constructor.
40       * @param name name of the method
41       * @param type method type (may be null)
42       * @param tool tool used for OD (may be null)
43       */
44      public OdMethodFacade(final String name, final OdMethodType type, final String tool) {
45          this.name = name;
46          this.type = type;
47          this.tool = tool;
48      }
49  
50      /** Get the name of the method.
51       * @return name of the method
52       */
53      public String getName() {
54          return name;
55      }
56  
57      /** Get the method type.
58       * @return method type
59       */
60      public OdMethodType getType() {
61          return type;
62      }
63  
64      /** Get the tool used for OD.
65       * @return tool used for OD
66       */
67      public String getTool() {
68          return tool;
69      }
70  
71      /** Parse a string from OCM.
72       * @param s string to parse
73       * @return OD method facade
74       */
75      public static OdMethodFacade parse(final String s) {
76          final String[] fields = SPLITTER.split(s);
77          if (fields.length == 2) {
78              // we have method and tool
79              OdMethodType type;
80              try {
81                  type = OdMethodType.valueOf(fields[0]);
82              } catch (IllegalArgumentException iae) {
83                  type = null;
84              }
85              return new OdMethodFacade(fields[0], type, fields[1]);
86          } else {
87              return new OdMethodFacade(s, null, null);
88          }
89      }
90  
91  }