AshwinK:
¿Hay alguna manera de transmitir los lista -> Mapa -> Filtro -> Mapa Volver a tipo de objeto original de la lista?
No hay solución si lo estamos haciendo uso de foreach de la siguiente manera:
List<Query> updatedQueries = getUpdatedQueries();
List<Query> finalQueries = new ArrayList<>();
updatedQueries.forEach(query -> {
Period period = getPeriodRequest(query);
boolean isValidPeriod = periodService.validatePeriodicity(period);
if(isValidPeriod && isMandatory(period)){
finalQueries.add(query);
}
});
Pero ¿hay alguna manera de hacerlo usando manera siguiente?
List<Query> updatedQueries = getUpdatedQueries();
List<Query> finalQueries = updatedQueries
.stream()
.map(this::getPeriodRequest) //returns the object of type Period
.filter(period->periodService.validatePeriodicity(period))
.filter(this::isMandatory)
//is any way we can map back to Query object (without any object translation function)
.collect(Collectors.toList());
Hadi J:
Prueba este
List<Query> finalQueries = updatedQueries
.stream().filter(query->{
Period period = getPeriodRequest(query);
return periodService.validatePeriodicity(period )&& isMandatory(period))
})
.collect(Collectors.toList());