From 13f2eef879859dab437d6199ce717ecc75096536 Mon Sep 17 00:00:00 2001 From: pivovarit Date: Mon, 6 Feb 2017 09:05:55 +0100 Subject: [PATCH] Fix Discounter examples --- core-java/src/main/java/com/baeldung/strategy/Discounter.java | 4 ++++ .../com/baeldung/strategy/StrategyDesignPatternUnitTest.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core-java/src/main/java/com/baeldung/strategy/Discounter.java b/core-java/src/main/java/com/baeldung/strategy/Discounter.java index 4701287946..00bf4855d1 100644 --- a/core-java/src/main/java/com/baeldung/strategy/Discounter.java +++ b/core-java/src/main/java/com/baeldung/strategy/Discounter.java @@ -5,6 +5,10 @@ import java.util.function.UnaryOperator; public interface Discounter extends UnaryOperator { + default Discounter combine(Discounter after) { + return value -> after.apply(this.apply(value)); + } + static Discounter christmas() { return (amount) -> amount.multiply(BigDecimal.valueOf(0.9)); } diff --git a/core-java/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java b/core-java/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java index 2c1c166b9c..7ca1d000be 100644 --- a/core-java/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java +++ b/core-java/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java @@ -57,7 +57,7 @@ public class StrategyDesignPatternUnitTest { final Discounter combinedDiscounter = discounters .stream() - .reduce(v -> v, (d1, d2) -> (Discounter) d1.andThen(d2)); + .reduce(v -> v, Discounter::combine); combinedDiscounter.apply(amount); }