1 /* Copyright 2022-2025 Thales Alenia Space
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 org.hipparchus.CalculusFieldElement;
20 import org.orekit.errors.OrekitException;
21 import org.orekit.errors.OrekitMessages;
22 import org.orekit.utils.TimeSpanMap;
23
24 /** Offset clock model aggregating several other clock models.
25 * @author Luc Maisonobe
26 * @since 12.1
27 */
28 public class AggregatedClockModel implements ClockModel {
29
30 /** Underlying clock models. */
31 private final TimeSpanMap<ClockModel> models;
32
33 /** Simple constructor.
34 * @param models underlying clock models
35 */
36 public AggregatedClockModel(final TimeSpanMap<ClockModel> models) {
37 this.models = models;
38 }
39
40 /** Get the underlying models.
41 * @return underlying models
42 */
43 public TimeSpanMap<ClockModel> getModels() {
44 return models;
45 }
46
47 /** {@inheritDoc} */
48 @Override
49 public AbsoluteDate getValidityStart() {
50 return models.getFirstNonNullSpan().getStart();
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public AbsoluteDate getValidityEnd() {
56 return models.getLastNonNullSpan().getEnd();
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public ClockOffset getOffset(final AbsoluteDate date) {
62 return getModel(date).getOffset(date);
63 }
64
65 /** {@inheritDoc} */
66 @Override
67 public <T extends CalculusFieldElement<T>> FieldClockOffset<T> getOffset(final FieldAbsoluteDate<T> date) {
68 return getModel(date.toAbsoluteDate()).getOffset(date);
69 }
70
71 /** Get the model valid at specified date.
72 * @param date date for which model is requested
73 * @return clock model valid at date
74 */
75 private ClockModel getModel(final AbsoluteDate date) {
76 final ClockModel clockModel = models.get(date);
77 if (clockModel == null) {
78 // this may happen if map is limited or not contiguous
79 // typically for models retrieved from SP3Ephemeris
80 throw new OrekitException(OrekitMessages.NO_DATA_GENERATED, date);
81 }
82 return clockModel;
83 }
84
85 }