<p:autocomplete> con lambda stream

Consulta en la coleccion y filtra para no mostrar los repetidos y los que tengan los atributos activo="si", en reparacion="no"

 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() // Convert to steam
                        .filter(x -> isVehiculoValid(x)).collect(Collectors.toList());        // we want "jack" only
                if (validos.isEmpty()) {
                    return suggestions;
                }
                if (vehiculoList.isEmpty()) {
                    return validos;
                } else {
                    validos.forEach((v) -> {
                        Optional<Vehiculo> optional = vehiculoList.stream()
                                .filter(v2 -> v2.getIdvehiculo() == v.getIdvehiculo())
                                .findAny();
                        if (!optional.isPresent()) {
                            suggestions.add(v);
                        }
                    });


        } catch (Exception e) {
            JsfUtil.errorMessage("completeVehiculoFiltrado() " + e.getLocalizedMessage());
        }
        return suggestions;
    }

Last updated