Skip to content

Instantly share code, notes, and snippets.

View HDBandit's full-sized avatar

Gerard Vico HDBandit

View GitHub Profile
List<Car> filteredCars = filterCars(input, car -> {
return "Ferrari".equals(car.getBrand()) && "red".equals(car.getColor());
});
// 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;
}
// 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);
}
}
}
...
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;
public class PersonBasicInfoDTO {
private String name;
private String surname;
private int age;
private String address;
public String getName() {
return name;
}
public class PersonCompleteInfoDTO {
private String name;
private String surname;
private int age;
private String address;
private String jobLocation;
private int salary;
private String jobCategory;
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 interface CreateTaskRequest {
String getTitle();
String getDescription();
TaskType getType();
}
@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 class UserCreateTaskRequest extends AbstractCreateTaskRequest {
private String userName;
public UserCreateTaskRequest() {
super(TaskType.USER);
}
public String getUserName() {
return userName;