In a scenario where a map of coreValues contains: Value 1 -> List("1", "2", null, "3") I want to filter out null values from the list, i have below solution:
boolean hasCoreValues = false;
Optional<Map<String,List<String>> coreValues = buildCoreValuesMap(core);
hasCoreValues = corevalues.map(cv -> {
final List<String> values = cv.getOrDefault(value, Immutable.of())
values.removeAll(singletonList(null));
return !values.isEmpty();
}).orElse(false);
public Optional<Map<String, List<String>>> buildCoreValuesMap(String core) {
return Optional.ofNullable(context.selectFrom(DataStorage)
.where(DataStorage.CORE.in(core))
.fetchGroups(DataStorage.CORE,
DataStorage.VALUES));
}
is there a better way to do it without going thru the list again to remove the null?