Commit c2bde5c5 by Jan Hrabal

maj

parent ff400445
package com.jh.boot.web;
import com.jh.boot.jpa.AbstractIdEntity;
import com.jh.boot.web.list.Page;
import com.jh.boot.web.list.SortTrend;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.jh.boot.jpa.AbstractIdEntity;
import com.jh.boot.web.list.Page;
import com.jh.boot.web.list.SortTrend;
public class Converter {
private Converter() {}
......@@ -42,7 +44,22 @@ public class Converter {
return new Page<D>(page.getPage(), page.getPagesCount(), page.getPageSize(), page.getTotalElements(), content, page.getSortBy(), SortTrend.parse(page.getTrend()));
}
public static <T> List<IdNameDto> mapToDtos(Collection<T> collection, Function<T, Long> getId, Function<T, String> getName) {
if (collection == null || collection.isEmpty() || getId == null || getName == null) {
return Collections.emptyList();
}
List<IdNameDto> result = new ArrayList<IdNameDto>();
for (T t : collection) {
result.add(new IdNameDto(getId.apply(t), getName.apply(t)));
}
return result;
}
//public static <T> T toEntity(IdNameDto )
/**
* Helper function to safely get id
*
......
package com.jh.boot.web;
public class IdNameDto {
private Long id;
private String name;
public IdNameDto() {
}
public IdNameDto(Long id, String name) {
super();
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment