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

Method main

streams/OptionalMap.java:25–45  ·  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 // If Optional is not empty, map() first extracts
28 // the contents which it then passes
29 // to the function:
30
31 test("Add brackets", s -> "[" + s + "]");
32
33 test("Increment", s -> {
34 try {
35 return Integer.parseInt(s) + 1 + "";
36 } catch(NumberFormatException e) {
37 return s;
38 }
39 });
40
41 test("Replace", s -> s.replace("2", "9"));
42
43 test("Take last digit", s -> s.length() > 0 ?
44 s.charAt(s.length() - 1) + "" : s);
45 }
46 // After the function is finished, map() wraps the
47 // result in an Optional before returning it:
48}

Callers

nothing calls this directly

Calls 2

testMethod · 0.95
replaceMethod · 0.80

Tested by

no test coverage detected