forked from java8/Java8InAction
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9c7a38
commit b734604
Showing
75 changed files
with
148 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/lambdasinaction/chap9/Car.java → ...main/java/lambdasinaction/chap10/Car.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap9; | ||
package lambdasinaction.chap10; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...java/lambdasinaction/chap9/Insurance.java → ...ava/lambdasinaction/chap10/Insurance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap9; | ||
package lambdasinaction.chap10; | ||
|
||
public class Insurance { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...naction/chap9/OperationsWithOptional.java → ...action/chap10/OperationsWithOptional.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap9; | ||
package lambdasinaction.chap10; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...a/lambdasinaction/chap9/OptionalMain.java → .../lambdasinaction/chap10/OptionalMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap9; | ||
package lambdasinaction.chap10; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...in/java/lambdasinaction/chap9/Person.java → ...n/java/lambdasinaction/chap10/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap9; | ||
package lambdasinaction.chap10; | ||
|
||
import java.util.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...sinaction/chap9/ReadPositiveIntParam.java → ...inaction/chap10/ReadPositiveIntParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap9; | ||
package lambdasinaction.chap10; | ||
|
||
import org.junit.*; | ||
|
||
|
6 changes: 3 additions & 3 deletions
6
...ava/lambdasinaction/chap10/AsyncShop.java → ...ava/lambdasinaction/chap11/AsyncShop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mbdasinaction/chap10/AsyncShopClient.java → ...mbdasinaction/chap11/AsyncShopClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap10; | ||
package lambdasinaction.chap11; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...mbdasinaction/chap10/BestPriceFinder.java → ...mbdasinaction/chap11/BestPriceFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap10; | ||
package lambdasinaction.chap11; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
2 changes: 1 addition & 1 deletion
2
...sinaction/chap10/BestPriceFinderMain.java → ...sinaction/chap11/BestPriceFinderMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...java/lambdasinaction/chap10/Discount.java → ...java/lambdasinaction/chap11/Discount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...mbdasinaction/chap10/ExchangeService.java → ...mbdasinaction/chap11/ExchangeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...in/java/lambdasinaction/chap10/Quote.java → ...in/java/lambdasinaction/chap11/Quote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap10; | ||
package lambdasinaction.chap11; | ||
|
||
public class Quote { | ||
|
||
|
6 changes: 3 additions & 3 deletions
6
...ain/java/lambdasinaction/chap10/Shop.java → ...ain/java/lambdasinaction/chap11/Shop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ain/java/lambdasinaction/chap10/Util.java → ...ain/java/lambdasinaction/chap11/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...action/chap10/v1/BestPriceFinderMain.java → ...action/chap11/v1/BestPriceFinderMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../java/lambdasinaction/chap10/v1/Shop.java → .../java/lambdasinaction/chap11/v1/Shop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a/lambdasinaction/chap10/v1/ShopMain.java → ...a/lambdasinaction/chap11/v1/ShopMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...bdasinaction/chap11/DateTimeExamples.java → ...bdasinaction/chap12/DateTimeExamples.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ava/lambdasinaction/chap12/Recursion.java → ...ava/lambdasinaction/chap13/Recursion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap12; | ||
package lambdasinaction.chap13; | ||
|
||
import java.util.stream.LongStream; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...a/lambdasinaction/chap12/SubsetsMain.java → ...a/lambdasinaction/chap13/SubsetsMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a/lambdasinaction/chap13/Combinators.java → ...a/lambdasinaction/chap14/Combinators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap13; | ||
package lambdasinaction.chap14; | ||
|
||
import java.util.function.Function; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...java/lambdasinaction/chap13/Currying.java → ...java/lambdasinaction/chap14/Currying.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap13; | ||
package lambdasinaction.chap14; | ||
|
||
import java.util.function.DoubleUnaryOperator; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ava/lambdasinaction/chap13/LazyLists.java → ...ava/lambdasinaction/chap14/LazyLists.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mbdasinaction/chap13/PatternMatching.java → ...mbdasinaction/chap14/PatternMatching.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...action/chap13/PersistentTrainJourney.java → ...action/chap14/PersistentTrainJourney.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap13; | ||
package lambdasinaction.chap14; | ||
|
||
import java.util.function.Consumer; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ambdasinaction/chap13/PersistentTree.java → ...ambdasinaction/chap14/PersistentTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap13; | ||
package lambdasinaction.chap14; | ||
|
||
public class PersistentTree { | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...java/lambdasinaction/chap4/Filtering.java → ...java/lambdasinaction/chap5/Filtering.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...n/java/lambdasinaction/chap4/Finding.java → ...n/java/lambdasinaction/chap5/Finding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../java/lambdasinaction/chap4/Laziness.java → .../java/lambdasinaction/chap5/Laziness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap4; | ||
package lambdasinaction.chap5; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
4 changes: 3 additions & 1 deletion
4
...n/java/lambdasinaction/chap4/Mapping.java → ...n/java/lambdasinaction/chap5/Mapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...lambdasinaction/chap4/NumericStreams.java → ...lambdasinaction/chap5/NumericStreams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
...asinaction/chap4/PuttingIntoPractice.java → ...asinaction/chap5/PuttingIntoPractice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
package lambdasinaction.chap5; | ||
import lambdasinaction.chap4.*; | ||
|
||
import java.util.*; | ||
import java.util.function.*; | ||
import java.util.stream.*; | ||
import java.util.*; | ||
|
||
import static java.util.stream.Collectors.*; | ||
import static lambdasinaction.chap5.Dish.menu; | ||
import static lambdasinaction.chap4.Dish.menu; | ||
|
||
public class Reducing { | ||
public class Reducing{ | ||
|
||
public static void main(String ... args) { | ||
System.out.println("Total calories in menu: " + calculateTotalCalories()); | ||
System.out.println("Total calories in menu: " + calculateTotalCaloriesWithMethodReference()); | ||
System.out.println("Total calories in menu: " + calculateTotalCaloriesWithoutCollectors()); | ||
System.out.println("Total calories in menu: " + calculateTotalCaloriesUsingSum()); | ||
} | ||
public static void main(String...args){ | ||
|
||
private static int calculateTotalCalories() { | ||
return menu.stream().collect(reducing(0, Dish::getCalories, (Integer i, Integer j) -> i + j)); | ||
} | ||
List<Integer> numbers = Arrays.asList(3,4,5,1,2); | ||
int sum = numbers.stream().reduce(0, (a, b) -> a + b); | ||
System.out.println(sum); | ||
|
||
private static int calculateTotalCaloriesWithMethodReference() { | ||
return menu.stream().collect(reducing(0, Dish::getCalories, Integer::sum)); | ||
} | ||
int sum2 = numbers.stream().reduce(0, Integer::sum); | ||
System.out.println(sum2); | ||
|
||
private static int calculateTotalCaloriesWithoutCollectors() { | ||
return menu.stream().map(Dish::getCalories).reduce(Integer::sum).get(); | ||
} | ||
int max = numbers.stream().reduce(0, (a, b) -> Integer.max(a, b)); | ||
System.out.println(max); | ||
|
||
Optional<Integer> min = numbers.stream().reduce(Integer::min); | ||
min.ifPresent(System.out::println); | ||
|
||
private static int calculateTotalCaloriesUsingSum() { | ||
return menu.stream().mapToInt(Dish::getCalories).sum(); | ||
int calories = menu.stream() | ||
.map(Dish::getCalories) | ||
.reduce(0, Integer::sum); | ||
System.out.println("Number of calories:" + calories); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...in/java/lambdasinaction/chap4/Trader.java → ...in/java/lambdasinaction/chap5/Trader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap4; | ||
package lambdasinaction.chap5; | ||
public class Trader{ | ||
|
||
private String name; | ||
|
3 changes: 2 additions & 1 deletion
3
...va/lambdasinaction/chap4/Transaction.java → ...va/lambdasinaction/chap5/Transaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package lambdasinaction.chap4; | ||
package lambdasinaction.chap5; | ||
|
||
public class Transaction{ | ||
|
||
private Trader trader; | ||
|
4 changes: 1 addition & 3 deletions
4
...mbdasinaction/chap5/CollectorHarness.java → ...mbdasinaction/chap6/CollectorHarness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main/java/lambdasinaction/chap5/Dish.java → ...main/java/lambdasinaction/chap6/Dish.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lambdasinaction.chap5; | ||
package lambdasinaction.chap6; | ||
|
||
import java.util.*; | ||
|
||
|
Oops, something went wrong.