Skip to content

Commit 30cf084

Browse files
committed
minor changes
1 parent a348200 commit 30cf084

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

src/com/winterbe/java8/Optional2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ private static void test1() {
2828
.flatMap(o -> Optional.ofNullable(o.nested))
2929
.flatMap(n -> Optional.ofNullable(n.inner))
3030
.flatMap(i -> Optional.ofNullable(i.foo))
31-
.ifPresent(System.out::print);
31+
.ifPresent(System.out::println);
3232
}
3333
}

src/com/winterbe/java8/Streams5.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,23 @@ public static void main(String[] args) {
1616
stringCollection.add("ddd2");
1717
stringCollection.add("aaa2");
1818
stringCollection.add("bbb1");
19-
stringCollection.add("aaa1");
2019
stringCollection.add("bbb3");
2120
stringCollection.add("ccc");
22-
stringCollection.add("bbb2");
23-
stringCollection.add("ddd1");
2421

2522
// test1(stringCollection);
2623
// test2(stringCollection);
2724
// test3(stringCollection);
2825
// test4(stringCollection);
29-
// test5(stringCollection);
26+
test5(stringCollection);
3027
// test6(stringCollection);
31-
test7(stringCollection);
28+
// test7(stringCollection);
3229
}
3330

3431
// stream has already been operated upon or closed
3532
private static void test7(List<String> stringCollection) {
3633
Stream<String> stream = stringCollection
3734
.stream()
38-
.filter(s -> s.toLowerCase().startsWith("a"));
35+
.filter(s -> s.startsWith("a"));
3936

4037
stream.anyMatch(s -> true);
4138
stream.noneMatch(s -> true);
@@ -47,28 +44,28 @@ private static void test6(List<String> stringCollection) {
4744
.stream()
4845
.filter(s -> {
4946
System.out.println("filter: " + s);
50-
return s.toLowerCase().startsWith("a");
47+
return s.startsWith("a");
5148
})
5249
.map(s -> {
53-
System.out.println("map: " + s);
50+
System.out.println("map: " + s);
5451
return s.toUpperCase();
5552
})
56-
.anyMatch(s -> true);
53+
.anyMatch(s -> s.startsWith("A"));
5754
}
5855

5956
private static void test5(List<String> stringCollection) {
6057
stringCollection
6158
.stream()
6259
.filter(s -> {
63-
System.out.println("filter: " + s);
60+
System.out.println("filter: " + s);
6461
return s.toLowerCase().startsWith("a");
6562
})
6663
.sorted((s1, s2) -> {
67-
System.out.printf("sort: %s; %s\n", s1, s2);
64+
System.out.printf("sort: %s; %s\n", s1, s2);
6865
return s1.compareTo(s2);
6966
})
7067
.map(s -> {
71-
System.out.println("map: " + s);
68+
System.out.println("map: " + s);
7269
return s.toUpperCase();
7370
})
7471
.forEach(s -> System.out.println("forEach: " + s));
@@ -79,15 +76,15 @@ private static void test4(List<String> stringCollection) {
7976
stringCollection
8077
.stream()
8178
.sorted((s1, s2) -> {
82-
System.out.printf("sort: %s; %s\n", s1, s2);
79+
System.out.printf("sort: %s; %s\n", s1, s2);
8380
return s1.compareTo(s2);
8481
})
8582
.filter(s -> {
86-
System.out.println("filter: " + s);
83+
System.out.println("filter: " + s);
8784
return s.toLowerCase().startsWith("a");
8885
})
8986
.map(s -> {
90-
System.out.println("map: " + s);
87+
System.out.println("map: " + s);
9188
return s.toUpperCase();
9289
})
9390
.forEach(s -> System.out.println("forEach: " + s));
@@ -97,11 +94,11 @@ private static void test3(List<String> stringCollection) {
9794
stringCollection
9895
.stream()
9996
.filter(s -> {
100-
System.out.println("filter: " + s);
101-
return s.toLowerCase().startsWith("a");
97+
System.out.println("filter: " + s);
98+
return s.startsWith("a");
10299
})
103100
.map(s -> {
104-
System.out.println("map: " + s);
101+
System.out.println("map: " + s);
105102
return s.toUpperCase();
106103
})
107104
.forEach(s -> System.out.println("forEach: " + s));
@@ -111,12 +108,12 @@ private static void test2(List<String> stringCollection) {
111108
stringCollection
112109
.stream()
113110
.map(s -> {
114-
System.out.println("map: " + s);
111+
System.out.println("map: " + s);
115112
return s.toUpperCase();
116113
})
117114
.filter(s -> {
118-
System.out.println("filter: " + s);
119-
return s.toLowerCase().startsWith("a");
115+
System.out.println("filter: " + s);
116+
return s.startsWith("A");
120117
})
121118
.forEach(s -> System.out.println("forEach: " + s));
122119
}
@@ -125,7 +122,7 @@ private static void test1(List<String> stringCollection) {
125122
stringCollection
126123
.stream()
127124
.filter(s -> {
128-
System.out.println("filter: " + s);
125+
System.out.println("filter: " + s);
129126
return true;
130127
})
131128
.forEach(s -> System.out.println("forEach: " + s));

src/com/winterbe/java8/Streams7.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void test2() {
3535
IntStream.range(1, 4)
3636
.mapToObj(num -> new Foo("Foo" + num))
3737
.peek(f -> IntStream.range(1, 4)
38-
.mapToObj(num -> new Bar(f.name + " -> Bar" + num))
38+
.mapToObj(num -> new Bar("Bar" + num + " <- " + f.name))
3939
.forEach(f.bars::add))
4040
.flatMap(f -> f.bars.stream())
4141
.forEach(b -> System.out.println(b.name));
@@ -51,7 +51,7 @@ static void test1() {
5151
foos.forEach(f ->
5252
IntStream
5353
.range(1, 4)
54-
.forEach(num -> f.bars.add(new Bar(f.name + " -> Bar" + num))));
54+
.forEach(num -> f.bars.add(new Bar("Bar" + num + " <- " + f.name))));
5555

5656
foos.stream()
5757
.flatMap(f -> f.bars.stream())

0 commit comments

Comments
 (0)