MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

streams/OptionalFlatMap.java:25–46  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

23 }
24 }
25 public static void main(String[] args) {
26
27 test("Add brackets",
28 s -> Optional.of("[" + s + "]"));
29
30 test("Increment", s -> {
31 try {
32 return Optional.of(
33 Integer.parseInt(s) + 1 + "");
34 } catch(NumberFormatException e) {
35 return Optional.of(s);
36 }
37 });
38
39 test("Replace",
40 s -> Optional.of(s.replace("2", "9")));
41
42 test("Take last digit",
43 s -> Optional.of(s.length() > 0 ?
44 s.charAt(s.length() - 1) + ""
45 : s));
46 }
47}
48/* Output:
49 ---( Add brackets )---

Callers

nothing calls this directly

Calls 2

testMethod · 0.95
replaceMethod · 0.80

Tested by

no test coverage detected