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