TimeStampedCache.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 java.util.stream.Stream;

  19. import org.orekit.time.AbsoluteDate;
  20. import org.orekit.time.TimeStamped;

  21. /**
  22.  * Interface for a data structure that can provide concurrent access to
  23.  * {@link TimeStamped} data surrounding a given date.
  24.  *
  25.  * @author Luc Maisonobe
  26.  * @author Evan Ward
  27.  * @param <T> the type of data
  28.  * @see GenericTimeStampedCache
  29.  * @see ImmutableTimeStampedCache
  30.  */
  31. public interface TimeStampedCache<T extends TimeStamped> {

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

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

  72.     /**
  73.      * Get the maximum size of the lists returned by
  74.      * {@link #getNeighbors(AbsoluteDate, int)}.
  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.      * @throws IllegalStateException if this cache is empty
  84.      */
  85.     T getEarliest()
  86.         throws IllegalStateException;

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

  95. }