diff --git a/pom.xml b/pom.xml
index 10e5035e..37cbf712 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,8 +37,8 @@
maven-compiler-plugin
3.1
- 1.9
- 1.9
+ 1.8
+ 1.8
diff --git a/src/main/java/lambdasinaction/chap10/OperationsWithOptional.java b/src/main/java/lambdasinaction/chap10/OperationsWithOptional.java
index d2940969..42651b46 100644
--- a/src/main/java/lambdasinaction/chap10/OperationsWithOptional.java
+++ b/src/main/java/lambdasinaction/chap10/OperationsWithOptional.java
@@ -1,25 +1,25 @@
-package lambdasinaction.chap10;
-
-import java.util.*;
-
-import static java.util.Optional.of;
-import static java.util.Optional.empty;
-
-public class OperationsWithOptional {
-
- public static void main(String... args) {
- System.out.println(max(of(3), of(5)));
- System.out.println(max(empty(), of(5)));
-
- Optional opt1 = of(5);
- Optional opt2 = opt1.or(() -> of(4));
-
- System.out.println(
- of(5).or(() -> of(4))
- );
- }
-
- public static final Optional max(Optional i, Optional j) {
- return i.flatMap(a -> j.map(b -> Math.max(a, b)));
- }
-}
+//package lambdasinaction.chap10;
+//
+//import java.util.*;
+//
+//import static java.util.Optional.of;
+//import static java.util.Optional.empty;
+//
+//public class OperationsWithOptional {
+//
+// public static void main(String... args) {
+// System.out.println(max(of(3), of(5)));
+// System.out.println(max(empty(), of(5)));
+//
+// Optional opt1 = of(5);
+// Optional opt2 = opt1.or(() -> of(4));
+//
+// System.out.println(
+// of(5).or(() -> of(4))
+// );
+// }
+//
+// public static final Optional max(Optional i, Optional j) {
+// return i.flatMap(a -> j.map(b -> Math.max(a, b)));
+// }
+//}
diff --git a/src/main/java/lambdasinaction/chap10/OptionalMain.java b/src/main/java/lambdasinaction/chap10/OptionalMain.java
index dcd97792..56d742eb 100644
--- a/src/main/java/lambdasinaction/chap10/OptionalMain.java
+++ b/src/main/java/lambdasinaction/chap10/OptionalMain.java
@@ -1,24 +1,24 @@
-package lambdasinaction.chap10;
-
-import java.util.*;
-
-import static java.util.stream.Collectors.toSet;
-
-public class OptionalMain {
-
- public String getCarInsuranceName(Optional person) {
- return person.flatMap(Person::getCar)
- .flatMap(Car::getInsurance)
- .map(Insurance::getName)
- .orElse("Unknown");
- }
-
- public Set getCarInsuranceNames(List persons) {
- return persons.stream()
- .map(Person::getCar)
- .map(optCar -> optCar.flatMap(Car::getInsurance))
- .map(optInsurance -> optInsurance.map(Insurance::getName))
- .flatMap(Optional::stream)
- .collect(toSet());
- }
-}
+//package lambdasinaction.chap10;
+//
+//import java.util.*;
+//
+//import static java.util.stream.Collectors.toSet;
+//
+//public class OptionalMain {
+//
+// public String getCarInsuranceName(Optional person) {
+// return person.flatMap(Person::getCar)
+// .flatMap(Car::getInsurance)
+// .map(Insurance::getName)
+// .orElse("Unknown");
+// }
+//
+// public Set getCarInsuranceNames(List persons) {
+// return persons.stream()
+// .map(Person::getCar)
+// .map(optCar -> optCar.flatMap(Car::getInsurance))
+// .map(optInsurance -> optInsurance.map(Insurance::getName))
+// .flatMap(Optional::stream)
+// .collect(toSet());
+// }
+//}
diff --git a/src/main/java/lambdasinaction/chap6/CollectorHarness.java b/src/main/java/lambdasinaction/chap6/CollectorHarness.java
index 8370be16..46bab3b0 100644
--- a/src/main/java/lambdasinaction/chap6/CollectorHarness.java
+++ b/src/main/java/lambdasinaction/chap6/CollectorHarness.java
@@ -1,23 +1,23 @@
-package lambdasinaction.chap6;
-
-import java.util.function.*;
-
-public class CollectorHarness {
-
- public static void main(String[] args) {
- //System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimes) + " msecs");
- System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimesWithCustomCollector) + " msecs" );
- }
-
- private static long execute(Consumer primePartitioner) {
- long fastest = Long.MAX_VALUE;
- for (int i = 0; i < 10; i++) {
- long start = System.nanoTime();
- primePartitioner.accept(1_000_000);
- long duration = (System.nanoTime() - start) / 1_000_000;
- if (duration < fastest) fastest = duration;
- System.out.println("done in " + duration);
- }
- return fastest;
- }
-}
+//package lambdasinaction.chap6;
+//
+//import java.util.function.*;
+//
+//public class CollectorHarness {
+//
+// public static void main(String[] args) {
+// //System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimes) + " msecs");
+// System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimesWithCustomCollector) + " msecs" );
+// }
+//
+// private static long execute(Consumer primePartitioner) {
+// long fastest = Long.MAX_VALUE;
+// for (int i = 0; i < 10; i++) {
+// long start = System.nanoTime();
+// primePartitioner.accept(1_000_000);
+// long duration = (System.nanoTime() - start) / 1_000_000;
+// if (duration < fastest) fastest = duration;
+// System.out.println("done in " + duration);
+// }
+// return fastest;
+// }
+//}
diff --git a/src/main/java/lambdasinaction/chap6/Grouping.java b/src/main/java/lambdasinaction/chap6/Grouping.java
index 9105cc80..37aa39a4 100644
--- a/src/main/java/lambdasinaction/chap6/Grouping.java
+++ b/src/main/java/lambdasinaction/chap6/Grouping.java
@@ -1,96 +1,96 @@
-package lambdasinaction.chap6;
-
-import java.util.*;
-
-import static java.util.stream.Collectors.*;
-import static lambdasinaction.chap6.Dish.dishTags;
-import static lambdasinaction.chap6.Dish.menu;
-
-public class Grouping {
-
- enum CaloricLevel { DIET, NORMAL, FAT };
-
- public static void main(String ... args) {
- System.out.println("Dishes grouped by type: " + groupDishesByType());
- System.out.println("Dish names grouped by type: " + groupDishNamesByType());
- System.out.println("Dish tags grouped by type: " + groupDishTagsByType());
- System.out.println("Caloric dishes grouped by type: " + groupCaloricDishesByType());
- System.out.println("Dishes grouped by caloric level: " + groupDishesByCaloricLevel());
- System.out.println("Dishes grouped by type and caloric level: " + groupDishedByTypeAndCaloricLevel());
- System.out.println("Count dishes in groups: " + countDishesInGroups());
- System.out.println("Most caloric dishes by type: " + mostCaloricDishesByType());
- System.out.println("Most caloric dishes by type: " + mostCaloricDishesByTypeWithoutOprionals());
- System.out.println("Sum calories by type: " + sumCaloriesByType());
- System.out.println("Caloric levels by type: " + caloricLevelsByType());
- }
-
- private static Map> groupDishesByType() {
- return menu.stream().collect(groupingBy(Dish::getType));
- }
-
- private static Map> groupDishNamesByType() {
- return menu.stream().collect(groupingBy(Dish::getType, mapping(Dish::getName, toList())));
- }
-
- private static Map> groupDishTagsByType() {
- return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet())));
- }
-
- private static Map> groupCaloricDishesByType() {
-// return menu.stream().filter(dish -> dish.getCalories() > 500).collect(groupingBy(Dish::getType));
- return menu.stream().collect(groupingBy(Dish::getType, filtering(dish -> dish.getCalories() > 500, toList())));
- }
-
- private static Map> groupDishesByCaloricLevel() {
- return menu.stream().collect(
- groupingBy(dish -> {
- if (dish.getCalories() <= 400) return CaloricLevel.DIET;
- else if (dish.getCalories() <= 700) return CaloricLevel.NORMAL;
- else return CaloricLevel.FAT;
- } ));
- }
-
- private static Map>> groupDishedByTypeAndCaloricLevel() {
- return menu.stream().collect(
- groupingBy(Dish::getType,
- groupingBy((Dish dish) -> {
- if (dish.getCalories() <= 400) return CaloricLevel.DIET;
- else if (dish.getCalories() <= 700) return CaloricLevel.NORMAL;
- else return CaloricLevel.FAT;
- } )
- )
- );
- }
-
- private static Map countDishesInGroups() {
- return menu.stream().collect(groupingBy(Dish::getType, counting()));
- }
-
- private static Map> mostCaloricDishesByType() {
- return menu.stream().collect(
- groupingBy(Dish::getType,
- reducing((Dish d1, Dish d2) -> d1.getCalories() > d2.getCalories() ? d1 : d2)));
- }
-
- private static Map mostCaloricDishesByTypeWithoutOprionals() {
- return menu.stream().collect(
- groupingBy(Dish::getType,
- collectingAndThen(
- reducing((d1, d2) -> d1.getCalories() > d2.getCalories() ? d1 : d2),
- Optional::get)));
- }
-
- private static Map sumCaloriesByType() {
- return menu.stream().collect(groupingBy(Dish::getType,
- summingInt(Dish::getCalories)));
- }
-
- private static Map> caloricLevelsByType() {
- return menu.stream().collect(
- groupingBy(Dish::getType, mapping(
- dish -> { if (dish.getCalories() <= 400) return CaloricLevel.DIET;
- else if (dish.getCalories() <= 700) return CaloricLevel.NORMAL;
- else return CaloricLevel.FAT; },
- toSet() )));
- }
-}
+//package lambdasinaction.chap6;
+//
+//import java.util.*;
+//
+//import static java.util.stream.Collectors.*;
+//import static lambdasinaction.chap6.Dish.dishTags;
+//import static lambdasinaction.chap6.Dish.menu;
+//
+//public class Grouping {
+//
+// enum CaloricLevel { DIET, NORMAL, FAT };
+//
+// public static void main(String ... args) {
+// System.out.println("Dishes grouped by type: " + groupDishesByType());
+// System.out.println("Dish names grouped by type: " + groupDishNamesByType());
+// System.out.println("Dish tags grouped by type: " + groupDishTagsByType());
+// System.out.println("Caloric dishes grouped by type: " + groupCaloricDishesByType());
+// System.out.println("Dishes grouped by caloric level: " + groupDishesByCaloricLevel());
+// System.out.println("Dishes grouped by type and caloric level: " + groupDishedByTypeAndCaloricLevel());
+// System.out.println("Count dishes in groups: " + countDishesInGroups());
+// System.out.println("Most caloric dishes by type: " + mostCaloricDishesByType());
+// System.out.println("Most caloric dishes by type: " + mostCaloricDishesByTypeWithoutOprionals());
+// System.out.println("Sum calories by type: " + sumCaloriesByType());
+// System.out.println("Caloric levels by type: " + caloricLevelsByType());
+// }
+//
+// private static Map> groupDishesByType() {
+// return menu.stream().collect(groupingBy(Dish::getType));
+// }
+//
+// private static Map> groupDishNamesByType() {
+// return menu.stream().collect(groupingBy(Dish::getType, mapping(Dish::getName, toList())));
+// }
+//
+// private static Map> groupDishTagsByType() {
+// return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet())));
+// }
+//
+// private static Map> groupCaloricDishesByType() {
+//// return menu.stream().filter(dish -> dish.getCalories() > 500).collect(groupingBy(Dish::getType));
+// return menu.stream().collect(groupingBy(Dish::getType, filtering(dish -> dish.getCalories() > 500, toList())));
+// }
+//
+// private static Map> groupDishesByCaloricLevel() {
+// return menu.stream().collect(
+// groupingBy(dish -> {
+// if (dish.getCalories() <= 400) return CaloricLevel.DIET;
+// else if (dish.getCalories() <= 700) return CaloricLevel.NORMAL;
+// else return CaloricLevel.FAT;
+// } ));
+// }
+//
+// private static Map>> groupDishedByTypeAndCaloricLevel() {
+// return menu.stream().collect(
+// groupingBy(Dish::getType,
+// groupingBy((Dish dish) -> {
+// if (dish.getCalories() <= 400) return CaloricLevel.DIET;
+// else if (dish.getCalories() <= 700) return CaloricLevel.NORMAL;
+// else return CaloricLevel.FAT;
+// } )
+// )
+// );
+// }
+//
+// private static Map countDishesInGroups() {
+// return menu.stream().collect(groupingBy(Dish::getType, counting()));
+// }
+//
+// private static Map> mostCaloricDishesByType() {
+// return menu.stream().collect(
+// groupingBy(Dish::getType,
+// reducing((Dish d1, Dish d2) -> d1.getCalories() > d2.getCalories() ? d1 : d2)));
+// }
+//
+// private static Map mostCaloricDishesByTypeWithoutOprionals() {
+// return menu.stream().collect(
+// groupingBy(Dish::getType,
+// collectingAndThen(
+// reducing((d1, d2) -> d1.getCalories() > d2.getCalories() ? d1 : d2),
+// Optional::get)));
+// }
+//
+// private static Map sumCaloriesByType() {
+// return menu.stream().collect(groupingBy(Dish::getType,
+// summingInt(Dish::getCalories)));
+// }
+//
+// private static Map> caloricLevelsByType() {
+// return menu.stream().collect(
+// groupingBy(Dish::getType, mapping(
+// dish -> { if (dish.getCalories() <= 400) return CaloricLevel.DIET;
+// else if (dish.getCalories() <= 700) return CaloricLevel.NORMAL;
+// else return CaloricLevel.FAT; },
+// toSet() )));
+// }
+//}
diff --git a/src/main/java/lambdasinaction/chap6/PartitionPrimeNumbers.java b/src/main/java/lambdasinaction/chap6/PartitionPrimeNumbers.java
index 69d7c4ca..04de7674 100644
--- a/src/main/java/lambdasinaction/chap6/PartitionPrimeNumbers.java
+++ b/src/main/java/lambdasinaction/chap6/PartitionPrimeNumbers.java
@@ -1,106 +1,106 @@
-package lambdasinaction.chap6;
-
-import java.util.*;
-import java.util.function.*;
-import java.util.stream.*;
-
-import static java.util.stream.Collectors.*;
-import static java.util.stream.Collector.Characteristics.*;
-
-public class PartitionPrimeNumbers {
-
- public static void main(String ... args) {
- System.out.println("Numbers partitioned in prime and non-prime: " + partitionPrimes(100));
- System.out.println("Numbers partitioned in prime and non-prime: " + partitionPrimesWithCustomCollector(100));
-
- }
-
- public static Map> partitionPrimes(int n) {
- return IntStream.rangeClosed(2, n).boxed()
- .collect(partitioningBy(candidate -> isPrime(candidate)));
- }
-
- public static boolean isPrime(int candidate) {
- return IntStream.rangeClosed(2, candidate-1)
- .limit((long) Math.floor(Math.sqrt((double) candidate)) - 1)
- .noneMatch(i -> candidate % i == 0);
- }
-
- public static Map> partitionPrimesWithCustomCollector(int n) {
- return IntStream.rangeClosed(2, n).boxed().collect(new PrimeNumbersCollector());
- }
-
- public static boolean isPrime(List primes, Integer candidate) {
- double candidateRoot = Math.sqrt((double) candidate);
- //return takeWhile(primes, i -> i <= candidateRoot).stream().noneMatch(i -> candidate % i == 0);
- return primes.stream().takeWhile(i -> i <= candidateRoot).noneMatch(i -> candidate % i == 0);
- }
-/*
- public static List takeWhile(List list, Predicate p) {
- int i = 0;
- for (A item : list) {
- if (!p.test(item)) {
- return list.subList(0, i);
- }
- i++;
- }
- return list;
- }
-*/
- public static class PrimeNumbersCollector
- implements Collector>, Map>> {
-
- @Override
- public Supplier