1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.frames;
18
19 import org.orekit.time.AbsoluteDate;
20
21 import java.util.LinkedHashMap;
22 import java.util.Map;
23 import java.util.concurrent.locks.ReentrantLock;
24 import java.util.function.Function;
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public class CachedTransformProvider {
39
40
41 private final Frame origin;
42
43
44 private final Frame destination;
45
46
47 private final int cacheSize;
48
49
50 private final Function<AbsoluteDate, Transform> fullGenerator;
51
52
53 private final Function<AbsoluteDate, KinematicTransform> kinematicGenerator;
54
55
56 private final Function<AbsoluteDate, StaticTransform> staticGenerator;
57
58
59 private final ReentrantLock lock;
60
61
62 private final Map<AbsoluteDate, Transform> fullCache;
63
64
65 private final Map<AbsoluteDate, KinematicTransform> kinematicCache;
66
67
68 private final Map<AbsoluteDate, StaticTransform> staticCache;
69
70
71
72
73
74
75
76
77
78 public CachedTransformProvider(final Frame origin, final Frame destination,
79 final Function<AbsoluteDate, Transform> fullGenerator,
80 final Function<AbsoluteDate, KinematicTransform> kinematicGenerator,
81 final Function<AbsoluteDate, StaticTransform> staticGenerator,
82 final int cacheSize) {
83
84 this.origin = origin;
85 this.destination = destination;
86 this.cacheSize = cacheSize;
87 this.fullGenerator = fullGenerator;
88 this.kinematicGenerator = kinematicGenerator;
89 this.staticGenerator = staticGenerator;
90 this.lock = new ReentrantLock();
91
92
93 this.fullCache = new LinkedHashMap<AbsoluteDate, Transform>(cacheSize, 0.75f, true) {
94
95 @Override
96 protected boolean removeEldestEntry(final Map.Entry<AbsoluteDate, Transform> eldest) {
97 return size() > cacheSize;
98 }
99 };
100
101
102 this.kinematicCache = new LinkedHashMap<AbsoluteDate, KinematicTransform>(cacheSize, 0.75f, true) {
103
104 @Override
105 protected boolean removeEldestEntry(final Map.Entry<AbsoluteDate, KinematicTransform> eldest) {
106 return size() > cacheSize;
107 }
108 };
109
110
111 this.staticCache = new LinkedHashMap<AbsoluteDate, StaticTransform>(cacheSize, 0.75f, true) {
112
113 @Override
114 protected boolean removeEldestEntry(final Map.Entry<AbsoluteDate, StaticTransform> eldest) {
115 return size() > cacheSize;
116 }
117 };
118
119 }
120
121
122
123
124 public Frame getOrigin() {
125 return origin;
126 }
127
128
129
130
131 public Frame getDestination() {
132 return destination;
133 }
134
135
136
137
138 public int getCacheSize() {
139 return cacheSize;
140 }
141
142
143
144
145
146 public Transform getTransform(final AbsoluteDate date) {
147 lock.lock();
148 try {
149 return fullCache.computeIfAbsent(date, fullGenerator);
150 } finally {
151 lock.unlock();
152 }
153 }
154
155
156
157
158
159 public KinematicTransform getKinematicTransform(final AbsoluteDate date) {
160 lock.lock();
161 try {
162 return kinematicCache.computeIfAbsent(date, kinematicGenerator);
163 } finally {
164 lock.unlock();
165 }
166 }
167
168
169
170
171
172 public StaticTransform getStaticTransform(final AbsoluteDate date) {
173 lock.lock();
174 try {
175 return staticCache.computeIfAbsent(date, staticGenerator);
176 } finally {
177 lock.unlock();
178 }
179 }
180
181 }