diff --git a/core-java-8/src/main/java/com/baeldung/doublecolumn/Computer.java b/core-java-8/src/main/java/com/baeldung/doublecolon/Computer.java similarity index 84% rename from core-java-8/src/main/java/com/baeldung/doublecolumn/Computer.java rename to core-java-8/src/main/java/com/baeldung/doublecolon/Computer.java index 18867a2354..9535740309 100644 --- a/core-java-8/src/main/java/com/baeldung/doublecolumn/Computer.java +++ b/core-java-8/src/main/java/com/baeldung/doublecolon/Computer.java @@ -1,4 +1,4 @@ -package com.baeldung.doublecolumn; +package com.baeldung.doublecolon; public class Computer { @@ -44,6 +44,18 @@ public class Computer { this.healty = healty; } + public void turnOnPc() { + System.out.println("Computer turned on"); + } + + public void turnOffPc() { + System.out.println("Computer turned off"); + } + + public Double calculateValue(Double initialValue) { + return initialValue/1.50; + } + @Override public String toString() { return "Computer{" + "age=" + age + ", color='" + color + '\'' + ", healty=" + healty + '}'; diff --git a/core-java-8/src/main/java/com/baeldung/doublecolumn/ComputerUtils.java b/core-java-8/src/main/java/com/baeldung/doublecolon/ComputerUtils.java similarity index 87% rename from core-java-8/src/main/java/com/baeldung/doublecolumn/ComputerUtils.java rename to core-java-8/src/main/java/com/baeldung/doublecolon/ComputerUtils.java index 5c255313a7..d181dfcdf7 100644 --- a/core-java-8/src/main/java/com/baeldung/doublecolumn/ComputerUtils.java +++ b/core-java-8/src/main/java/com/baeldung/doublecolon/ComputerUtils.java @@ -1,10 +1,10 @@ -package com.baeldung.doublecolumn; +package com.baeldung.doublecolon; + +import com.baeldung.doublecolon.function.ComputerPredicate; import java.util.ArrayList; import java.util.List; -import com.baeldung.doublecolumn.function.ComputerPredicate; - public class ComputerUtils { public static final ComputerPredicate after2010Predicate = (c) -> (c.getAge() > 2010); diff --git a/core-java-8/src/main/java/com/baeldung/doublecolon/MacbookPro.java b/core-java-8/src/main/java/com/baeldung/doublecolon/MacbookPro.java new file mode 100644 index 0000000000..673429132a --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/doublecolon/MacbookPro.java @@ -0,0 +1,35 @@ +package com.baeldung.doublecolon; + +import java.util.function.Function; + + +public class MacbookPro extends Computer{ + + public MacbookPro(int age, String color) { + super(age, color); + } + + public MacbookPro(Integer age, String color, Integer healty) { + super(age, color, healty); + } + + @Override + public void turnOnPc() { + System.out.println("MacbookPro turned on"); + } + + @Override + public void turnOffPc() { + System.out.println("MacbookPro turned off"); + } + + @Override + public Double calculateValue(Double initialValue){ + + Function function = super::calculateValue; + final Double pcValue = function.apply(initialValue); + System.out.println("First value is:" +pcValue); + return pcValue + (initialValue/10) ; + + } +} diff --git a/core-java-8/src/main/java/com/baeldung/doublecolumn/function/ComputerPredicate.java b/core-java-8/src/main/java/com/baeldung/doublecolon/function/ComputerPredicate.java similarity index 52% rename from core-java-8/src/main/java/com/baeldung/doublecolumn/function/ComputerPredicate.java rename to core-java-8/src/main/java/com/baeldung/doublecolon/function/ComputerPredicate.java index 94cf0a2be7..5ce491e86a 100644 --- a/core-java-8/src/main/java/com/baeldung/doublecolumn/function/ComputerPredicate.java +++ b/core-java-8/src/main/java/com/baeldung/doublecolon/function/ComputerPredicate.java @@ -1,6 +1,6 @@ -package com.baeldung.doublecolumn.function; +package com.baeldung.doublecolon.function; -import com.baeldung.doublecolumn.Computer; +import com.baeldung.doublecolon.Computer; @FunctionalInterface public interface ComputerPredicate { diff --git a/core-java-8/src/main/java/com/baeldung/doublecolumn/function/TriFunction.java b/core-java-8/src/main/java/com/baeldung/doublecolon/function/TriFunction.java similarity index 89% rename from core-java-8/src/main/java/com/baeldung/doublecolumn/function/TriFunction.java rename to core-java-8/src/main/java/com/baeldung/doublecolon/function/TriFunction.java index 1fb13b9ced..d0d6299479 100644 --- a/core-java-8/src/main/java/com/baeldung/doublecolumn/function/TriFunction.java +++ b/core-java-8/src/main/java/com/baeldung/doublecolon/function/TriFunction.java @@ -1,4 +1,4 @@ -package com.baeldung.doublecolumn.function; +package com.baeldung.doublecolon.function; import java.util.Objects; import java.util.function.Function; diff --git a/core-java-8/src/test/java/com/baeldung/doublecolumn/TestComputerUtils.java b/core-java-8/src/test/java/com/baeldung/doublecolon/TestComputerUtils.java similarity index 67% rename from core-java-8/src/test/java/com/baeldung/doublecolumn/TestComputerUtils.java rename to core-java-8/src/test/java/com/baeldung/doublecolon/TestComputerUtils.java index c46630ec13..06cf1cf749 100644 --- a/core-java-8/src/test/java/com/baeldung/doublecolumn/TestComputerUtils.java +++ b/core-java-8/src/test/java/com/baeldung/doublecolon/TestComputerUtils.java @@ -1,6 +1,6 @@ -package com.baeldung.doublecolumn; +package com.baeldung.doublecolon; -import com.baeldung.doublecolumn.function.TriFunction; +import com.baeldung.doublecolon.function.TriFunction; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -9,7 +9,7 @@ import org.junit.Test; import java.util.*; import java.util.function.BiFunction; -import static com.baeldung.doublecolumn.ComputerUtils.*; +import static com.baeldung.doublecolon.ComputerUtils.*; public class TestComputerUtils { @@ -22,7 +22,7 @@ public class TestComputerUtils { } @Test - public void testFilter() { + public void testConstructorReference() { Computer c1 = new Computer(2015, "white"); Computer c2 = new Computer(2009, "black"); @@ -53,7 +53,7 @@ public class TestComputerUtils { } @Test - public void testRepair() { + public void testStaticMethodReference() { Computer c1 = new Computer(2015, "white", 35); Computer c2 = new Computer(2009, "black", 65); @@ -66,4 +66,24 @@ public class TestComputerUtils { Assert.assertEquals("Computer repaired", new Integer(100), c1.getHealty()); } + @Test + public void testInstanceMethodArbitraryObjectParticularType() { + + Computer c1 = new Computer(2015, "white", 35); + Computer c2 = new MacbookPro(2009, "black", 65); + List inventory = Arrays.asList(c1, c2); + inventory.forEach(Computer::turnOnPc); + + } + + @Test + public void testSuperMethodReference() { + + final TriFunction integerStringIntegerObjectTriFunction = MacbookPro::new; + final MacbookPro macbookPro = integerStringIntegerObjectTriFunction.apply(2010, "black",100); + Double initialValue=new Double(999.99); + final Double actualValue = macbookPro.calculateValue(initialValue); + Assert.assertEquals(766.659, actualValue,0.0); + } + }