FieldTimeStampedCache.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.utils;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.time.FieldAbsoluteDate;
  20. import org.orekit.time.FieldTimeStamped;

  21. import java.util.stream.Stream;

  22. /**
  23.  * Interface for a data structure that can provide concurrent access to {@link FieldTimeStamped} data surrounding a given
  24.  * date.
  25.  *
  26.  * @param <T> the type of data
  27.  * @param <KK> type of the field element
  28.  *
  29.  * @author Luc Maisonobe
  30.  * @author Evan Ward
  31.  * @author Vincent Cucchietti
  32.  * @see ImmutableFieldTimeStampedCache
  33.  */
  34. public interface FieldTimeStampedCache<T extends FieldTimeStamped<KK>, KK extends CalculusFieldElement<KK>> {

  35.     /**
  36.      * Get the entries surrounding a central date.
  37.      * <p>
  38.      * If the central date is well within covered range, the returned array will be balanced with half the points before
  39.      * central date and half the points after it (depending on n parity, of course). If the central date is near the
  40.      * boundary, then the returned array will be unbalanced and will contain only the n earliest (or latest) entries. A
  41.      * typical example of the later case is leap seconds cache, since the number of leap seconds cannot be arbitrarily
  42.      * increased.
  43.      * <p>
  44.      * This method is safe for multiple threads to execute concurrently.
  45.      *
  46.      * @param central central date
  47.      *
  48.      * @return list of cached entries surrounding the specified date. The size of the list is guaranteed to be
  49.      * {@link #getMaxNeighborsSize()}.
  50.      */
  51.     default Stream<T> getNeighbors(FieldAbsoluteDate<KK> central) {
  52.         return getNeighbors(central, getMaxNeighborsSize());
  53.     }

  54.     /**
  55.      * Get the entries surrounding a central date.
  56.      * <p>
  57.      * If the central date is well within covered range, the returned array will be balanced with half the points before
  58.      * central date and half the points after it (depending on n parity, of course). If the central date is near the
  59.      * boundary, then the returned array will be unbalanced and will contain only the n earliest (or latest) entries. A
  60.      * typical example of the later case is leap seconds cache, since the number of leap seconds cannot be arbitrarily
  61.      * increased.
  62.      * <p>
  63.      * This method is safe for multiple threads to execute concurrently.
  64.      *
  65.      * @param central central date
  66.      * @param n number of neighbors (cannot exceed {@link #getMaxNeighborsSize()})
  67.      *
  68.      * @return list of cached entries surrounding the specified date. The size of the list is guaranteed to be
  69.      * {@link #getMaxNeighborsSize()}.
  70.      * @since 12.1
  71.      */
  72.     Stream<T> getNeighbors(FieldAbsoluteDate<KK> central, int n);

  73.     /**
  74.      * Get the fixed size of the lists returned by {@link #getNeighbors(FieldAbsoluteDate)}.
  75.      *
  76.      * @return size of the list
  77.      */
  78.     int getMaxNeighborsSize();

  79.     /**
  80.      * Get the earliest entry in this cache.
  81.      *
  82.      * @return earliest cached entry
  83.      *
  84.      * @throws IllegalStateException if this cache is empty
  85.      */
  86.     T getEarliest()
  87.             throws IllegalStateException;

  88.     /**
  89.      * Get the latest entry in this cache.
  90.      *
  91.      * @return latest cached entry
  92.      *
  93.      * @throws IllegalStateException if this cache is empty
  94.      */
  95.     T getLatest()
  96.             throws IllegalStateException;
  97. }