Как использовать поток Java8 для этого кода:
Specification<T> specification = specifications.getSpec(searchCriteria.getConditions().get(0));
for(int i = 1; i < searchCriteria.getConditions().size(); i++) {
specification = specification.and(getSpec(searchCriteria.getConditions().get(i)));
}
Использование потока:
IntStream.range(1,searchCriteria.getConditions().size())
.mapToObj(index-> getSpec(searchCriteria.getConditions().get(index)))
.collect();//how to merge with calling and
Связанный класс && method:
@Getter
@Setter
public class SearchCriteria implements Serializable{
private static final long serialVersionUID = 1L;
private List<Condition> conditions;
private Integer limit;
private Integer offset;
@Getter
@Setter
public class Condition{
private String key;
private EConstant.OPERATION operation;
private String value;
}
}
public Specification<T> getSpec(SearchCriteria.Condition condition){
....
}