commit
da40afeeeb
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.doublecolumn;
|
package com.baeldung.doublecolon;
|
||||||
|
|
||||||
public class Computer {
|
public class Computer {
|
||||||
|
|
||||||
|
@ -44,6 +44,18 @@ public class Computer {
|
||||||
this.healty = healty;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Computer{" + "age=" + age + ", color='" + color + '\'' + ", healty=" + healty + '}';
|
return "Computer{" + "age=" + age + ", color='" + color + '\'' + ", healty=" + healty + '}';
|
|
@ -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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.baeldung.doublecolumn.function.ComputerPredicate;
|
|
||||||
|
|
||||||
public class ComputerUtils {
|
public class ComputerUtils {
|
||||||
|
|
||||||
public static final ComputerPredicate after2010Predicate = (c) -> (c.getAge() > 2010);
|
public static final ComputerPredicate after2010Predicate = (c) -> (c.getAge() > 2010);
|
|
@ -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<Double,Double> function = super::calculateValue;
|
||||||
|
final Double pcValue = function.apply(initialValue);
|
||||||
|
System.out.println("First value is:" +pcValue);
|
||||||
|
return pcValue + (initialValue/10) ;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
@FunctionalInterface
|
||||||
public interface ComputerPredicate {
|
public interface ComputerPredicate {
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.doublecolumn.function;
|
package com.baeldung.doublecolon.function;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
|
@ -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.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -9,7 +9,7 @@ import org.junit.Test;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import static com.baeldung.doublecolumn.ComputerUtils.*;
|
import static com.baeldung.doublecolon.ComputerUtils.*;
|
||||||
|
|
||||||
public class TestComputerUtils {
|
public class TestComputerUtils {
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class TestComputerUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilter() {
|
public void testConstructorReference() {
|
||||||
|
|
||||||
Computer c1 = new Computer(2015, "white");
|
Computer c1 = new Computer(2015, "white");
|
||||||
Computer c2 = new Computer(2009, "black");
|
Computer c2 = new Computer(2009, "black");
|
||||||
|
@ -53,7 +53,7 @@ public class TestComputerUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepair() {
|
public void testStaticMethodReference() {
|
||||||
|
|
||||||
Computer c1 = new Computer(2015, "white", 35);
|
Computer c1 = new Computer(2015, "white", 35);
|
||||||
Computer c2 = new Computer(2009, "black", 65);
|
Computer c2 = new Computer(2009, "black", 65);
|
||||||
|
@ -66,4 +66,24 @@ public class TestComputerUtils {
|
||||||
Assert.assertEquals("Computer repaired", new Integer(100), c1.getHealty());
|
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<Computer> inventory = Arrays.asList(c1, c2);
|
||||||
|
inventory.forEach(Computer::turnOnPc);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuperMethodReference() {
|
||||||
|
|
||||||
|
final TriFunction<Integer, String, Integer, MacbookPro> 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue