TimeSystem.java

  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. import java.util.HashMap;
  19. import java.util.Map;

  20. import org.orekit.errors.OrekitIllegalArgumentException;
  21. import org.orekit.errors.OrekitMessages;
  22. import org.orekit.time.TimeScale;
  23. import org.orekit.time.TimeScales;

  24. /** Enumerate for the time systems used in navigation files.
  25.  *
  26.  * @author Thomas Neidhart
  27.  * @author Evan Ward
  28.  * @author Thomas Paulet
  29.  * @since 11.0
  30.  */
  31. public enum TimeSystem {

  32.     /** Global Positioning System. */
  33.     GPS("GPS"),

  34.     /** GLONASS. */
  35.     GLONASS("GLO"),

  36.     /** GALILEO. */
  37.     GALILEO("GAL"),

  38.     /** International Atomic Time. */
  39.     TAI("TAI"),

  40.     /** Coordinated Universal Time. */
  41.     UTC("UTC"),

  42.     /** Quasi-Zenith System. */
  43.     QZSS("QZS"),

  44.     /** Beidou. */
  45.     BEIDOU("BDS"),

  46.     /** IRNSS. */
  47.     IRNSS("IRN"),

  48.     /** Unknown. */
  49.     UNKNOWN("LCL");

  50.     /** Parsing map. */
  51.     private static final Map<String, TimeSystem> KEYS_MAP = new HashMap<>();
  52.     static {
  53.         for (final TimeSystem timeSystem : values()) {
  54.             KEYS_MAP.put(timeSystem.getKey(), timeSystem);
  55.         }
  56.     }

  57.     /** Key for the system. */
  58.     private final String key;

  59.     /** Simple constructor.
  60.      * @param key key letter
  61.      */
  62.     TimeSystem(final String key) {
  63.         this.key = key;
  64.     }

  65.     /** Get the key for the system.
  66.      * @return key for the system
  67.      */
  68.     public String getKey() {
  69.         return key;
  70.     }

  71.     /** Parse a string to get the time system.
  72.      * <p>
  73.      * The string must be the time system.
  74.      * </p>
  75.      * @param s string to parse
  76.      * @return the time system
  77.      * @exception OrekitIllegalArgumentException if the string does not correspond to a time system key
  78.      */
  79.     public static TimeSystem parseTimeSystem(final String s)
  80.         throws OrekitIllegalArgumentException {
  81.         final TimeSystem timeSystem = KEYS_MAP.get(s);
  82.         if (timeSystem == null) {
  83.             throw new OrekitIllegalArgumentException(OrekitMessages.UNKNOWN_TIME_SYSTEM, s);
  84.         }
  85.         return timeSystem;
  86.     }

  87.     /** Get the time scale corresponding to time system.
  88.      * @param timeScales the set of time scales to use
  89.      * @return the time scale corresponding to time system in the set of time scales
  90.      */
  91.     public TimeScale getTimeScale(final TimeScales timeScales) {

  92.         TimeScale timeScale = null;
  93.         switch (this) {
  94.             case GPS:
  95.                 timeScale = timeScales.getGPS();
  96.                 break;

  97.             case GALILEO:
  98.                 timeScale = timeScales.getGST();
  99.                 break;

  100.             case GLONASS:
  101.                 timeScale = timeScales.getGLONASS();
  102.                 break;

  103.             case QZSS:
  104.                 timeScale = timeScales.getQZSS();
  105.                 break;

  106.             case TAI:
  107.                 timeScale = timeScales.getTAI();
  108.                 break;

  109.             case UTC:
  110.                 timeScale = timeScales.getUTC();
  111.                 break;

  112.             case BEIDOU:
  113.                 timeScale = timeScales.getBDT();
  114.                 break;

  115.             case IRNSS:
  116.                 timeScale = timeScales.getIRNSS();
  117.                 break;

  118.             // Default value is GPS time scale, even in unknown case.
  119.             default:
  120.                 timeScale = timeScales.getGPS();
  121.                 break;
  122.         }

  123.         return timeScale;
  124.     }
  125. }