- Collection<MapEntryNode> candidates = ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getValue();
- Collection<String> candidateNames = new ArrayList<>(candidates.size());
- for (MapEntryNode candidate: candidates) {
- candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
- }
-
- return candidateNames;
+ return entity.getChild(CANDIDATE_NODE_ID).map(child -> {
+ Collection<MapEntryNode> candidates = ((MapNode) child).getValue();
+ Collection<String> candidateNames = new ArrayList<>(candidates.size());
+ for (MapEntryNode candidate: candidates) {
+ candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
+ }
+ return candidateNames;
+ }).orElse(ImmutableList.of());