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
18 package org.orekit.frames;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.orekit.time.AbsoluteDate;
24 import org.orekit.utils.GenericTimeStampedCache;
25 import org.orekit.utils.TimeStampedGenerator;
26
27 /** Generator to use transforms in {@link GenericTimeStampedCache}.
28 * @see GenericTimeStampedCache
29 * @since 9.0
30 * @author Luc Maisonobe
31 */
32 public class TransformGenerator implements TimeStampedGenerator<Transform> {
33
34 /** Number of neighbors. */
35 private final int neighborsSize;
36
37 /** Underlying provider. */
38 private final TransformProvider provider;
39
40 /** Step size. */
41 private final double step;
42
43 /** simple constructor.
44 * @param neighborsSize number of neighbors
45 * @param provider underlying provider
46 * @param step step size
47 */
48 public TransformGenerator(final int neighborsSize,
49 final TransformProvider provider,
50 final double step) {
51 this.neighborsSize = neighborsSize;
52 this.provider = provider;
53 this.step = step;
54 }
55
56 /** {@inheritDoc} */
57 public List<Transform> generate(final AbsoluteDate existingDate, final AbsoluteDate date) {
58
59 final List<Transform> generated = new ArrayList<>();
60
61 if (existingDate == null) {
62
63 // no prior existing transforms, just generate a first one
64 for (int i = 0; i < neighborsSize; ++i) {
65 generated.add(provider.getTransform(date.shiftedBy(i * step)));
66 }
67
68 } else {
69
70 // some transforms have already been generated
71 // add the missing ones up to specified date
72 AbsoluteDate t = existingDate;
73 if (date.compareTo(t) > 0) {
74 // forward generation
75 do {
76 t = t.shiftedBy(step);
77 generated.add(generated.size(), provider.getTransform(t));
78 } while (t.compareTo(date) <= 0);
79 } else {
80 // backward generation
81 do {
82 t = t.shiftedBy(-step);
83 generated.add(0, provider.getTransform(t));
84 } while (t.compareTo(date) >= 0);
85 }
86
87 }
88
89 // return the generated transforms
90 return generated;
91
92 }
93
94 }