* Adding code to java core and deleting it from java-8

* removing failed unittest

* removing space
This commit is contained in:
kyleandari 2019-01-05 13:25:22 -05:00 committed by maibin
parent fe44881bb1
commit 2d8ea6d287
24 changed files with 61 additions and 217 deletions

View File

@ -1,22 +0,0 @@
package com.baeldung.interfaces;
public interface Electronic {
//Constant variable
public static final String LED = "LED";
//Abstract method
public int getElectricityUse();
// Static method
public static boolean isEnergyEfficient(String electtronicType) {
if (electtronicType.equals(LED)) {
return true;
}
return false;
}
//Default method
public default void printDescription() {
System.out.println("Electronic Description");
}
}

View File

@ -1,10 +0,0 @@
package com.baeldung.interfaces;
import com.baeldung.interfaces.multiinheritance.Transform;
public class Motorcycle implements Transform {
@Override
public void transform() {
// Implementation
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.interfaces;
public class Truck extends Vehicle {
@Override
public void transform() {
// implementation
}
}

View File

@ -1,6 +0,0 @@
package com.baeldung.interfaces;
import com.baeldung.interfaces.multiinheritance.Transform;
public abstract class Vehicle implements Transform {
}

View File

@ -1,13 +0,0 @@
package com.baeldung.interfaces.multiinheritance;
public class Vehicle implements Fly, Transform {
@Override
public void fly() {
System.out.println("I can Fly!!");
}
@Override
public void transform() {
System.out.println("I can Transform!!");
}
}

View File

@ -1,25 +0,0 @@
package com.baeldung.interfaces.polymorphysim;
public class Circle implements Shape {
private double radius;
public Circle(double radius){
this.radius = radius;
}
@Override
public String name() {
return "Circle";
}
@Override
public double area() {
return Math.PI * (radius * radius);
}
@Override
public String getColor() {
return "green";
}
}

View File

@ -1,26 +0,0 @@
package com.baeldung.interfaces.polymorphysim;
import java.util.ArrayList;
public class DisplayShape {
private ArrayList<Shape> shapes;
public ArrayList<Shape> getShapes() {
return shapes;
}
public DisplayShape() {
shapes = new ArrayList<>();
}
public void add(Shape shape) {
shapes.add(shape);
}
public void display() {
for (Shape shape : shapes) {
System.out.println(shape.name() + " area: " + shape.area());
}
}
}

View File

@ -1,23 +0,0 @@
package com.baeldung.interfaces.polymorphysim;
import java.util.function.Predicate;
public class FunctionalMain {
public static void main(String[] args) {
Shape circleShape = new Circle(2);
Shape squareShape = new Square(2);
DisplayShape DisplayShape = new DisplayShape();
DisplayShape.add(circleShape);
DisplayShape.add(squareShape);
Predicate<Shape> checkArea = (shape) -> shape.area() < 5;
for (Shape shape : DisplayShape.getShapes()) {
if (checkArea.test(shape)) {
System.out.println(shape.name() + " " + shape.area());
}
}
}
}

View File

@ -1,15 +0,0 @@
package com.baeldung.interfaces.polymorphysim;
public class MainPolymorphic {
public static void main(String[] args){
Shape circleShape = new Circle(2);
Shape squareShape = new Square(2);
DisplayShape displayShape = new DisplayShape();
displayShape.add(circleShape);
displayShape.add(squareShape);
displayShape.display();
}
}

View File

@ -1,9 +0,0 @@
package com.baeldung.interfaces.polymorphysim;
import com.baeldung.interfaces.HasColor;
public interface Shape extends HasColor {
public abstract String name();
public abstract double area();
}

View File

@ -1,25 +0,0 @@
package com.baeldung.interfaces.polymorphysim;
public class Square implements Shape {
private double width;
public Square(double width) {
this.width = width;
}
@Override
public String name() {
return "Square";
}
@Override
public double area() {
return width * width;
}
@Override
public String getColor() {
return "red";
}
}

View File

@ -1,26 +0,0 @@
package com.baeldung.interfaces;
import com.baeldung.interfaces.polymorphysim.Circle;
import com.baeldung.interfaces.polymorphysim.Shape;
import com.baeldung.interfaces.polymorphysim.Square;
import org.assertj.core.api.Assertions;
import org.junit.Test;
public class PolymorphysimUnitTest {
@Test
public void whenInterfacePointsToCircle_CircleAreaMethodisBeingCalled(){
double expectedArea = 12.566370614359172;
Shape circle = new Circle(2);
double actualArea = circle.area();
Assertions.assertThat(actualArea).isEqualTo(expectedArea);
}
@Test
public void whenInterfacePointsToSquare_SquareAreaMethodisBeingCalled(){
double expectedArea = 4;
Shape square = new Square(2);
double actualArea = square.area();
Assertions.assertThat(actualArea).isEqualTo(expectedArea);
}
}

View File

@ -0,0 +1,5 @@
package com.baeldung.interfaces;
public interface Box extends HasColor {
int getHeight();
}

View File

@ -11,5 +11,4 @@ public class Employee {
public void setSalary(double salary) { public void setSalary(double salary) {
this.salary = salary; this.salary = salary;
} }
} }

View File

@ -6,12 +6,11 @@ public class EmployeeSalaryComparator implements Comparator<Employee> {
@Override @Override
public int compare(Employee employeeA, Employee employeeB) { public int compare(Employee employeeA, Employee employeeB) {
if (employeeA.getSalary() < employeeB.getSalary()) {
if(employeeA.getSalary() < employeeB.getSalary()){
return -1; return -1;
}else if(employeeA.getSalary() > employeeB.getSalary()){ } else if (employeeA.getSalary() > employeeB.getSalary()) {
return 1; return 1;
}else{ } else {
return 0; return 0;
} }
} }

View File

@ -1,5 +1,4 @@
package com.baeldung.interfaces; package com.baeldung.interfaces;
public interface HasColor { public interface HasColor {
public String getColor();
} }

View File

@ -1,6 +1,7 @@
package com.baeldung.interfaces.multiinheritance; package com.baeldung.interfaces.multiinheritance;
public class Car implements Fly, Transform { public class Car implements Fly,Transform {
@Override @Override
public void fly() { public void fly() {
System.out.println("I can Fly!!"); System.out.println("I can Fly!!");

View File

@ -1,5 +1,6 @@
package com.baeldung.interfaces.multiinheritance; package com.baeldung.interfaces.multiinheritance;
public abstract interface Fly{ public interface Fly {
void fly(); void fly();
} }

View File

@ -0,0 +1,4 @@
package com.baeldung.interfaces.multiinheritance;
public abstract class Vehicle implements Transform {
}

View File

@ -0,0 +1,9 @@
package com.baeldung.interfaces.polymorphysim;
public class Circle implements Shape {
@Override
public String name() {
return "Circle";
}
}

View File

@ -0,0 +1,20 @@
package com.baeldung.interfaces.polymorphysim;
import java.util.ArrayList;
import java.util.List;
public class MainTestClass {
public static void main(String[] args) {
List<Shape> shapes = new ArrayList<>();
Shape circleShape = new Circle();
Shape squareShape = new Square();
shapes.add(circleShape);
shapes.add(squareShape);
for (Shape shape : shapes) {
System.out.println(shape.name());
}
}
}

View File

@ -0,0 +1,6 @@
package com.baeldung.interfaces.polymorphysim;
public interface Shape {
String name();
}

View File

@ -0,0 +1,9 @@
package com.baeldung.interfaces.polymorphysim;
public class Square implements Shape {
@Override
public String name() {
return "Square";
}
}