PreloadedTimeScales.java

  1. /* Contributed in the public domain.
  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.time;

  18. import java.util.Collection;
  19. import java.util.concurrent.ConcurrentHashMap;
  20. import java.util.concurrent.ConcurrentMap;
  21. import java.util.function.BiFunction;

  22. import org.orekit.frames.EOPEntry;
  23. import org.orekit.frames.EOPHistory;
  24. import org.orekit.utils.IERSConventions;

  25. /**
  26.  * A set of time scales that creates most time scales when constructed. The exceptions are
  27.  * {@link #getUT1(IERSConventions, boolean)} and {@link #getGMST(IERSConventions,
  28.  * boolean)} where six different instances exist based on conventions and simple EOP
  29.  * settings.
  30.  *
  31.  * @author Evan Ward
  32.  * @since 10.1
  33.  */
  34. class PreloadedTimeScales extends AbstractTimeScales {

  35.     /** TAI time scale. */
  36.     private final TAIScale tai;
  37.     /** UTC time scale. */
  38.     private final UTCScale utc;
  39.     /** TT time scale. */
  40.     private final TTScale tt;
  41.     /** Galileo time scale. */
  42.     private final GalileoScale gst;
  43.     /** GLONASS time scale. */
  44.     private final GLONASSScale glonass;
  45.     /** QZSS time scale. */
  46.     private final QZSSScale qzss;
  47.     /** GPS time scale. */
  48.     private final GPSScale gps;
  49.     /** TCG time scale. */
  50.     private final TCGScale tcg;
  51.     /** Tdb time scale. */
  52.     private final TDBScale tdb;
  53.     /** TCB time scale. */
  54.     private final TCBScale tcb;
  55.     /** IRNSS time scale. */
  56.     private final IRNSSScale irnss;
  57.     /** BDT time scale. */
  58.     private final BDTScale bdt;
  59.     /** Provider of EOP data. */
  60.     private final BiFunction<
  61.             ? super IERSConventions,
  62.             ? super TimeScales,
  63.             ? extends Collection<? extends EOPEntry>> eopSupplier;
  64.     /** Cached EOP data. */
  65.     private final ConcurrentMap<IERSConventions, Collection<? extends EOPEntry>> eopMap;

  66.     /**
  67.      * Create a new set of time scales from the given data.
  68.      *
  69.      * @param leapSeconds for UTC.
  70.      * @param eopSupplier provides EOP for UT1.
  71.      */
  72.     PreloadedTimeScales(
  73.             final Collection<? extends OffsetModel> leapSeconds,
  74.             final BiFunction<
  75.                     ? super IERSConventions,
  76.                     ? super TimeScales,
  77.                     ? extends Collection<? extends EOPEntry>> eopSupplier) {
  78.         tai = new TAIScale();
  79.         tt = new TTScale();
  80.         gps = new GPSScale();
  81.         qzss = new QZSSScale();
  82.         gst = new GalileoScale();
  83.         irnss = new IRNSSScale();
  84.         bdt = new BDTScale();
  85.         tcg = new TCGScale(tt, tai);
  86.         utc = new UTCScale(tai, leapSeconds);
  87.         glonass = new GLONASSScale(utc);
  88.         tdb = new TDBScale(tt, getJ2000Epoch());
  89.         tcb = new TCBScale(tdb, tai);
  90.         final int n = IERSConventions.values().length;
  91.         eopMap = new ConcurrentHashMap<>(n);
  92.         this.eopSupplier = eopSupplier;
  93.     }

  94.     @Override
  95.     public TAIScale getTAI() {
  96.         return tai;
  97.     }

  98.     @Override
  99.     public UTCScale getUTC() {
  100.         return utc;
  101.     }

  102.     @Override
  103.     protected EOPHistory getEopHistory(final IERSConventions conventions,
  104.                                        final boolean simpleEOP) {
  105.         final Collection<? extends EOPEntry> data;
  106.         synchronized (this) {
  107.             data = eopMap.computeIfAbsent(conventions, c -> eopSupplier.apply(c, this));
  108.         }
  109.         return new EOPHistory(conventions, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
  110.                               data, simpleEOP, this);
  111.     }

  112.     @Override
  113.     public TTScale getTT() {
  114.         return tt;
  115.     }

  116.     @Override
  117.     public GalileoScale getGST() {
  118.         return gst;
  119.     }

  120.     @Override
  121.     public GLONASSScale getGLONASS() {
  122.         return glonass;
  123.     }

  124.     @Override
  125.     public QZSSScale getQZSS() {
  126.         return qzss;
  127.     }

  128.     @Override
  129.     public GPSScale getGPS() {
  130.         return gps;
  131.     }

  132.     @Override
  133.     public TCGScale getTCG() {
  134.         return tcg;
  135.     }

  136.     @Override
  137.     public TDBScale getTDB() {
  138.         return tdb;
  139.     }

  140.     @Override
  141.     public TCBScale getTCB() {
  142.         return tcb;
  143.     }

  144.     @Override
  145.     public IRNSSScale getIRNSS() {
  146.         return irnss;
  147.     }

  148.     @Override
  149.     public BDTScale getBDT() {
  150.         return bdt;
  151.     }

  152. }