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.HashMap;
21  import java.util.Map;
22  
23  import org.hipparchus.CalculusFieldElement;
24  import org.hipparchus.Field;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.FieldAbsoluteDate;
27  
28  /**
29  ** Transform provider using fixed transform.
30   * @author Luc Maisonobe
31   */
32  public class FixedTransformProvider implements TransformProvider {
33  
34      /** Fixed transform. */
35      private final Transform transform;
36  
37      /** Cached field-based transforms. */
38      private final transient Map<Field<? extends CalculusFieldElement<?>>, FieldTransform<? extends CalculusFieldElement<?>>> cached;
39  
40      /** Simple constructor.
41       * @param transform fixed transform
42       */
43      public FixedTransformProvider(final Transform transform) {
44          this.transform = transform;
45          this.cached    = new HashMap<>();
46      }
47  
48      /** {@inheritDoc} */
49      public Transform getTransform(final AbsoluteDate date) {
50          return transform;
51      }
52  
53      /** {@inheritDoc} */
54      @SuppressWarnings("unchecked")
55      @Override
56      public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
57          synchronized (cached) {
58              return (FieldTransform<T>) cached.computeIfAbsent(date.getField(),
59                                                              f -> new FieldTransform<>((Field<T>) f, transform));
60          }
61      }
62  
63  }