CarrierPhase.java

  1. /* Copyright 2002-2024 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. import java.util.HashMap;
  19. import java.util.Map;

  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitMessages;

  22. /** Enumerate for carrier phase in {@link DataStreamRecord}.
  23.  * @author Luc Maisonobe
  24.  * @since 11.0
  25.  */
  26. public enum CarrierPhase {

  27.     /** No. */
  28.     NO(0),

  29.     /** Yes, L1. */
  30.     L1(1),

  31.     /** Yes, L1&L2. */
  32.     L1_L2(2);

  33.     /** code map. */
  34.     private static final Map<Integer, CarrierPhase> CODES_MAP = new HashMap<Integer, CarrierPhase>();
  35.     static {
  36.         for (final CarrierPhase type : values()) {
  37.             CODES_MAP.put(type.getCode(), type);
  38.         }
  39.     }

  40.     /** Code. */
  41.     private final int code;

  42.     /** Simple constructor.
  43.      * @param code code in the sourcetable records
  44.      */
  45.     CarrierPhase(final int code) {
  46.         this.code = code;
  47.     }

  48.     /** Get code.
  49.      * @return code
  50.      */
  51.     private int getCode() {
  52.         return code;
  53.     }

  54.     /** Get the carrier phase corresponding to a code.
  55.      * @param code carrier phase code
  56.      * @return the carrier phase corresponding to the code
  57.      */
  58.     public static CarrierPhase getCarrierPhase(final String code) {
  59.         CarrierPhase carrierPhase = null;
  60.         try {
  61.             carrierPhase = CODES_MAP.get(Integer.parseInt(code));
  62.         } catch (NumberFormatException nfe) {
  63.             // error will be handled by the if below
  64.         }
  65.         if (carrierPhase == null) {
  66.             throw new OrekitException(OrekitMessages.UNKNOWN_CARRIER_PHASE_CODE, code);
  67.         }
  68.         return carrierPhase;
  69.     }

  70. }