private Collection<NodeMatch> matchReferenceField(QueryPath queryPath, Iterable<FormTree.Node> fields) { List<Collection<NodeMatch>> matches = Lists.newArrayList(); for (FormTree.Node field : fields) { if(field.getType() instanceof ReferenceType) { Collection<NodeMatch> result = unionMatches(queryPath, field); if (!result.isEmpty()) { matches.add(result); } } else if(field.getType() instanceof EnumType) { Optional<NodeMatch> result = matchEnum(queryPath, field); if(result.isPresent()) { matches.add(Collections.singleton(result.get())); } } else if(field.getType() instanceof GeoPointType) { matchCoordinate(queryPath, field).ifPresent(match -> { matches.add(Collections.singleton(match)); }); } } if(matches.size() > 0) { return matches.get(0); } // If no results, check search at the next level List<FormTree.Node> children = childrenOf(fields); if(children.isEmpty()) { return Collections.emptyList(); } else { return matchReferenceField(queryPath, children); } }
List<FormTree.Node> children = childrenOf(fields); if(children.isEmpty()) { return Collections.emptyList();