-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayShortcutsExample.java
91 lines (78 loc) · 1.89 KB
/
ArrayShortcutsExample.java
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
package jarrayliterals;
import static jarrayliterals.ArrayShortcuts.*;
import java.util.Arrays;
public class ArrayShortcutsExample {
public static void complexExample() {
Object obj =
$($(
$(1f, 2f), $(3f, 4f), $(5f, 6f), $(7f, 8f)
), $(
$(100L), $(200L)
), $(
"a", "B"
), $(
$($($($($(2d)))))
), $(
$($(true), $(true, false), $(false, false, false))
), $(
$('a', 'c')
), $(
$S(2,3,4), $S(1,5,6,7,8,9,0)
), $(
$($, $($null))
), $(
$B(2,5,6,7,8,9), $B(101,199), $B
), $(
$($($($($($())))))
), $(
$($($($($($B)))))
));
System.out.println(ArrayShortcuts.toString(obj));
}
public static void simpleExample() {
Object[] flat = (Object[])
$( $b, $(true, false), $($), $S(1,2,3,4), $B(2,3), $('c'), $($null), $, $null );
testTypes(flat);
System.out.println();
Object[] tediousTempVar = new Object[][]{{}};
Object[][] flat2 = new Object[][]{
{},
{true, false},
tediousTempVar,
{(short) 1, (short) 2, (short) 3, (short) 4},
{(byte) 2, (byte) 3},
{'c'},
{null},
{},
null
};
testTypes(flat2);
}
private static void testTypes(Object[] arr) {
System.out.println(Arrays.deepToString(arr));
for (int i=0; i<arr.length; i++) {
if (arr[i] != null) {
System.out.println(""+i+"th element is typeof "+arr[i].getClass().getSimpleName()+".");
} else {
System.out.println(""+i+"th element is null.");
}
}
try {
testType((Boolean[]) arr[0]);
testType((Boolean[]) arr[1]);
} catch (ClassCastException e) {
System.out.println("Nay :(! Type of array can't be cast Boolean[]!");
}
}
private static void testType(Boolean[] arr) {
System.out.println("Yay :)! Type of array can be cast to Boolean[]!");
}
/**
* @param args
*/
public static void main(String[] args) {
simpleExample();
System.out.println("****************************");
complexExample();
}
}