StationPredicate.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  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.files.sinex;

  18. import org.orekit.time.AbsoluteDate;
  19. import org.orekit.utils.Constants;

  20. import java.util.function.Predicate;

  21. /** Predicates for station coordinates blocks.
  22.  * @author Luc Maisonobe
  23.  * @since 13.0
  24.  */
  25. enum StationPredicate implements Predicate<SinexParseInfo> {

  26.     /** Predicate for STAX line. */
  27.     STAX {
  28.         /** {@inheritDoc} */
  29.         @Override
  30.         protected void store(final SinexParseInfo parseInfo, final double coordinate, final Station station,
  31.                              final AbsoluteDate epoch) {
  32.             parseInfo.setPx(coordinate, station, epoch);
  33.         }
  34.     },

  35.     /** Predicate for STAY line. */
  36.     STAY {
  37.         /** {@inheritDoc} */
  38.         @Override
  39.         protected void store(final SinexParseInfo parseInfo, final double coordinate, final Station station,
  40.                              final AbsoluteDate epoch) {
  41.             parseInfo.setPy(coordinate, station, epoch);
  42.         }
  43.     },

  44.     /** Predicate for STAZ line. */
  45.     STAZ {
  46.         /** {@inheritDoc} */
  47.         @Override
  48.         protected void store(final SinexParseInfo parseInfo, final double coordinate, final Station station,
  49.                              final AbsoluteDate epoch) {
  50.             parseInfo.setPz(coordinate, station, epoch);
  51.         }
  52.     },

  53.     /** Predicate for VELX line. */
  54.     VELX {
  55.         /** {@inheritDoc} */
  56.         @Override
  57.         protected void store(final SinexParseInfo parseInfo, final double coordinate, final Station station,
  58.                              final AbsoluteDate epoch) {
  59.             parseInfo.setVx(coordinate / Constants.JULIAN_YEAR, station);
  60.         }
  61.     },

  62.     /** Predicate for VELY line. */
  63.     VELY {
  64.         /** {@inheritDoc} */
  65.         @Override
  66.         protected void store(final SinexParseInfo parseInfo, final double coordinate, final Station station,
  67.                              final AbsoluteDate epoch) {
  68.             parseInfo.setVy(coordinate / Constants.JULIAN_YEAR, station);
  69.         }
  70.     },

  71.     /** Predicate for VELZ line. */
  72.     VELZ {
  73.         /** {@inheritDoc} */
  74.         @Override
  75.         protected void store(final SinexParseInfo parseInfo, final double coordinate, final Station station,
  76.                              final AbsoluteDate epoch) {
  77.             parseInfo.setVz(coordinate / Constants.JULIAN_YEAR, station);
  78.         }
  79.     };

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public boolean test(final SinexParseInfo parseInfo) {
  83.         if (name().equals(parseInfo.parseString(7, 6))) {
  84.             // this is the data type we are concerned with
  85.             store(parseInfo, parseInfo.parseDouble(47, 22),
  86.                   parseInfo.getCurrentLineStation(14),
  87.                   parseInfo.stringEpochToAbsoluteDate(parseInfo.parseString(27, 12), false));
  88.             return true;
  89.         } else {
  90.             // it is a data type for another predicate
  91.             return false;
  92.         }
  93.     }

  94.     /** Store parsed fields.
  95.      * @param parseInfo  container for parse info
  96.      * @param coordinate station coordinate
  97.      * @param station    station
  98.      * @param epoch      current epoch
  99.      */
  100.     protected abstract void store(SinexParseInfo parseInfo, double coordinate, Station station, AbsoluteDate epoch);

  101. }