I am writing below code but it seems to be awkward. Could it be written better? Finally the code has to create a predicate consisted of list of predicates with OR condition.
First predicate, it shoould be appended to list of predicates
Predicate<SomeDto> p1 = t -> StringUtils.isBlank(t.getColor());
List of predicates from someListOfColors
List<Predicate<SomeDto>> collect = Arrays.stream(somelistOfColors)
.map(ta -> {
Predicate<SomeDto> p2 = t -> t.getColor().equals(ta.getCode());
return p2;
}).collect(Collectors.toList());
All of predicates should be connected with OR condition
or(p1, collect.toArray(new Predicate[collect.size()]));
Method for OR condition
private Predicate<SomeDto> or(Predicate<SomeDto>... predicates) {
return s -> Arrays.stream(predicates).anyMatch(t -> t.test(s));
}