/** * Returns a list of suggestions based on the query. The current implementation treats the query * as a substring of the property string. * * @param query The query that came to the concrete child class * @return The list of suggestions */ public static List<AutocompleteSuggestion> baseAutoComplete( @Nullable String query, Set<String> allProperties) { String finalQuery = firstNonNull(query, "").toLowerCase(); ImmutableList.Builder<AutocompleteSuggestion> suggestions = new ImmutableList.Builder<>(); String queryWithStars = ".*" + (finalQuery.isEmpty() ? "" : finalQuery + ".*"); Pattern queryPattern = safeGetPattern(queryWithStars); /* * if queryWithStars is not a valid Pattern, finalQuery must be a funky string that will not * match anything as string.contains or regex.matches; so we skip formalities altogether */ if (queryPattern != null) { suggestions.addAll( allProperties.stream() .filter(prop -> queryPattern.matcher(prop.toLowerCase()).matches()) .map(prop -> new AutocompleteSuggestion(prop, false)) .collect(Collectors.toList())); } return suggestions.build(); }