Jugando con Java Lambda/Stream
Java ofrece características interesantes
List<Vehiculo> validos = temp.stream()
.filter(x -> isVehiculoValid(x)).collect(Collectors.toList());
validos.forEach((v) -> {
Optional<Vehiculo> optional = vehiculoList.stream()
.filter(v2 -> v2.getIdvehiculo() == v.getIdvehiculo())
.findAny();
if (!optional.isPresent()) {
suggestions.add(v);
}
});
Si no usamos Java 8
for (Vehiculo v : validos) {
found = false;
for (Vehiculo v2 : vehiculoList) {
if (v.getIdvehiculo() == v2.getIdvehiculo()) {
found = true;
}
}
if (!found) {
suggestions.add(v);
}
}
public Boolean isVehiculoValid(Vehiculo vehiculo) {
Boolean valid = false;
try {
if (vehiculo.getActivo().equals("si") && vehiculo.getEnreparacion().equals("no")) {
for (Tipovehiculo t : solicitud.getTipovehiculo()) {
if (vehiculo.getTipovehiculo().getIdtipovehiculo().equals(t.getIdtipovehiculo())) {
valid = true;
break;
}
}
}
} catch (Exception e) {
JsfUtil.errorMessage("isVehiculoValido()) " + e.getLocalizedMessage());
}
return valid;
}
Java ofrece características interesantes
List<Vehiculo> validos = temp.stream()
.filter(x -> isVehiculoValid(x)).collect(Collectors.toList());
validos.forEach((v) -> {
Optional<Vehiculo> optional = vehiculoList.stream()
.filter(v2 -> v2.getIdvehiculo() == v.getIdvehiculo())
.findAny();
if (!optional.isPresent()) {
suggestions.add(v);
}
});
Si no usamos Java 8
for (Vehiculo v : validos) {
found = false;
for (Vehiculo v2 : vehiculoList) {
if (v.getIdvehiculo() == v2.getIdvehiculo()) {
found = true;
}
}
if (!found) {
suggestions.add(v);
}
}
public Boolean isVehiculoValid(Vehiculo vehiculo) {
Boolean valid = false;
try {
if (vehiculo.getActivo().equals("si") && vehiculo.getEnreparacion().equals("no")) {
for (Tipovehiculo t : solicitud.getTipovehiculo()) {
if (vehiculo.getTipovehiculo().getIdtipovehiculo().equals(t.getIdtipovehiculo())) {
valid = true;
break;
}
}
}
} catch (Exception e) {
JsfUtil.errorMessage("isVehiculoValido()) " + e.getLocalizedMessage());
}
return valid;
}
Comments