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.gnss.metric.ntrip;
18  
19  import java.util.regex.Pattern;
20  
21  import org.orekit.errors.OrekitException;
22  import org.orekit.errors.OrekitMessages;
23  
24  /** Enumerate for data format in {@link DataStreamRecord}.
25   * @author Luc Maisonobe
26   * @since 11.0
27   */
28  public enum DataFormat {
29  
30      /** RTCM 2.x. */
31      RTCM_2("RTCM 2(?:[\\.0-9]+)?"),
32  
33      /** RTCM 3.x. */
34      RTCM_3("RTCM 3(?:[\\.0-9]+)?"),
35  
36      /** RTCM SAPOS. */
37      RTCM_SAPOS("RTCM SAPOS"),
38  
39      /** CMR. */
40      CMR("CMR"),
41  
42      /** CMR+. */
43      CMR_PLUS("CMR +"),
44  
45      /** SAPOS-AdV. */
46      SAPOS_ADV("SAPOS-AdV"),
47  
48      /** RTCA. */
49      RTCA("RTCA"),
50  
51      /** RAW. */
52      RAW("RAW"),
53  
54      /** RINEX. */
55      RINEX("RINEX"),
56  
57      /** SP3. */
58      SP3("SP3"),
59  
60      /** BINEX. */
61      BINEX("BINEX");
62  
63      /** Keyword pattern. */
64      private final Pattern pattern;
65  
66      /** Simple constructor.
67       * @param keywordPattern pattern for keyword in the sourcetable records
68       */
69      DataFormat(final String keywordPattern) {
70          this.pattern = Pattern.compile(keywordPattern);
71      }
72  
73      /** Get pattern for keyword.
74       * @return pattern for keyword
75       */
76      private Pattern getPattern() {
77          return pattern;
78      }
79  
80      /** Get the message type corresponding to a keyword.
81       * @param keyword data format keyword
82       * @return the message type corresponding to the keyword
83       */
84      public static DataFormat getDataFormat(final String keyword) {
85          for (final DataFormat format : values()) {
86              if (format.getPattern().matcher(keyword).matches()) {
87                  return format;
88              }
89          }
90          throw new OrekitException(OrekitMessages.UNKNOWN_DATA_FORMAT, keyword);
91      }
92  
93  }