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.HashMap;
20  import java.util.Map;
21  
22  import org.orekit.errors.OrekitException;
23  import org.orekit.errors.OrekitMessages;
24  
25  /** Enumerate for carrier phase in {@link DataStreamRecord}.
26   * @author Luc Maisonobe
27   * @since 11.0
28   */
29  public enum CarrierPhase {
30  
31      /** No. */
32      NO(0),
33  
34      /** Yes, L1. */
35      L1(1),
36  
37      /** Yes, L1&L2. */
38      L1_L2(2);
39  
40      /** code map. */
41      private static final Map<Integer, CarrierPhase> CODES_MAP = new HashMap<>();
42      static {
43          for (final CarrierPhase type : values()) {
44              CODES_MAP.put(type.getCode(), type);
45          }
46      }
47  
48      /** Code. */
49      private final int code;
50  
51      /** Simple constructor.
52       * @param code code in the sourcetable records
53       */
54      CarrierPhase(final int code) {
55          this.code = code;
56      }
57  
58      /** Get code.
59       * @return code
60       */
61      private int getCode() {
62          return code;
63      }
64  
65      /** Get the carrier phase corresponding to a code.
66       * @param code carrier phase code
67       * @return the carrier phase corresponding to the code
68       */
69      public static CarrierPhase getCarrierPhase(final String code) {
70          CarrierPhase carrierPhase = null;
71          try {
72              carrierPhase = CODES_MAP.get(Integer.parseInt(code));
73          } catch (NumberFormatException nfe) {
74              // error will be handled by the if below
75          }
76          if (carrierPhase == null) {
77              throw new OrekitException(OrekitMessages.UNKNOWN_CARRIER_PHASE_CODE, code);
78          }
79          return carrierPhase;
80      }
81  
82  }