Skip to content
Snippets Groups Projects
Commit 8999bc19 authored by Stuart Marks's avatar Stuart Marks
Browse files

Remove uses of Optional.get().

parent 2315cef5
No related branches found
No related tags found
No related merge requests found
...@@ -127,7 +127,7 @@ public class D_SimpleStreams { ...@@ -127,7 +127,7 @@ public class D_SimpleStreams {
*/ */
@Test @Ignore @Test @Ignore
public void ex10_findLongestLine() throws IOException { public void ex10_findLongestLine() throws IOException {
String longest = ""; // TODO String longest = null; // TODO
assertEquals("Feed'st thy light's flame with self-substantial fuel,", longest); assertEquals("Feed'st thy light's flame with self-substantial fuel,", longest);
} }
......
...@@ -157,12 +157,12 @@ public class D_SimpleStreams { ...@@ -157,12 +157,12 @@ public class D_SimpleStreams {
*/ */
@Test @Test
public void ex10_findLongestLine() throws IOException { public void ex10_findLongestLine() throws IOException {
//TODO//String longest = ""; //TODO//String longest = null;
//BEGINREMOVE //BEGINREMOVE
String longest = String longest =
reader.lines() reader.lines()
.max(Comparator.comparingInt(String::length)) .max(Comparator.comparingInt(String::length))
.get(); .orElse("");
// Alternative: // Alternative:
// Instead of Comparator.comparingInt(String::length), one could // Instead of Comparator.comparingInt(String::length), one could
// use something like: // use something like:
......
...@@ -75,7 +75,7 @@ public class F_AdvancedStreams { ...@@ -75,7 +75,7 @@ public class F_AdvancedStreams {
reader.lines() reader.lines()
.flatMap(line -> WORD_PATTERN.splitAsStream(line)) .flatMap(line -> WORD_PATTERN.splitAsStream(line))
.reduce((a, b) -> b) .reduce((a, b) -> b)
.get(); .orElse("");
//ENDREMOVE //ENDREMOVE
assertEquals("thee", result); assertEquals("thee", result);
......
...@@ -440,7 +440,7 @@ public class G_Challenges { ...@@ -440,7 +440,7 @@ public class G_Challenges {
.max((i, j) -> Integer.compare(bounds.get(i) - bounds.get(i-1), .max((i, j) -> Integer.compare(bounds.get(i) - bounds.get(i-1),
bounds.get(j) - bounds.get(j-1))) bounds.get(j) - bounds.get(j-1)))
.map(i -> input.substring(bounds.get(i-1), bounds.get(i))) .map(i -> input.substring(bounds.get(i-1), bounds.get(i)))
.get(); .orElse("");
//ENDREMOVE //ENDREMOVE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment