1 /* Copyright 2002-2025 CS GROUP
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.orekit.errors.OrekitIllegalArgumentException;
20 import org.orekit.errors.OrekitMessages;
21
22 /**
23 * Pair of time stamped values being defined at the same date.
24 *
25 * @param <K> first time stamped value
26 * @param <V> second time stamped value
27 *
28 * @author Vincent Cucchietti
29 * @see TimeStamped
30 */
31 public class TimeStampedPair<K extends TimeStamped, V extends TimeStamped> implements TimeStamped {
32
33 /** Default date equality threshold of 1 ns. */
34 public static final double DEFAULT_DATE_EQUALITY_THRESHOLD = 1e-9;
35
36 /** First time stamped value. */
37 private final K first;
38
39 /** Second time stamped value. */
40 private final V second;
41
42 /**
43 * Constructor.
44 * <p>
45 * First and second value must have the same date.
46 *
47 * @param first first time stamped value
48 * @param second second time stamped value
49 */
50 public TimeStampedPair(final K first, final V second) {
51 this(first, second, DEFAULT_DATE_EQUALITY_THRESHOLD);
52 }
53
54 /**
55 * Constructor.
56 * <p>
57 * First and second value must have the same date.
58 *
59 * @param first first time stamped value
60 * @param second second time stamped value
61 * @param dateEqualityThreshold threshold below which dates are considered equal
62 */
63 public TimeStampedPair(final K first, final V second, final double dateEqualityThreshold) {
64 checkDatesConsistency(first.getDate(), second.getDate(), dateEqualityThreshold);
65 this.first = first;
66 this.second = second;
67 }
68
69 /**
70 * Check date consistency.
71 *
72 * @param firstDate first date
73 * @param secondDate second date
74 * @param dateEqualityThreshold threshold below which dates are considered equal
75 */
76 public static void checkDatesConsistency(final AbsoluteDate firstDate, final AbsoluteDate secondDate,
77 final double dateEqualityThreshold) {
78 if (!firstDate.isCloseTo(secondDate, dateEqualityThreshold)) {
79 throw new OrekitIllegalArgumentException(OrekitMessages.DATES_MISMATCH, firstDate, secondDate);
80 }
81 }
82
83 /** {@inheritDoc} */
84 @Override
85 public AbsoluteDate getDate() {
86 return first.getDate();
87 }
88
89 /** Get first time stamped value.
90 * @return first time stamped value
91 */
92 public K getFirst() {
93 return first;
94 }
95
96 /** Get second time stamped value.
97 * @return second time stamped value
98 */
99 public V getSecond() {
100 return second;
101 }
102
103 }