TransformGenerator.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.frames;

  18. import java.util.ArrayList;
  19. import java.util.List;

  20. import org.orekit.time.AbsoluteDate;
  21. import org.orekit.utils.GenericTimeStampedCache;
  22. import org.orekit.utils.TimeStampedGenerator;

  23. /** Generator to use transforms in {@link GenericTimeStampedCache}.
  24.  * @see GenericTimeStampedCache
  25.  * @since 9.0
  26.  * @author Luc Maisonobe
  27.  */
  28. public class TransformGenerator implements TimeStampedGenerator<Transform> {

  29.     /** Number of neighbors. */
  30.     private int neighborsSize;

  31.     /** Underlying provider. */
  32.     private final TransformProvider provider;

  33.     /** Step size. */
  34.     private final double step;

  35.     /** simple constructor.
  36.      * @param neighborsSize number of neighbors
  37.      * @param provider underlying provider
  38.      * @param step step size
  39.      */
  40.     public TransformGenerator(final int neighborsSize,
  41.                               final TransformProvider provider,
  42.                               final double step) {
  43.         this.neighborsSize = neighborsSize;
  44.         this.provider      = provider;
  45.         this.step          = step;
  46.     }

  47.     /** {@inheritDoc} */
  48.     public List<Transform> generate(final AbsoluteDate existingDate, final AbsoluteDate date) {

  49.         final List<Transform> generated = new ArrayList<>();

  50.         if (existingDate == null) {

  51.             // no prior existing transforms, just generate a first one
  52.             for (int i = 0; i < neighborsSize; ++i) {
  53.                 generated.add(provider.getTransform(date.shiftedBy(i * step)));
  54.             }

  55.         } else {

  56.             // some transforms have already been generated
  57.             // add the missing ones up to specified date
  58.             AbsoluteDate t = existingDate;
  59.             if (date.compareTo(t) > 0) {
  60.                 // forward generation
  61.                 do {
  62.                     t = t.shiftedBy(step);
  63.                     generated.add(generated.size(), provider.getTransform(t));
  64.                 } while (t.compareTo(date) <= 0);
  65.             } else {
  66.                 // backward generation
  67.                 do {
  68.                     t = t.shiftedBy(-step);
  69.                     generated.add(0, provider.getTransform(t));
  70.                 } while (t.compareTo(date) >= 0);
  71.             }

  72.         }

  73.         // return the generated transforms
  74.         return generated;

  75.     }

  76. }