Skip to content

Commit 7e3becd

Browse files
author
Dan Nuffer
committed
Compatible with java 1.8
1 parent 4786c46 commit 7e3becd

5 files changed

Lines changed: 9 additions & 39 deletions

File tree

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
<artifactId>maven-compiler-plugin</artifactId>
3838
<version>3.1</version>
3939
<configuration>
40-
<source>1.9</source>
41-
<target>1.9</target>
40+
<source>1.8</source>
41+
<target>1.8</target>
4242
</configuration>
4343
</plugin>
4444
<plugin>

‎src/main/java/lambdasinaction/chap10/OperationsWithOptional.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public static void main(String... args) {
1212
System.out.println(max(empty(), of(5)));
1313

1414
Optional<Integer> opt1 = of(5);
15-
Optional<Integer> opt2 = opt1.or(() -> of(4));
15+
Optional<Integer> opt2 = of(opt1.orElse(4));
1616

1717
System.out.println(
18-
of(5).or(() -> of(4))
18+
of(5).orElse(4)
1919
);
2020
}
2121

‎src/main/java/lambdasinaction/chap10/OptionalMain.java‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎src/main/java/lambdasinaction/chap6/Grouping.java‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ enum CaloricLevel { DIET, NORMAL, FAT };
1313
public static void main(String ... args) {
1414
System.out.println("Dishes grouped by type: " + groupDishesByType());
1515
System.out.println("Dish names grouped by type: " + groupDishNamesByType());
16-
System.out.println("Dish tags grouped by type: " + groupDishTagsByType());
1716
System.out.println("Caloric dishes grouped by type: " + groupCaloricDishesByType());
1817
System.out.println("Dishes grouped by caloric level: " + groupDishesByCaloricLevel());
1918
System.out.println("Dishes grouped by type and caloric level: " + groupDishedByTypeAndCaloricLevel());
@@ -32,13 +31,8 @@ private static Map<Dish.Type, List<String>> groupDishNamesByType() {
3231
return menu.stream().collect(groupingBy(Dish::getType, mapping(Dish::getName, toList())));
3332
}
3433

35-
private static Map<Dish.Type, Set<String>> groupDishTagsByType() {
36-
return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet())));
37-
}
38-
3934
private static Map<Dish.Type, List<Dish>> groupCaloricDishesByType() {
40-
// return menu.stream().filter(dish -> dish.getCalories() > 500).collect(groupingBy(Dish::getType));
41-
return menu.stream().collect(groupingBy(Dish::getType, filtering(dish -> dish.getCalories() > 500, toList())));
35+
return menu.stream().filter(dish -> dish.getCalories() > 500).collect(groupingBy(Dish::getType));
4236
}
4337

4438
private static Map<CaloricLevel, List<Dish>> groupDishesByCaloricLevel() {

‎src/main/java/lambdasinaction/chap6/PartitionPrimeNumbers.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public static Map<Boolean, List<Integer>> partitionPrimesWithCustomCollector(int
3232

3333
public static boolean isPrime(List<Integer> primes, Integer candidate) {
3434
double candidateRoot = Math.sqrt((double) candidate);
35-
//return takeWhile(primes, i -> i <= candidateRoot).stream().noneMatch(i -> candidate % i == 0);
36-
return primes.stream().takeWhile(i -> i <= candidateRoot).noneMatch(i -> candidate % i == 0);
35+
return takeWhile(primes, i -> i <= candidateRoot).stream().noneMatch(i -> candidate % i == 0);
36+
// return primes.stream().takeWhile(i -> i <= candidateRoot).noneMatch(i -> candidate % i == 0);
3737
}
38-
/*
38+
3939
public static <A> List<A> takeWhile(List<A> list, Predicate<A> p) {
4040
int i = 0;
4141
for (A item : list) {
@@ -46,7 +46,7 @@ public static <A> List<A> takeWhile(List<A> list, Predicate<A> p) {
4646
}
4747
return list;
4848
}
49-
*/
49+
5050
public static class PrimeNumbersCollector
5151
implements Collector<Integer, Map<Boolean, List<Integer>>, Map<Boolean, List<Integer>>> {
5252

0 commit comments

Comments
 (0)