1   /* Copyright 2022-2026 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.clocks;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.orekit.time.FieldAbsoluteDate;
21  import org.orekit.time.FieldTimeStamped;
22  
23  /** Container for time stamped clock offset.
24   * @param <T> type of the field elements
25   * @author Luc Maisonobe
26   * @since 12.1
27   */
28  public class FieldClockOffset<T extends CalculusFieldElement<T>> implements FieldTimeStamped<T> {
29  
30      /** Date. */
31      private final FieldAbsoluteDate<T> date;
32  
33      /** Clock bias. */
34      private final T bias;
35  
36      /** Clock rate. */
37      private final T rate;
38  
39      /** Clock acceleration. */
40      private final T acceleration;
41  
42      /** Simple constructor.
43       * @param date         date
44       * @param bias         clock bias
45       * @param rate         clock rate (can be set to {@code null} if unknown)
46       * @param acceleration clock acceleration (can be set to {@code null} if unknown)
47       */
48      public FieldClockOffset(final FieldAbsoluteDate<T> date, final T bias,
49                              final T rate, final T acceleration) {
50          this.date         = date;
51          this.bias         = bias;
52          this.rate         = rate;
53          this.acceleration = acceleration;
54      }
55  
56      /** Add another offset to the instance.
57       * <p>
58       * The instance is not modified, a new instance is created
59       * </p>
60       * @param other offset to add (date part will be ignored)
61       * @return instance + other, at instance date
62       * @since 14.0
63       */
64      public FieldClockOffset<T> add(final FieldClockOffset<T> other) {
65          return new FieldClockOffset<>(date,
66                                        bias.add(other.bias),
67                                        rate.add(other.rate),
68                                        acceleration.add(other.acceleration));
69      }
70  
71      /** Subtract another offset from the instance.
72       * <p>
73       * The instance is not modified, a new instance is created
74       * </p>
75       * @param other offset to subtract (date part will be ignored)
76       * @return instance - other, at instance date
77       * @since 14.0
78       */
79      public FieldClockOffset<T> subtract(final FieldClockOffset<T> other) {
80          return new FieldClockOffset<>(date,
81                                        bias.subtract(other.bias),
82                                        rate.subtract(other.rate),
83                                        acceleration.subtract(other.acceleration));
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public FieldAbsoluteDate<T> getDate() {
89          return date;
90      }
91  
92      /** Get bias.
93       * @return bias
94       */
95      public T getBias() {
96          return bias;
97      }
98  
99      /** Get rate.
100      * @return rate ({@code null} if unknown)
101      */
102     public T getRate() {
103         return rate;
104     }
105 
106     /** Get acceleration.
107      * @return acceleration ({@code null} if unknown)
108      */
109     public T getAcceleration() {
110         return acceleration;
111     }
112 
113 }