There is a method that receives "someObj" and its purpose is to check the var ASet of type Set<>, iterate through it and replace its objects with the database object. For that I written the following code:
if(!CollectionUtils.isEmpty(someObj.getASet())){
someObj.setASet(
someObj.getASet()
.stream()
.map( c -> AService.getExistingA(c.getId()))
.collect(Collectors.toSet())
);
}
It does the purpose but I'm really not happy with it's readability.
Optional.ofNullable(someObj.getASet())
.ifPresent( ASet-> someObj.setASet(
ASet.stream()
.map( c -> AService.getExistingA(c.getId()))
.collect(Collectors.toSet())
));
Now it looks even less readable, can you recommend a better way? I think the worst problem is that someObj.setASet, it simply looks weird, is ther any functional way to replace that object after the collect?