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  /**
28   * Enumerate for satellite system.
29   *
30   * @author Luc Maisonobe
31   * @since 9.2
32   */
33  public enum SatelliteSystem {
34  
35      /** GPS system. */
36      GPS('G'),
37  
38      /** GLONASS system. */
39      GLONASS('R'),
40  
41      /** Galileo system. */
42      GALILEO('E'),
43  
44      /** Beidou system. */
45      BEIDOU('C'),
46  
47      /** Quasi-Zenith Satellite System system. */
48      QZSS('J'),
49  
50      /** Indian Regional Navigation Satellite System system. */
51      IRNSS('I'),
52  
53      /** SBAS system. */
54      SBAS('S'),
55  
56      /** Mixed system. */
57      MIXED('M');
58  
59      /** Parsing map. */
60      private static final Map<Character, SatelliteSystem> KEYS_MAP = new HashMap<>();
61      static {
62          for (final SatelliteSystem satelliteSystem : values()) {
63              KEYS_MAP.put(satelliteSystem.getKey(), satelliteSystem);
64          }
65      }
66  
67      /** Key for the system. */
68      private final char key;
69  
70      /** Simple constructor.
71       * @param key key letter
72       */
73      SatelliteSystem(final char key) {
74          this.key = key;
75      }
76  
77      /** Get the key for the system.
78       * @return key for the system
79       */
80      public char getKey() {
81          return key;
82      }
83  
84      /** Parse a string to get the satellite system.
85       * <p>
86       * The string first character must be the satellite system.
87       * </p>
88       * @param s string to parse
89       * @return the satellite system
90       * @exception OrekitIllegalArgumentException if the string does not correspond to a satellite system key
91       */
92      public static SatelliteSystem parseSatelliteSystem(final String s)
93          throws OrekitIllegalArgumentException {
94          final SatelliteSystem satelliteSystem = KEYS_MAP.get(s.charAt(0));
95          if (satelliteSystem == null) {
96              throw new OrekitIllegalArgumentException(OrekitMessages.UNKNOWN_SATELLITE_SYSTEM, s.charAt(0));
97          }
98          return satelliteSystem;
99      }
100 
101     /** Get default time scale for satellite system.
102      * @param timeScales the set of timeScales to use
103      * @return the default time scale among the given set matching to satellite system,
104      *         null if there are not
105      */
106     public TimeScale getDefaultTimeSystem(final TimeScales timeScales) {
107 
108         TimeScale timeScale = null;
109         switch (this) {
110             case GPS:
111                 timeScale = timeScales.getGPS();
112                 break;
113 
114             case GALILEO:
115                 timeScale = timeScales.getGST();
116                 break;
117 
118             case GLONASS:
119                 timeScale = timeScales.getGLONASS();
120                 break;
121 
122             case QZSS:
123                 timeScale = timeScales.getQZSS();
124                 break;
125 
126             case BEIDOU:
127                 timeScale = timeScales.getBDT();
128                 break;
129 
130             case IRNSS:
131                 timeScale = timeScales.getIRNSS();
132                 break;
133 
134             // Default value is null
135             default:
136                 timeScale = null;
137                 break;
138         }
139 
140         return timeScale;
141     }
142 
143 }