0
|
1 package fj;
|
|
2
|
|
3 /**
|
|
4 * Functions that convert between Java primitive types.
|
|
5 *
|
|
6 * @version %build.number%
|
|
7 */
|
|
8 public final class Primitive {
|
|
9 private Primitive() {
|
|
10 throw new UnsupportedOperationException();
|
|
11 }
|
|
12
|
|
13 // BEGIN Boolean ->
|
|
14
|
|
15 /**
|
|
16 * A function that converts booleans to bytes.
|
|
17 */
|
|
18 public static final F<Boolean, Byte> Boolean_Byte = new F<Boolean, Byte>() {
|
|
19 public Byte f(final Boolean b) {
|
|
20 return (byte) (b ? 1 : 0);
|
|
21 }
|
|
22 };
|
|
23
|
|
24 /**
|
|
25 * A function that converts booleans to characters.
|
|
26 */
|
|
27 public static final F<Boolean, Character> Boolean_Character = new F<Boolean, Character>() {
|
|
28 public Character f(final Boolean b) {
|
|
29 return (char) (b ? 1 : 0);
|
|
30 }
|
|
31 };
|
|
32
|
|
33 /**
|
|
34 * A function that converts booleans to doubles.
|
|
35 */
|
|
36 public static final F<Boolean, Double> Boolean_Double = new F<Boolean, Double>() {
|
|
37 public Double f(final Boolean b) {
|
|
38 return b ? 1D : 0D;
|
|
39 }
|
|
40 };
|
|
41
|
|
42 /**
|
|
43 * A function that converts booleans to floats.
|
|
44 */
|
|
45 public static final F<Boolean, Float> Boolean_Float = new F<Boolean, Float>() {
|
|
46 public Float f(final Boolean b) {
|
|
47 return b ? 1F : 0F;
|
|
48 }
|
|
49 };
|
|
50
|
|
51 /**
|
|
52 * A function that converts booleans to integers.
|
|
53 */
|
|
54 public static final F<Boolean, Integer> Boolean_Integer = new F<Boolean, Integer>() {
|
|
55 public Integer f(final Boolean b) {
|
|
56 return b ? 1 : 0;
|
|
57 }
|
|
58 };
|
|
59
|
|
60 /**
|
|
61 * A function that converts booleans to longs.
|
|
62 */
|
|
63 public static final F<Boolean, Long> Boolean_Long = new F<Boolean, Long>() {
|
|
64 public Long f(final Boolean b) {
|
|
65 return b ? 1L : 0L;
|
|
66 }
|
|
67 };
|
|
68
|
|
69 /**
|
|
70 * A function that converts booleans to shorts.
|
|
71 */
|
|
72 public static final F<Boolean, Short> Boolean_Short = new F<Boolean, Short>() {
|
|
73 public Short f(final Boolean b) {
|
|
74 return (short) (b ? 1 : 0);
|
|
75 }
|
|
76 };
|
|
77
|
|
78 // END Boolean ->
|
|
79
|
|
80 // BEGIN Byte ->
|
|
81
|
|
82 /**
|
|
83 * A function that converts bytes to booleans.
|
|
84 */
|
|
85 public static final F<Byte, Boolean> Byte_Boolean = new F<Byte, Boolean>() {
|
|
86 public Boolean f(final Byte b) {
|
|
87 return b != 0;
|
|
88 }
|
|
89 };
|
|
90
|
|
91 /**
|
|
92 * A function that converts bytes to characters.
|
|
93 */
|
|
94 public static final F<Byte, Character> Byte_Character = new F<Byte, Character>() {
|
|
95 public Character f(final Byte b) {
|
|
96 return (char) (byte) b;
|
|
97 }
|
|
98 };
|
|
99
|
|
100 /**
|
|
101 * A function that converts bytes to doubles.
|
|
102 */
|
|
103 public static final F<Byte, Double> Byte_Double = new F<Byte, Double>() {
|
|
104 public Double f(final Byte b) {
|
|
105 return (double) b;
|
|
106 }
|
|
107 };
|
|
108
|
|
109 /**
|
|
110 * A function that converts bytes to floats.
|
|
111 */
|
|
112 public static final F<Byte, Float> Byte_Float = new F<Byte, Float>() {
|
|
113 public Float f(final Byte b) {
|
|
114 return (float) b;
|
|
115 }
|
|
116 };
|
|
117
|
|
118 /**
|
|
119 * A function that converts bytes to integers.
|
|
120 */
|
|
121 public static final F<Byte, Integer> Byte_Integer = new F<Byte, Integer>() {
|
|
122 public Integer f(final Byte b) {
|
|
123 return (int) b;
|
|
124 }
|
|
125 };
|
|
126
|
|
127 /**
|
|
128 * A function that converts bytes to longs.
|
|
129 */
|
|
130 public static final F<Byte, Long> Byte_Long = new F<Byte, Long>() {
|
|
131 public Long f(final Byte b) {
|
|
132 return (long) b;
|
|
133 }
|
|
134 };
|
|
135
|
|
136 /**
|
|
137 * A function that converts bytes to shorts.
|
|
138 */
|
|
139 public static final F<Byte, Short> Byte_Short = new F<Byte, Short>() {
|
|
140 public Short f(final Byte b) {
|
|
141 return (short) b;
|
|
142 }
|
|
143 };
|
|
144
|
|
145 // END Byte ->
|
|
146
|
|
147 // BEGIN Character ->
|
|
148
|
|
149 /**
|
|
150 * A function that converts characters to booleans.
|
|
151 */
|
|
152 public static final F<Character, Boolean> Character_Boolean = new F<Character, Boolean>() {
|
|
153 public Boolean f(final Character c) {
|
|
154 return c != 0;
|
|
155 }
|
|
156 };
|
|
157
|
|
158 /**
|
|
159 * A function that converts characters to bytes.
|
|
160 */
|
|
161 public static final F<Character, Byte> Character_Byte = new F<Character, Byte>() {
|
|
162 public Byte f(final Character c) {
|
|
163 return (byte) (char) c;
|
|
164 }
|
|
165 };
|
|
166
|
|
167 /**
|
|
168 * A function that converts characters to doubles.
|
|
169 */
|
|
170 public static final F<Character, Double> Character_Double = new F<Character, Double>() {
|
|
171 public Double f(final Character c) {
|
|
172 return (double) (char) c;
|
|
173 }
|
|
174 };
|
|
175
|
|
176 /**
|
|
177 * A function that converts characters to floats.
|
|
178 */
|
|
179 public static final F<Character, Float> Character_Float = new F<Character, Float>() {
|
|
180 public Float f(final Character c) {
|
|
181 return (float) (char) c;
|
|
182 }
|
|
183 };
|
|
184
|
|
185 /**
|
|
186 * A function that converts characters to integers.
|
|
187 */
|
|
188 public static final F<Character, Integer> Character_Integer = new F<Character, Integer>() {
|
|
189 public Integer f(final Character c) {
|
|
190 return (int) (char) c;
|
|
191 }
|
|
192 };
|
|
193
|
|
194 /**
|
|
195 * A function that converts characters to longs.
|
|
196 */
|
|
197 public static final F<Character, Long> Character_Long = new F<Character, Long>() {
|
|
198 public Long f(final Character c) {
|
|
199 return (long) (char) c;
|
|
200 }
|
|
201 };
|
|
202
|
|
203 /**
|
|
204 * A function that converts characters to shorts.
|
|
205 */
|
|
206 public static final F<Character, Short> Character_Short = new F<Character, Short>() {
|
|
207 public Short f(final Character c) {
|
|
208 return (short) (char) c;
|
|
209 }
|
|
210 };
|
|
211
|
|
212 // END Character ->
|
|
213
|
|
214 // BEGIN Double ->
|
|
215
|
|
216 /**
|
|
217 * A function that converts doubles to booleans.
|
|
218 */
|
|
219 public static final F<Double, Boolean> Double_Boolean = new F<Double, Boolean>() {
|
|
220 public Boolean f(final Double d) {
|
|
221 return d != 0D;
|
|
222 }
|
|
223 };
|
|
224
|
|
225 /**
|
|
226 * A function that converts doubles to bytes.
|
|
227 */
|
|
228 public static final F<Double, Byte> Double_Byte = new F<Double, Byte>() {
|
|
229 public Byte f(final Double d) {
|
|
230 return (byte) (double) d;
|
|
231 }
|
|
232 };
|
|
233
|
|
234 /**
|
|
235 * A function that converts doubles to characters.
|
|
236 */
|
|
237 public static final F<Double, Character> Double_Character = new F<Double, Character>() {
|
|
238 public Character f(final Double d) {
|
|
239 return (char) (double) d;
|
|
240 }
|
|
241 };
|
|
242
|
|
243 /**
|
|
244 * A function that converts doubles to floats.
|
|
245 */
|
|
246 public static final F<Double, Float> Double_Float = new F<Double, Float>() {
|
|
247 public Float f(final Double d) {
|
|
248 return (float) (double) d;
|
|
249 }
|
|
250 };
|
|
251
|
|
252 /**
|
|
253 * A function that converts doubles to integers.
|
|
254 */
|
|
255 public static final F<Double, Integer> Double_Integer = new F<Double, Integer>() {
|
|
256 public Integer f(final Double d) {
|
|
257 return (int) (double) d;
|
|
258 }
|
|
259 };
|
|
260
|
|
261 /**
|
|
262 * A function that converts doubles to longs.
|
|
263 */
|
|
264 public static final F<Double, Long> Double_Long = new F<Double, Long>() {
|
|
265 public Long f(final Double d) {
|
|
266 return (long) (double) d;
|
|
267 }
|
|
268 };
|
|
269
|
|
270 /**
|
|
271 * A function that converts doubles to shorts.
|
|
272 */
|
|
273 public static final F<Double, Short> Double_Short = new F<Double, Short>() {
|
|
274 public Short f(final Double d) {
|
|
275 return (short) (double) d;
|
|
276 }
|
|
277 };
|
|
278
|
|
279 // END Double ->
|
|
280
|
|
281 // BEGIN Float ->
|
|
282
|
|
283 /**
|
|
284 * A function that converts floats to booleans.
|
|
285 */
|
|
286 public static final F<Float, Boolean> Float_Boolean = new F<Float, Boolean>() {
|
|
287 public Boolean f(final Float f) {
|
|
288 return f != 0F;
|
|
289 }
|
|
290 };
|
|
291
|
|
292 /**
|
|
293 * A function that converts floats to bytes.
|
|
294 */
|
|
295 public static final F<Float, Byte> Float_Byte = new F<Float, Byte>() {
|
|
296 public Byte f(final Float f) {
|
|
297 return (byte) (float) f;
|
|
298 }
|
|
299 };
|
|
300
|
|
301 /**
|
|
302 * A function that converts floats to characters.
|
|
303 */
|
|
304 public static final F<Float, Character> Float_Character = new F<Float, Character>() {
|
|
305 public Character f(final Float f) {
|
|
306 return (char) (float) f;
|
|
307 }
|
|
308 };
|
|
309
|
|
310 /**
|
|
311 * A function that converts floats to doubles.
|
|
312 */
|
|
313 public static final F<Float, Double> Float_Double = new F<Float, Double>() {
|
|
314 public Double f(final Float f) {
|
|
315 return (double) (float) f;
|
|
316 }
|
|
317 };
|
|
318
|
|
319 /**
|
|
320 * A function that converts floats to integers.
|
|
321 */
|
|
322 public static final F<Float, Integer> Float_Integer = new F<Float, Integer>() {
|
|
323 public Integer f(final Float f) {
|
|
324 return (int) (float) f;
|
|
325 }
|
|
326 };
|
|
327
|
|
328 /**
|
|
329 * A function that converts floats to longs.
|
|
330 */
|
|
331 public static final F<Float, Long> Float_Long = new F<Float, Long>() {
|
|
332 public Long f(final Float f) {
|
|
333 return (long) (float) f;
|
|
334 }
|
|
335 };
|
|
336
|
|
337 /**
|
|
338 * A function that converts floats to shorts.
|
|
339 */
|
|
340 public static final F<Float, Short> Float_Short = new F<Float, Short>() {
|
|
341 public Short f(final Float f) {
|
|
342 return (short) (float) f;
|
|
343 }
|
|
344 };
|
|
345
|
|
346 // END Float ->
|
|
347
|
|
348 // BEGIN Integer ->
|
|
349
|
|
350 /**
|
|
351 * A function that converts integers to booleans.
|
|
352 */
|
|
353 public static final F<Integer, Boolean> Integer_Boolean = new F<Integer, Boolean>() {
|
|
354 public Boolean f(final Integer i) {
|
|
355 return i != 0;
|
|
356 }
|
|
357 };
|
|
358
|
|
359 /**
|
|
360 * A function that converts integers to bytes.
|
|
361 */
|
|
362 public static final F<Integer, Byte> Integer_Byte = new F<Integer, Byte>() {
|
|
363 public Byte f(final Integer i) {
|
|
364 return (byte) (int) i;
|
|
365 }
|
|
366 };
|
|
367
|
|
368 /**
|
|
369 * A function that converts integers to characters.
|
|
370 */
|
|
371 public static final F<Integer, Character> Integer_Character = new F<Integer, Character>() {
|
|
372 public Character f(final Integer i) {
|
|
373 return (char) (int) i;
|
|
374 }
|
|
375 };
|
|
376
|
|
377 /**
|
|
378 * A function that converts integers to doubles.
|
|
379 */
|
|
380 public static final F<Integer, Double> Integer_Double = new F<Integer, Double>() {
|
|
381 public Double f(final Integer i) {
|
|
382 return (double) i;
|
|
383 }
|
|
384 };
|
|
385
|
|
386 /**
|
|
387 * A function that converts integers to floats.
|
|
388 */
|
|
389 public static final F<Integer, Float> Integer_Float = new F<Integer, Float>() {
|
|
390 public Float f(final Integer i) {
|
|
391 return (float) i;
|
|
392 }
|
|
393 };
|
|
394
|
|
395 /**
|
|
396 * A function that converts integers to longs.
|
|
397 */
|
|
398 public static final F<Integer, Long> Integer_Long = new F<Integer, Long>() {
|
|
399 public Long f(final Integer i) {
|
|
400 return (long) i;
|
|
401 }
|
|
402 };
|
|
403
|
|
404 /**
|
|
405 * A function that converts integers to shorts.
|
|
406 */
|
|
407 public static final F<Integer, Short> Integer_Short = new F<Integer, Short>() {
|
|
408 public Short f(final Integer i) {
|
|
409 return (short) (int) i;
|
|
410 }
|
|
411 };
|
|
412
|
|
413 // END Integer ->
|
|
414
|
|
415 // BEGIN Long ->
|
|
416
|
|
417 /**
|
|
418 * A function that converts longs to booleans.
|
|
419 */
|
|
420 public static final F<Long, Boolean> Long_Boolean = new F<Long, Boolean>() {
|
|
421 public Boolean f(final Long l) {
|
|
422 return l != 0L;
|
|
423 }
|
|
424 };
|
|
425
|
|
426 /**
|
|
427 * A function that converts longs to bytes.
|
|
428 */
|
|
429 public static final F<Long, Byte> Long_Byte = new F<Long, Byte>() {
|
|
430 public Byte f(final Long l) {
|
|
431 return (byte) (long) l;
|
|
432 }
|
|
433 };
|
|
434
|
|
435 /**
|
|
436 * A function that converts longs to characters.
|
|
437 */
|
|
438 public static final F<Long, Character> Long_Character = new F<Long, Character>() {
|
|
439 public Character f(final Long l) {
|
|
440 return (char) (long) l;
|
|
441 }
|
|
442 };
|
|
443
|
|
444 /**
|
|
445 * A function that converts longs to doubles.
|
|
446 */
|
|
447 public static final F<Long, Double> Long_Double = new F<Long, Double>() {
|
|
448 public Double f(final Long l) {
|
|
449 return (double) (long) l;
|
|
450 }
|
|
451 };
|
|
452
|
|
453 /**
|
|
454 * A function that converts longs to floats.
|
|
455 */
|
|
456 public static final F<Long, Float> Long_Float = new F<Long, Float>() {
|
|
457 public Float f(final Long l) {
|
|
458 return (float) (long) l;
|
|
459 }
|
|
460 };
|
|
461
|
|
462 /**
|
|
463 * A function that converts longs to integers.
|
|
464 */
|
|
465 public static final F<Long, Integer> Long_Integer = new F<Long, Integer>() {
|
|
466 public Integer f(final Long l) {
|
|
467 return (int) (long) l;
|
|
468 }
|
|
469 };
|
|
470
|
|
471 /**
|
|
472 * A function that converts longs to shorts.
|
|
473 */
|
|
474 public static final F<Long, Short> Long_Short = new F<Long, Short>() {
|
|
475 public Short f(final Long l) {
|
|
476 return (short) (long) l;
|
|
477 }
|
|
478 };
|
|
479
|
|
480 // END Long ->
|
|
481
|
|
482 // BEGIN Short ->
|
|
483
|
|
484 /**
|
|
485 * A function that converts shorts to booleans.
|
|
486 */
|
|
487 public static final F<Short, Boolean> Short_Boolean = new F<Short, Boolean>() {
|
|
488 public Boolean f(final Short s) {
|
|
489 return s != 0;
|
|
490 }
|
|
491 };
|
|
492
|
|
493 /**
|
|
494 * A function that converts shorts to bytes.
|
|
495 */
|
|
496 public static final F<Short, Byte> Short_Byte = new F<Short, Byte>() {
|
|
497 public Byte f(final Short s) {
|
|
498 return (byte) (short) s;
|
|
499 }
|
|
500 };
|
|
501
|
|
502 /**
|
|
503 * A function that converts shorts to characters.
|
|
504 */
|
|
505 public static final F<Short, Character> Short_Character = new F<Short, Character>() {
|
|
506 public Character f(final Short s) {
|
|
507 return (char) (short) s;
|
|
508 }
|
|
509 };
|
|
510
|
|
511 /**
|
|
512 * A function that converts shorts to doubles.
|
|
513 */
|
|
514 public static final F<Short, Double> Short_Double = new F<Short, Double>() {
|
|
515 public Double f(final Short s) {
|
|
516 return (double) (short) s;
|
|
517 }
|
|
518 };
|
|
519
|
|
520 /**
|
|
521 * A function that converts shorts to floats.
|
|
522 */
|
|
523 public static final F<Short, Float> Short_Float = new F<Short, Float>() {
|
|
524 public Float f(final Short s) {
|
|
525 return (float) (short) s;
|
|
526 }
|
|
527 };
|
|
528
|
|
529 /**
|
|
530 * A function that converts shorts to integers.
|
|
531 */
|
|
532 public static final F<Short, Integer> Short_Integer = new F<Short, Integer>() {
|
|
533 public Integer f(final Short s) {
|
|
534 return (int) (short) s;
|
|
535 }
|
|
536 };
|
|
537
|
|
538 /**
|
|
539 * A function that converts shorts to longs.
|
|
540 */
|
|
541 public static final F<Short, Long> Short_Long = new F<Short, Long>() {
|
|
542 public Long f(final Short s) {
|
|
543 return (long) (short) s;
|
|
544 }
|
|
545 };
|
|
546
|
|
547 // END Short
|
|
548 }
|