1   /* Copyright 2002-2022 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;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.orekit.errors.OrekitIllegalArgumentException;
23  import org.orekit.errors.OrekitMessages;
24  import org.orekit.time.TimeScale;
25  import org.orekit.time.TimeScales;
26  
27  /** Enumerate for the time systems used in navigation files.
28   *
29   * @author Thomas Neidhart
30   * @author Evan Ward
31   * @author Thomas Paulet
32   * @since 11.0
33   */
34  public enum TimeSystem {
35  
36      /** Global Positioning System. */
37      GPS("GPS"),
38  
39      /** GLONASS. */
40      GLONASS("GLO"),
41  
42      /** GALILEO. */
43      GALILEO("GAL"),
44  
45      /** International Atomic Time. */
46      TAI("TAI"),
47  
48      /** Coordinated Universal Time. */
49      UTC("UTC"),
50  
51      /** Quasi-Zenith System. */
52      QZSS("QZS"),
53  
54      /** Beidou. */
55      BEIDOU("BDS"),
56  
57      /** IRNSS. */
58      IRNSS("IRN"),
59  
60      /** Unknown. */
61      UNKNOWN("LCL");
62  
63      /** Parsing map. */
64      private static final Map<String, TimeSystem> KEYS_MAP = new HashMap<>();
65      static {
66          for (final TimeSystem timeSystem : values()) {
67              KEYS_MAP.put(timeSystem.getKey(), timeSystem);
68          }
69      }
70  
71      /** Key for the system. */
72      private final String key;
73  
74      /** Simple constructor.
75       * @param key key letter
76       */
77      TimeSystem(final String key) {
78          this.key = key;
79      }
80  
81      /** Get the key for the system.
82       * @return key for the system
83       */
84      public String getKey() {
85          return key;
86      }
87  
88      /** Parse a string to get the time system.
89       * <p>
90       * The string must be the time system.
91       * </p>
92       * @param s string to parse
93       * @return the time system
94       * @exception OrekitIllegalArgumentException if the string does not correspond to a time system key
95       */
96      public static TimeSystem parseTimeSystem(final String s)
97          throws OrekitIllegalArgumentException {
98          final TimeSystem timeSystem = KEYS_MAP.get(s);
99          if (timeSystem == null) {
100             throw new OrekitIllegalArgumentException(OrekitMessages.UNKNOWN_TIME_SYSTEM, s);
101         }
102         return timeSystem;
103     }
104 
105     /** Get the time scale corresponding to time system.
106      * @param timeScales the set of time scales to use
107      * @return the time scale corresponding to time system in the set of time scales
108      */
109     public TimeScale getTimeScale(final TimeScales timeScales) {
110 
111         TimeScale timeScale = null;
112         switch (this) {
113             case GPS:
114                 timeScale = timeScales.getGPS();
115                 break;
116 
117             case GALILEO:
118                 timeScale = timeScales.getGST();
119                 break;
120 
121             case GLONASS:
122                 timeScale = timeScales.getGLONASS();
123                 break;
124 
125             case QZSS:
126                 timeScale = timeScales.getQZSS();
127                 break;
128 
129             case TAI:
130                 timeScale = timeScales.getTAI();
131                 break;
132 
133             case UTC:
134                 timeScale = timeScales.getUTC();
135                 break;
136 
137             case BEIDOU:
138                 timeScale = timeScales.getBDT();
139                 break;
140 
141             case IRNSS:
142                 timeScale = timeScales.getIRNSS();
143                 break;
144 
145             // Default value is GPS time scale, even in unknown case.
146             default:
147                 timeScale = timeScales.getGPS();
148                 break;
149         }
150 
151         return timeScale;
152     }
153 }