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
19 import org.orekit.time.AbsoluteDate;
20
21 /** Expunge policy to apply when a {@link org.orekit.utils.TimeSpanMap} exceeds its capacity.
22 * @author Luc Maisonobe
23 * @since 13.1
24 */
25 public enum ExpungePolicy {
26
27 /** Expunge the span before the first transition.
28 * <p>
29 * Note that if we add data to the map in reverse chronological order, then entries
30 * exceeding capacity are expunged as soon as we attempt to add them, so this
31 * policy should probably not be used in reverse chronological order.
32 * </p>
33 */
34 EXPUNGE_EARLIEST {
35 boolean expungeEarliest(final AbsoluteDate date,
36 final AbsoluteDate earliest, final AbsoluteDate latest) {
37 return true;
38 }
39 },
40
41 /** Expunge the span after the latest transition.
42 * <p>
43 * Note that if we add data to the map in chronological order, then entries
44 * exceeding capacity are expunged as soon as we attempt to add them, so this
45 * policy should probably not be used in chronological order.
46 * </p>
47 */
48 EXPUNGE_LATEST {
49 boolean expungeEarliest(final AbsoluteDate date,
50 final AbsoluteDate earliest, final AbsoluteDate latest) {
51 return false;
52 }
53 },
54
55 /** Expunge either the earliest or latest span, depending on which is farthest from the last added transition. */
56 EXPUNGE_FARTHEST {
57 boolean expungeEarliest(final AbsoluteDate date,
58 final AbsoluteDate earliest, final AbsoluteDate latest) {
59 return date.durationFrom(earliest) >= latest.durationFrom(date);
60 }
61 };
62
63 /** Check if data to be expunged is the earliest data.
64 * @param date current date
65 * @param earliest earliest date
66 * @param latest latest date
67 * @return true if data to be expunged is the earliest data
68 */
69 abstract boolean expungeEarliest(AbsoluteDate date, AbsoluteDate earliest, AbsoluteDate latest);
70
71 }