ExpungePolicy.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  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.orekit.time.AbsoluteDate;

  19. /** Expunge policy to apply when a {@link org.orekit.utils.TimeSpanMap} exceeds its capacity.
  20.  * @author Luc Maisonobe
  21.  * @since 13.1
  22.  */
  23. public enum ExpungePolicy {

  24.     /** Expunge the span before the first transition.
  25.      * <p>
  26.      * Note that if we add data to the map in reverse chronological order, then entries
  27.      * exceeding capacity are expunged as soon as we attempt to add them, so this
  28.      * policy should probably not be used in reverse chronological order.
  29.      * </p>
  30.      */
  31.     EXPUNGE_EARLIEST {
  32.         boolean expungeEarliest(final AbsoluteDate date,
  33.                                 final AbsoluteDate earliest, final AbsoluteDate latest) {
  34.             return true;
  35.         }
  36.     },

  37.     /** Expunge the span after the latest transition.
  38.      * <p>
  39.      * Note that if we add data to the map in chronological order, then entries
  40.      * exceeding capacity are expunged as soon as we attempt to add them, so this
  41.      * policy should probably not be used in chronological order.
  42.      * </p>
  43.      */
  44.     EXPUNGE_LATEST {
  45.         boolean expungeEarliest(final AbsoluteDate date,
  46.                                 final AbsoluteDate earliest, final AbsoluteDate latest) {
  47.             return false;
  48.         }
  49.     },

  50.     /** Expunge either the earliest or latest span, depending on which is farthest from the last added transition. */
  51.     EXPUNGE_FARTHEST {
  52.         boolean expungeEarliest(final AbsoluteDate date,
  53.                                 final AbsoluteDate earliest, final AbsoluteDate latest) {
  54.             return date.durationFrom(earliest) >= latest.durationFrom(date);
  55.         }
  56.     };

  57.     /** Check if data to be expunged is the earliest data.
  58.      * @param date current date
  59.      * @param earliest earliest date
  60.      * @param latest latest date
  61.      * @return true if data to be expunged is the earliest data
  62.      */
  63.     abstract boolean expungeEarliest(AbsoluteDate date, AbsoluteDate earliest, AbsoluteDate latest);

  64. }