Repository navigation
Expand file tree
/
Copy pathCapturedSnapshot07.java
More file actions
61 lines (55 loc) · 1.77 KB
/
Copy pathCapturedSnapshot07.java
File metadata and controls
61 lines (55 loc) · 1.77 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class CapturedSnapshot07 {
private int intValue = 24;
private final double doubleValue = 3.14;
private String strValue = "foobar";
private final List<String> strList = new ArrayList<>(Arrays.asList("foo", "bar"));
private final Map<String, String> strMap = new HashMap<>();
public static int main(String mode, String arg) {
if (mode.equals("static")) {
CapturedSnapshot07 cs7 = new CapturedSnapshot07();
cs7.strValue = arg;
return cs7.staticLambda(arg);
}
if (mode.equals("capturing")) {
CapturedSnapshot07 cs7 = new CapturedSnapshot07();
cs7.strValue = arg;
return cs7.capturingLambda(arg);
}
if (mode.equals("multi")) {
CapturedSnapshot07 cs7 = new CapturedSnapshot07();
return cs7.multiLambda(arg);
}
return 0;
}
private int staticLambda(String arg) {
Function<String, String> func = s -> {
int idx = s.indexOf('@');
if (idx >= 0) { // beae1817-f3b0-4ea8-a74f-000000000001
return s.substring(idx);
}
return s.substring(0);
};
return func.apply(arg).length();
}
private int capturingLambda(String arg) {
Function<String, String> func = s -> {
int idx = strValue.indexOf('@');
if (idx >= 0) { // beae1817-f3b0-4ea8-a74f-000000000002
return strValue.substring(idx);
}
return strValue.substring(0);
};
return func.apply(arg).length();
}
private int multiLambda(String arg) {
return (int)Arrays.stream(arg.split(","))
.map(s -> s.toUpperCase()).filter(s -> s.startsWith("FOO")) // beae1817-f3b0-4ea8-a74f-000000000003
.count();
}
}