TimeStampedPair.java

  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. import org.orekit.errors.OrekitIllegalArgumentException;
  19. import org.orekit.errors.OrekitMessages;

  20. /**
  21.  * Pair of time stamped values being defined at the same date.
  22.  *
  23.  * @param <K> first time stamped value
  24.  * @param <V> second time stamped value
  25.  *
  26.  * @author Vincent Cucchietti
  27.  * @see TimeStamped
  28.  */
  29. public class TimeStampedPair<K extends TimeStamped, V extends TimeStamped> implements TimeStamped {

  30.     /** Default date equality threshold of 1 ns. */
  31.     public static final double DEFAULT_DATE_EQUALITY_THRESHOLD = 1e-9;

  32.     /** First time stamped value. */
  33.     private final K first;

  34.     /** Second time stamped value. */
  35.     private final V second;

  36.     /**
  37.      * Constructor.
  38.      * <p>
  39.      * First and second value must have the same date.
  40.      *
  41.      * @param first first time stamped value
  42.      * @param second second time stamped value
  43.      */
  44.     public TimeStampedPair(final K first, final V second) {
  45.         this(first, second, DEFAULT_DATE_EQUALITY_THRESHOLD);
  46.     }

  47.     /**
  48.      * Constructor.
  49.      * <p>
  50.      * First and second value must have the same date.
  51.      *
  52.      * @param first first time stamped value
  53.      * @param second second time stamped value
  54.      * @param dateEqualityThreshold threshold below which dates are considered equal
  55.      */
  56.     public TimeStampedPair(final K first, final V second, final double dateEqualityThreshold) {
  57.         checkDatesConsistency(first.getDate(), second.getDate(), dateEqualityThreshold);
  58.         this.first  = first;
  59.         this.second = second;
  60.     }

  61.     /**
  62.      * Check date consistency.
  63.      *
  64.      * @param firstDate first date
  65.      * @param secondDate second date
  66.      * @param dateEqualityThreshold threshold below which dates are considered equal
  67.      */
  68.     public static void checkDatesConsistency(final AbsoluteDate firstDate, final AbsoluteDate secondDate,
  69.                                              final double dateEqualityThreshold) {
  70.         if (!firstDate.isCloseTo(secondDate, dateEqualityThreshold)) {
  71.             throw new OrekitIllegalArgumentException(OrekitMessages.DATES_MISMATCH, firstDate, secondDate);
  72.         }
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public AbsoluteDate getDate() {
  77.         return first.getDate();
  78.     }

  79.     /** Get first time stamped value.
  80.      * @return first time stamped value
  81.      */
  82.     public K getFirst() {
  83.         return first;
  84.     }

  85.     /** Get second time stamped value.
  86.      * @return second time stamped value
  87.      */
  88.     public V getSecond() {
  89.         return second;
  90.     }

  91. }