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