1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.javafx.runtime.sequence; |
27 | |
|
28 | |
import com.sun.javafx.runtime.location.*; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class BoundSequences { |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public static <T> SequenceLocation<T> concatenate(Class<T> clazz, SequenceLocation<? extends T>... locations) { |
43 | 0 | return new BoundCompositeSequence<T>(clazz, locations); |
44 | |
} |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public static <T> SequenceLocation<T> concatenate(Class<T> clazz, SequenceLocation<? extends T>[] locations, int size) { |
53 | 38 | return new BoundCompositeSequence<T>(clazz, locations, size); |
54 | |
} |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@SuppressWarnings("unchecked") |
63 | |
public static <T, V extends T> SequenceLocation<T> upcast(Class<T> clazz, SequenceLocation<V> location) { |
64 | 0 | Class<V> vClass = location.getAsSequence().getElementType(); |
65 | 0 | if (clazz == vClass) |
66 | 0 | return (SequenceLocation<T>) location; |
67 | 0 | else if (!clazz.isAssignableFrom(vClass)) |
68 | 0 | throw new ClassCastException("Cannot upcast Sequence<" + vClass.getName() |
69 | |
+ "> to Sequence<" + clazz.getName() + ">"); |
70 | |
else |
71 | 0 | return new BoundUpcastSequence<T, V>(clazz, location); |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public static<T> SequenceLocation<T> reverse(SequenceLocation<T> sequence) { |
79 | 1 | return new BoundReverseSequence<T>(sequence); |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public static<T, V extends T> SequenceLocation<T> singleton(Class<T> clazz, ObjectLocation<V> location) { |
87 | 665 | return new BoundSingletonSequence<T, V>(clazz, location); |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public static<T> SequenceLocation<Integer> singleton(IntLocation location) { |
95 | 0 | return new BoundSingletonSequence<Integer, Integer>(Integer.class, location); |
96 | |
} |
97 | |
|
98 | |
public static<T> SequenceLocation<T> empty(final Class<T> clazz) { |
99 | 486 | return new AbstractBoundSequence<T>(clazz) { |
100 | 486 | { setInitialValue(Sequences.emptySequence(clazz)); } |
101 | |
}; |
102 | |
} |
103 | |
|
104 | |
public static<T> ObjectLocation<T> element(SequenceLocation<T> sequence, IntLocation index) { |
105 | 1 | return new BoundSequenceElement<T>(sequence, index); |
106 | |
} |
107 | |
|
108 | |
public static IntLocation element(SequenceLocation<Integer> sequence, IntLocation index) { |
109 | 9 | return Locations.asIntLocation(new BoundSequenceElement<Integer>(sequence, index)); |
110 | |
} |
111 | |
|
112 | |
public static DoubleLocation element(SequenceLocation<Double> sequence, IntLocation index) { |
113 | 0 | return Locations.asDoubleLocation(new BoundSequenceElement<Double>(sequence, index)); |
114 | |
} |
115 | |
|
116 | |
public static BooleanLocation element(SequenceLocation<Boolean> sequence, IntLocation index) { |
117 | 0 | return Locations.asBooleanLocation(new BoundSequenceElement<Boolean>(sequence, index)); |
118 | |
} |
119 | |
|
120 | |
public static<T> IntLocation sizeof(final SequenceLocation<T> sequence) { |
121 | 1 | return IntVariable.make(new IntBindingExpression() { |
122 | |
public int computeValue() { |
123 | 3 | return Sequences.size(sequence.get()); |
124 | |
} |
125 | |
}, sequence); |
126 | |
} |
127 | |
|
128 | |
public static<T> IntLocation sizeof(final ObjectLocation<T> item) { |
129 | 0 | return IntVariable.make(new IntBindingExpression() { |
130 | |
public int computeValue() { |
131 | 0 | return item.get() == null ? 0 : 1; |
132 | |
} |
133 | |
}, item); |
134 | |
} |
135 | |
|
136 | |
public static SequenceLocation<Integer> range(IntLocation a, IntLocation b) { |
137 | 34 | return new BoundIntRangeSequence(a, b); |
138 | |
} |
139 | |
|
140 | |
public static SequenceLocation<Integer> range(IntLocation a, IntLocation b, IntLocation step) { |
141 | 6 | return new BoundIntRangeSequence(a, b, step); |
142 | |
} |
143 | |
|
144 | |
public static SequenceLocation<Integer> range(IntLocation a, IntLocation b, boolean exclusive) { |
145 | 4 | return new BoundIntRangeSequence(a, b, exclusive); |
146 | |
} |
147 | |
|
148 | |
public static SequenceLocation<Integer> range(IntLocation a, IntLocation b, IntLocation step, boolean exclusive) { |
149 | 5 | return new BoundIntRangeSequence(a, b, step, exclusive); |
150 | |
} |
151 | |
|
152 | |
|
153 | |
public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b) { |
154 | 1 | return new BoundNumberRangeSequence(a, b); |
155 | |
} |
156 | |
|
157 | |
public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b, DoubleLocation step) { |
158 | 0 | return new BoundNumberRangeSequence(a, b, step); |
159 | |
} |
160 | |
|
161 | |
public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b, boolean exclusive) { |
162 | 1 | return new BoundNumberRangeSequence(a, b, exclusive); |
163 | |
} |
164 | |
|
165 | |
public static SequenceLocation<Double> range(DoubleLocation a, DoubleLocation b, DoubleLocation step, boolean exclusive) { |
166 | 1 | return new BoundNumberRangeSequence(a, b, step, exclusive); |
167 | |
} |
168 | |
|
169 | |
public static<T> SequenceLocation<T> slice(Class<T> clazz, SequenceLocation<T> sequence, IntLocation a, IntLocation b) { |
170 | 5 | return new BoundSequenceSlice<T>(clazz, sequence, a, b, false); |
171 | |
} |
172 | |
|
173 | |
public static<T> SequenceLocation<T> sliceExclusive(Class<T> clazz, SequenceLocation<T> sequence, IntLocation a, IntLocation b) { |
174 | 3 | return new BoundSequenceSlice<T>(clazz, sequence, a, b, true); |
175 | |
} |
176 | |
|
177 | |
public interface ObjectSimpleBoundComprehensionCallback<T, V> { |
178 | |
V computeElement$(T element, int index); |
179 | |
} |
180 | |
|
181 | |
public interface IntSimpleBoundComprehensionCallback<V> { |
182 | |
V computeElement$(int element, int index); |
183 | |
} |
184 | |
|
185 | |
public interface DoubleSimpleBoundComprehensionCallback<V> { |
186 | |
V computeElement$(double element, int index); |
187 | |
} |
188 | |
|
189 | |
public interface BooleanSimpleBoundComprehensionCallback<V> { |
190 | |
V computeElement$(boolean element, int index); |
191 | |
} |
192 | |
|
193 | |
public static<T, V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz, |
194 | |
SequenceLocation<T> seq, |
195 | |
boolean useIndex, |
196 | |
final ObjectSimpleBoundComprehensionCallback<T, V> callback) { |
197 | 0 | return new SimpleBoundComprehension<T, V>(clazz, seq, useIndex) { |
198 | |
protected V computeElement$(T element, int index) { |
199 | 0 | return callback.computeElement$(element, index); |
200 | |
} |
201 | |
}; |
202 | |
} |
203 | |
|
204 | |
public static<V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz, |
205 | |
SequenceLocation<Integer> seq, |
206 | |
boolean useIndex, |
207 | |
final IntSimpleBoundComprehensionCallback<V> callback) { |
208 | 5 | return new SimpleBoundComprehension<Integer, V>(clazz, seq, useIndex) { |
209 | |
protected V computeElement$(Integer element, int index) { |
210 | 37 | return callback.computeElement$(element, index); |
211 | |
} |
212 | |
}; |
213 | |
} |
214 | |
|
215 | |
public static<V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz, |
216 | |
SequenceLocation<Double> seq, |
217 | |
boolean useIndex, |
218 | |
final DoubleSimpleBoundComprehensionCallback<V> callback) { |
219 | 0 | return new SimpleBoundComprehension<Double, V>(clazz, seq, useIndex) { |
220 | |
protected V computeElement$(Double element, int index) { |
221 | 0 | return callback.computeElement$(element, index); |
222 | |
} |
223 | |
}; |
224 | |
} |
225 | |
|
226 | |
public static<V> SequenceLocation<V> makeSimpleBoundComprehension(Class<V> clazz, |
227 | |
SequenceLocation<Boolean> seq, |
228 | |
boolean useIndex, |
229 | |
final BooleanSimpleBoundComprehensionCallback<V> callback) { |
230 | 0 | return new SimpleBoundComprehension<Boolean, V>(clazz, seq, useIndex) { |
231 | |
protected V computeElement$(Boolean element, int index) { |
232 | 0 | return callback.computeElement$(element, index); |
233 | |
} |
234 | |
}; |
235 | |
} |
236 | |
|
237 | |
public interface ObjectBoundComprehensionCallback<T, V> { |
238 | |
SequenceLocation<V> computeElements$(ObjectLocation<T> elementLocation, IntLocation indexLocation); |
239 | |
} |
240 | |
|
241 | |
public interface IntBoundComprehensionCallback<T> { |
242 | |
SequenceLocation<T> computeElements$(IntLocation elementLocation, IntLocation indexLocation); |
243 | |
} |
244 | |
|
245 | |
public interface DoubleBoundComprehensionCallback<T> { |
246 | |
SequenceLocation<T> computeElements$(DoubleLocation elementLocation, IntLocation indexLocation); |
247 | |
} |
248 | |
|
249 | 0 | public interface BooleanBoundComprehensionCallback<T> { |
250 | |
SequenceLocation<T> computeElements$(BooleanLocation elementLocation, IntLocation indexLocation); |
251 | |
} |
252 | |
|
253 | |
public static<T, V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz, |
254 | |
SequenceLocation<T> sequenceLocation, |
255 | |
boolean useIndex, |
256 | |
final ObjectBoundComprehensionCallback<T, V> callback) { |
257 | 0 | return new AbstractBoundComprehension<T, ObjectLocation<T>, V>(clazz, sequenceLocation, useIndex) { |
258 | |
protected ObjectLocation<T> makeInductionLocation(T value) { |
259 | 0 | return ObjectVariable.<T>make(value); |
260 | |
} |
261 | |
|
262 | |
protected SequenceLocation<V> computeElements$(ObjectLocation<T> elementLocation, IntLocation indexLocation) { |
263 | 0 | return callback.computeElements$(elementLocation, indexLocation); |
264 | |
} |
265 | |
}; |
266 | |
} |
267 | |
|
268 | |
public static<V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz, |
269 | |
SequenceLocation<Integer> sequenceLocation, |
270 | |
boolean useIndex, |
271 | |
final IntBoundComprehensionCallback<V> callback) { |
272 | 105 | return new AbstractBoundComprehension<Integer, IntLocation, V>(clazz, sequenceLocation, useIndex) { |
273 | |
protected IntLocation makeInductionLocation(Integer value) { |
274 | 48 | return IntVariable.make(value); |
275 | |
} |
276 | |
|
277 | |
protected SequenceLocation<V> computeElements$(IntLocation elementLocation, IntLocation indexLocation) { |
278 | 48 | return callback.computeElements$(elementLocation, indexLocation); |
279 | |
} |
280 | |
}; |
281 | |
} |
282 | |
|
283 | |
public static<V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz, |
284 | |
SequenceLocation<Double> sequenceLocation, |
285 | |
boolean useIndex, |
286 | |
final DoubleBoundComprehensionCallback<V> callback) { |
287 | 0 | return new AbstractBoundComprehension<Double, DoubleLocation, V>(clazz, sequenceLocation, useIndex) { |
288 | |
protected DoubleLocation makeInductionLocation(Double value) { |
289 | 0 | return DoubleVariable.make(value); |
290 | |
} |
291 | |
|
292 | |
protected SequenceLocation<V> computeElements$(DoubleLocation elementLocation, IntLocation indexLocation) { |
293 | 0 | return callback.computeElements$(elementLocation, indexLocation); |
294 | |
} |
295 | |
}; |
296 | |
} |
297 | |
|
298 | |
public static<V> SequenceLocation<V> makeBoundComprehension(Class<V> clazz, |
299 | |
SequenceLocation<Boolean> sequenceLocation, |
300 | |
boolean useIndex, |
301 | |
final BooleanBoundComprehensionCallback<V> callback) { |
302 | 0 | return new AbstractBoundComprehension<Boolean, BooleanLocation, V>(clazz, sequenceLocation, useIndex) { |
303 | |
protected BooleanLocation makeInductionLocation(Boolean value) { |
304 | 0 | return BooleanVariable.make(value); |
305 | |
} |
306 | |
|
307 | |
protected SequenceLocation<V> computeElements$(BooleanLocation elementLocation, IntLocation indexLocation) { |
308 | 0 | return callback.computeElements$(elementLocation, indexLocation); |
309 | |
} |
310 | |
}; |
311 | |
} |
312 | |
|
313 | |
} |