1 /* Copyright 2002-2019 CS Systèmes d'Information
2 * Licensed to CS Systèmes d'Information (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.io.Serializable;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.hipparchus.Field;
25 import org.hipparchus.RealFieldElement;
26 import org.orekit.time.AbsoluteDate;
27 import org.orekit.time.FieldAbsoluteDate;
28
29 /**
30 ** Transform provider using fixed transform.
31 * @author Luc Maisonobe
32 */
33 public class FixedTransformProvider implements TransformProvider {
34
35 /** Serializable UID. */
36 private static final long serialVersionUID = 20170106L;
37
38 /** Fixed transform. */
39 private final Transform transform;
40
41 /** Cached field-based transforms. */
42 private final transient Map<Field<? extends RealFieldElement<?>>, FieldTransform<? extends RealFieldElement<?>>> cached;
43
44 /** Simple constructor.
45 * @param transform fixed transform
46 */
47 public FixedTransformProvider(final Transform transform) {
48 this.transform = transform;
49 this.cached = new HashMap<>();
50 }
51
52 /** {@inheritDoc} */
53 public Transform getTransform(final AbsoluteDate date) {
54 return transform;
55 }
56
57 /** {@inheritDoc} */
58 @Override
59 public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
60
61 @SuppressWarnings("unchecked")
62 FieldTransform<T> ft = (FieldTransform<T>) cached.get(date.getField());
63 if (ft == null) {
64 ft = new FieldTransform<>(date.getField(), transform);
65 cached.put(date.getField(), ft);
66 }
67
68 return ft;
69
70 }
71
72 /** Replace the instance with a data transfer object for serialization.
73 * <p>
74 * This intermediate class serializes nothing.
75 * </p>
76 * @return data transfer object that will be serialized
77 */
78 private Object writeReplace() {
79 return new DataTransferObject(transform);
80 }
81
82 /** Internal class used only for serialization. */
83 private static class DataTransferObject implements Serializable {
84
85 /** Serializable UID. */
86 private static final long serialVersionUID = 20170106L;
87
88 /** Fixed transform. */
89 private final Transform transform;
90
91 /** Simple constructor.
92 * @param transform fixed transform
93 */
94 private DataTransferObject(final Transform transform) {
95 this.transform = transform;
96 }
97
98 /** Replace the deserialized data transfer object with a {@link FixedTransformProvider}.
99 * @return replacement {@link FixedTransformProvider}
100 */
101 private Object readResolve() {
102 return new FixedTransformProvider(transform);
103 }
104
105 }
106
107 }