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         return new EOPHistory(conventions, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
114                               eopMap.computeIfAbsent(conventions, c -> eopSupplier.apply(c, this)),
115                               simpleEOP,
116                               this);
117     }
118 
119     @Override
120     public TTScale getTT() {
121         return tt;
122     }
123 
124     @Override
125     public GalileoScale getGST() {
126         return gst;
127     }
128 
129     @Override
130     public GLONASSScale getGLONASS() {
131         return glonass;
132     }
133 
134     @Override
135     public QZSSScale getQZSS() {
136         return qzss;
137     }
138 
139     @Override
140     public GPSScale getGPS() {
141         return gps;
142     }
143 
144     @Override
145     public TCGScale getTCG() {
146         return tcg;
147     }
148 
149     @Override
150     public TDBScale getTDB() {
151         return tdb;
152     }
153 
154     @Override
155     public TCBScale getTCB() {
156         return tcb;
157     }
158 
159     @Override
160     public IRNSSScale getIRNSS() {
161         return irnss;
162     }
163 
164     @Override
165     public BDTScale getBDT() {
166         return bdt;
167     }
168 
169 }
170