This file contains hidden or 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
List<Car> filteredCars = filterCars(input, car -> { | |
return "Ferrari".equals(car.getBrand()) && "red".equals(car.getColor()); | |
}); |
This file contains hidden or 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
// business logic | |
public static List<Car> filterCars(List<Car> cars, Predicate<Car> carPredicate) { | |
ArrayList<Car> filteredCars = new ArrayList<Car>(); | |
for (Car car : cars) { | |
if (carPredicate.test(car)) { | |
filteredCars.add(car); | |
} | |
} | |
return filteredCars; | |
} |
This file contains hidden or 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
// business logic | |
public static void processCars(List<Car> cars, Predicate<Car> carPredicate, Consumer<Car> carConsumer) { | |
for (Car car : cars) { | |
if (carPredicate.test(car)) { | |
carConsumer.accept(car); | |
} | |
} | |
} | |
... |
This file contains hidden or 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
package com.hdbandit.orika_mapper; | |
public class Person { | |
private String name; | |
private String surname; | |
private int age; | |
private String address; | |
private String jobLocation; | |
private int salary; |
This file contains hidden or 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
public class PersonBasicInfoDTO { | |
private String name; | |
private String surname; | |
private int age; | |
private String address; | |
public String getName() { | |
return name; | |
} |
This file contains hidden or 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
public class PersonCompleteInfoDTO { | |
private String name; | |
private String surname; | |
private int age; | |
private String address; | |
private String jobLocation; | |
private int salary; | |
private String jobCategory; |
This file contains hidden or 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
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); | |
// map Person-PersonBasicInfoDTO | |
mapperFactory.classMap(Person.class, PersonBasicInfoDTO.class) | |
.byDefault() | |
.register(); | |
// map Person-PersonCompleteInfoDTO | |
mapperFactory.classMap(Person.class, PersonCompleteInfoDTO.class) | |
.byDefault() | |
.register(); |
This file contains hidden or 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
public interface CreateTaskRequest { | |
String getTitle(); | |
String getDescription(); | |
TaskType getType(); | |
} |
This file contains hidden or 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
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "taskType") | |
@JsonSubTypes({ @Type(value = UserCreateTaskRequest.class, name = "user"), @Type(value = GroupCreateTaskRequest.class, name = "group") }) | |
public abstract class AbstractCreateTaskRequest implements CreateTaskRequest { | |
private String title; | |
private String description; | |
private TaskType taskType; | |
public AbstractCreateTaskRequest(TaskType taskType) { | |
this.taskType = taskType; |
This file contains hidden or 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
public class UserCreateTaskRequest extends AbstractCreateTaskRequest { | |
private String userName; | |
public UserCreateTaskRequest() { | |
super(TaskType.USER); | |
} | |
public String getUserName() { | |
return userName; |