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  
19  import java.util.Collection;
20  import java.util.concurrent.ConcurrentHashMap;
21  import java.util.concurrent.ConcurrentMap;
22  import java.util.function.BiFunction;
23  
24  import org.orekit.frames.EOPEntry;
25  import org.orekit.frames.EOPHistory;
26  import org.orekit.utils.IERSConventions;
27  
28  /**
29   * A set of time scales that creates most time scales when constructed. The exceptions are
30   * {@link #getUT1(IERSConventions, boolean)} and {@link #getGMST(IERSConventions,
31   * boolean)} where six different instances exist based on conventions and simple EOP
32   * settings.
33   *
34   * @author Evan Ward
35   * @since 10.1
36   */
37  class PreloadedTimeScales extends AbstractTimeScales {
38  
39      /** TAI time scale. */
40      private final TAIScale tai;
41      /** UTC time scale. */
42      private final UTCScale utc;
43      /** TT time scale. */
44      private final TTScale tt;
45      /** Galileo time scale. */
46      private final GalileoScale gst;
47      /** GLONASS time scale. */
48      private final GLONASSScale glonass;
49      /** QZSS time scale. */
50      private final QZSSScale qzss;
51      /** GPS time scale. */
52      private final GPSScale gps;
53      /** TCG time scale. */
54      private final TCGScale tcg;
55      /** Tdb time scale. */
56      private final TDBScale tdb;
57      /** TCB time scale. */
58      private final TCBScale tcb;
59      /** IRNSS time scale. */
60      private final IRNSSScale irnss;
61      /** BDT time scale. */
62      private final BDTScale bdt;
63      /** Provider of EOP data. */
64      private final BiFunction<
65              ? super IERSConventions,
66              ? super TimeScales,
67              ? extends Collection<? extends EOPEntry>> eopSupplier;
68      /** Cached EOP data. */
69      private final ConcurrentMap<IERSConventions, Collection<? extends EOPEntry>> eopMap;
70  
71      /**
72       * Create a new set of time scales from the given data.
73       *
74       * @param leapSeconds for UTC.
75       * @param eopSupplier provides EOP for UT1.
76       */
77      PreloadedTimeScales(
78              final Collection<? extends OffsetModel> leapSeconds,
79              final BiFunction<
80                      ? super IERSConventions,
81                      ? super TimeScales,
82                      ? extends Collection<? extends EOPEntry>> eopSupplier) {
83          tai = new TAIScale();
84          tt = new TTScale();
85          gps = new GPSScale();
86          qzss = new QZSSScale();
87          gst = new GalileoScale();
88          irnss = new IRNSSScale();
89          bdt = new BDTScale();
90          tcg = new TCGScale(tt, tai);
91          utc = new UTCScale(tai, leapSeconds);
92          glonass = new GLONASSScale(utc);
93          tdb = new TDBScale(tt, getJ2000Epoch());
94          tcb = new TCBScale(tdb, tai);
95          final int n = IERSConventions.values().length;
96          eopMap = new ConcurrentHashMap<>(n);
97          this.eopSupplier = eopSupplier;
98      }
99  
100     @Override
101     public TAIScale getTAI() {
102         return tai;
103     }
104 
105     @Override
106     public UTCScale getUTC() {
107         return utc;
108     }
109 
110     @Override
111     protected EOPHistory getEopHistory(final IERSConventions conventions,
112                                        final boolean simpleEOP) {
113         final Collection<? extends EOPEntry> data;
114         synchronized (this) {
115             data = eopMap.computeIfAbsent(conventions, c -> eopSupplier.apply(c, this));
116         }
117         return new EOPHistory(conventions, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
118                               data, simpleEOP, this);
119     }
120 
121     @Override
122     public TTScale getTT() {
123         return tt;
124     }
125 
126     @Override
127     public GalileoScale getGST() {
128         return gst;
129     }
130 
131     @Override
132     public GLONASSScale getGLONASS() {
133         return glonass;
134     }
135 
136     @Override
137     public QZSSScale getQZSS() {
138         return qzss;
139     }
140 
141     @Override
142     public GPSScale getGPS() {
143         return gps;
144     }
145 
146     @Override
147     public TCGScale getTCG() {
148         return tcg;
149     }
150 
151     @Override
152     public TDBScale getTDB() {
153         return tdb;
154     }
155 
156     @Override
157     public TCBScale getTCB() {
158         return tcb;
159     }
160 
161     @Override
162     public IRNSSScale getIRNSS() {
163         return irnss;
164     }
165 
166     @Override
167     public BDTScale getBDT() {
168         return bdt;
169     }
170 
171 }
172