DataFormat.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.regex.Pattern;

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

  21. /** Enumerate for data format in {@link DataStreamRecord}.
  22.  * @author Luc Maisonobe
  23.  * @since 11.0
  24.  */
  25. public enum DataFormat {

  26.     /** RTCM 2.x. */
  27.     RTCM_2("RTCM 2(?:[\\.0-9]+)?"),

  28.     /** RTCM 3.x. */
  29.     RTCM_3("RTCM 3(?:[\\.0-9]+)?"),

  30.     /** RTCM SAPOS. */
  31.     RTCM_SAPOS("RTCM SAPOS"),

  32.     /** CMR. */
  33.     CMR("CMR"),

  34.     /** CMR+. */
  35.     CMR_PLUS("CMR +"),

  36.     /** SAPOS-AdV. */
  37.     SAPOS_ADV("SAPOS-AdV"),

  38.     /** RTCA. */
  39.     RTCA("RTCA"),

  40.     /** RAW. */
  41.     RAW("RAW"),

  42.     /** RINEX. */
  43.     RINEX("RINEX"),

  44.     /** SP3. */
  45.     SP3("SP3"),

  46.     /** BINEX. */
  47.     BINEX("BINEX");

  48.     /** Keyword pattern. */
  49.     private final Pattern pattern;

  50.     /** Simple constructor.
  51.      * @param keywordPattern pattern for keyword in the sourcetable records
  52.      */
  53.     DataFormat(final String keywordPattern) {
  54.         this.pattern = Pattern.compile(keywordPattern);
  55.     }

  56.     /** Get pattern for keyword.
  57.      * @return pattern for keyword
  58.      */
  59.     private Pattern getPattern() {
  60.         return pattern;
  61.     }

  62.     /** Get the message type corresponding to a keyword.
  63.      * @param keyword data format keyword
  64.      * @return the message type corresponding to the keyword
  65.      */
  66.     public static DataFormat getDataFormat(final String keyword) {
  67.         for (final DataFormat format : values()) {
  68.             if (format.getPattern().matcher(keyword).matches()) {
  69.                 return format;
  70.             }
  71.         }
  72.         throw new OrekitException(OrekitMessages.UNKNOWN_DATA_FORMAT, keyword);
  73.     }

  74. }