Skip to content

Instantly share code, notes, and snippets.

View HDBandit's full-sized avatar

Gerard Vico HDBandit

View GitHub Profile
public class GroupCreateTaskRequest extends AbstractCreateTaskRequest {
private String groupName;
public GroupCreateTaskRequest() {
super(TaskType.GROUP);
}
public String getGroupName() {
return groupName;
public class UserCreateTaskRequest extends AbstractCreateTaskRequest {
private String userName;
public UserCreateTaskRequest() {
super(TaskType.USER);
}
public String getUserName() {
return userName;
@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;
public interface CreateTaskRequest {
String getTitle();
String getDescription();
TaskType getType();
}
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();
public class PersonCompleteInfoDTO {
private String name;
private String surname;
private int age;
private String address;
private String jobLocation;
private int salary;
private String jobCategory;
public class PersonBasicInfoDTO {
private String name;
private String surname;
private int age;
private String address;
public String getName() {
return name;
}
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;
// 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);
}
}
}
...
// 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;
}