lambda /stream
Last updated
Was this helpful?
Last updated
Was this helpful?
public List<Vehiculo> completeVehiculoFiltrado(String query) {
List<Vehiculo> suggestions = new ArrayList<>();
List<Vehiculo> temp = new ArrayList<>();
try {
Boolean found = false;
query = query.trim();
String field = (String) UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()).getAttributes().get("field");
temp = vehiculoRepository.findRegex(field, query, true, new Document(field, 1));
if (temp.isEmpty()) {
return suggestions;
} else {
List<Vehiculo> validos = temp.stream()
.filter(x -> isVehiculoValid(x)).collect(Collectors.toList());
if (validos.isEmpty()) {
return suggestions;
}
if (vehiculoList.isEmpty()) {
return validos;
} else {
// validos.stream().map((v) -> vehiculoList.stream()
// .filter(x -> v.getIdvehiculo().equals(x.getIdvehiculo()))
// .findAny()
// .orElse(null)).filter((v2) -> (v2 != null)).forEachOrdered((v2) -> {
// suggestions.add(v2);
// });
//
// validos.stream().filter(predicate)
validos.forEach((v) -> {
Optional<Vehiculo> optional = vehiculoList.stream()
.filter(v2 -> v2.getIdvehiculo() == v.getIdvehiculo())
.findAny();
if (!optional.isPresent()) {
suggestions.add(v);
}
});
}
}
// if (vehiculoList.isEmpty()) {
// if (!temp.isEmpty()) {
// for (Vehiculo v : temp) {
// if (isVehiculoValid(v)) {
// suggestions.add(v);
// }
// }
//
// }
//
// } else {
// if (!temp.isEmpty()) {
//
// for (Vehiculo v : temp) {
// found = false;
// for (Vehiculo v2 : vehiculoList) {
// if (v.getIdvehiculo() == v2.getIdvehiculo()) {
// found = true;
// }
// }
// if (!found && v.getActivo().equals("si") && v.getEnreparacion().equals("no")) {
// suggestions.add(v);
// }
//
// }
// }
//
// }
} catch (Exception e) {
JsfUtil.errorMessage("completeVehiculoFiltrado() " + e.getLocalizedMessage());
}
return suggestions;
}