@Test public void testIpStringAutocomplete_multipleWordsMatcIp() { Map<Ip, IpCompletionMetadata> metadata = ImmutableMap.of( Ip.parse("1.1.2.2"), new IpCompletionMetadata(), Ip.parse("2.2.2.2"), new IpCompletionMetadata()); assertThat( ipStringAutoComplete("1 2", metadata), equalTo(ImmutableList.of(new AutocompleteSuggestion("1.1.2.2", false)))); }
@Nonnull public static ImmutableList<AutocompleteSuggestion> ipStringAutoComplete( @Nullable String query, Map<Ip, IpCompletionMetadata> ips) { String testQuery = query == null ? "" : query.toLowerCase(); String[] subQueries = testQuery.split("\\s+"); Set<Ip> ipMatches = ips.keySet().stream() .filter(e -> Arrays.stream(subQueries).allMatch(sq -> e.toString().contains(sq))) .collect(ImmutableSet.toImmutableSet()); List<AutocompleteSuggestion> relevanceMatches = ips.entrySet().stream() .filter(e -> !ipMatches.contains(e.getKey())) .map( e -> new SimpleEntry<>( e.getKey(), e.getValue().getRelevances().stream() .filter(r -> r.matches(subQueries, e.getKey())) .collect(ImmutableList.toImmutableList()))) .filter(e -> !e.getValue().isEmpty()) .map( e -> AutocompleteSuggestion.builder() .setText(e.getKey().toString()) .setDescription(toDescription(e.getValue())) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList()); return new ImmutableList.Builder<AutocompleteSuggestion>() .addAll( ipMatches.stream() .map( ip -> AutocompleteSuggestion.builder() .setText(ip.toString()) .setDescription(toDescription(ips.get(ip))) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList())) .addAll(relevanceMatches) .build(); }
AutoCompleteUtils { @Nonnull public static ImmutableList<AutocompleteSuggestion> ipStringAutoComplete( @Nullable String query, Map<Ip, IpCompletionMetadata> ips) { String testQuery = query == null ? "" : query.toLowerCase(); String[] subQueries = testQuery.split("\\s+"); Set<Ip> ipMatches = ips.keySet().stream() .filter(e -> Arrays.stream(subQueries).allMatch(sq -> e.toString().contains(sq))) .collect(ImmutableSet.toImmutableSet()); List<AutocompleteSuggestion> relevanceMatches = ips.entrySet().stream() .filter(e -> !ipMatches.contains(e.getKey())) .map( e -> new SimpleEntry<>( e.getKey(), e.getValue().getRelevances().stream() .filter(r -> r.matches(subQueries, e.getKey())) .collect(ImmutableList.toImmutableList()))) .filter(e -> !e.getValue().isEmpty()) .map( e -> AutocompleteSuggestion.builder() .setText(e.getKey().toString()) .setDescription(toDescription(e.getValue())) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList()); return new ImmutableList.Builder<AutocompleteSuggestion>() .addAll( ipMatches.stream() .map( ip -> AutocompleteSuggestion.builder() .setText(ip.toString()) .setDescription(toDescription(ips.get(ip))) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList())) .addAll(relevanceMatches) .build(); } }
AutoCompleteUtils { @Nonnull public static ImmutableList<AutocompleteSuggestion> ipStringAutoComplete( @Nullable String query, Map<Ip, IpCompletionMetadata> ips) { String testQuery = query == null ? "" : query.toLowerCase(); String[] subQueries = testQuery.split("\\s+"); Set<Ip> ipMatches = ips.keySet().stream() .filter(e -> Arrays.stream(subQueries).allMatch(sq -> e.toString().contains(sq))) .collect(ImmutableSet.toImmutableSet()); List<AutocompleteSuggestion> relevanceMatches = ips.entrySet().stream() .filter(e -> !ipMatches.contains(e.getKey())) .map( e -> new SimpleEntry<>( e.getKey(), e.getValue().getRelevances().stream() .filter(r -> r.matches(subQueries, e.getKey())) .collect(ImmutableList.toImmutableList()))) .filter(e -> !e.getValue().isEmpty()) .map( e -> AutocompleteSuggestion.builder() .setText(e.getKey().toString()) .setDescription(toDescription(e.getValue())) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList()); return new ImmutableList.Builder<AutocompleteSuggestion>() .addAll( ipMatches.stream() .map( ip -> AutocompleteSuggestion.builder() .setText(ip.toString()) .setDescription(toDescription(ips.get(ip))) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList())) .addAll(relevanceMatches) .build(); }  }
AutoCompleteUtils { @Nonnull public static ImmutableList<AutocompleteSuggestion> ipStringAutoComplete( @Nullable String query, Map<Ip, IpCompletionMetadata> ips) { String testQuery = query == null ? "" : query.toLowerCase(); String[] subQueries = testQuery.split("\\s+"); Set<Ip> ipMatches = ips.keySet().stream() .filter(e -> Arrays.stream(subQueries).allMatch(sq -> e.toString().contains(sq))) .collect(ImmutableSet.toImmutableSet()); List<AutocompleteSuggestion> relevanceMatches = ips.entrySet().stream() .filter(e -> !ipMatches.contains(e.getKey())) .map( e -> new SimpleEntry<>( e.getKey(), e.getValue().getRelevances().stream() .filter(r -> r.matches(subQueries, e.getKey())) .collect(ImmutableList.toImmutableList()))) .filter(e -> !e.getValue().isEmpty()) .map( e -> AutocompleteSuggestion.builder() .setText(e.getKey().toString()) .setDescription(toDescription(e.getValue())) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList()); return new ImmutableList.Builder<AutocompleteSuggestion>() .addAll( ipMatches.stream() .map( ip -> AutocompleteSuggestion.builder() .setText(ip.toString()) .setDescription(toDescription(ips.get(ip))) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList())) .addAll(relevanceMatches) .build(); }  @Nonnull static List<AutocompleteSuggestion> autoComplete(
      Variable.Type completionType, String query, int maxSuggestions); @Nonnull static List<AutocompleteSuggestion> autoComplete(
      @Nullable String network,
      @Nullable String snapshot,
      Variable.Type completionType,
      String query,
      int maxSuggestions,
      @Nullable CompletionMetadata completionMetadata,
      @Nullable NodeRolesData nodeRolesData,
      @Nullable ReferenceLibrary referenceLibrary); @Nonnull static List<AutocompleteSuggestion> autoComplete(
      @Nullable String network,
      @Nullable String snapshot,
      Variable.Type completionType,
      String query,
      int maxSuggestions,
      @Nullable CompletionMetadata completionMetadata,
      @Nullable NodeRolesData nodeRolesData,
      @Nullable ReferenceLibrary referenceLibrary,
      boolean fuzzyMatching); @Nonnull static List<AutocompleteSuggestion> baseAutoComplete(
      @Nullable String query, Set<String> allProperties); @Nonnull static List<AutocompleteSuggestion> stringAutoComplete(
      @Nullable String query, Set<String> strings); @Nonnull static List<AutocompleteSuggestion> stringAutoComplete(
      @Nullable String query, Map<String, Optional<String>> stringsWithDescriptions); @Nonnull static ImmutableList<AutocompleteSuggestion> ipStringAutoComplete(
      @Nullable String query, Map<Ip, IpCompletionMetadata> ips); }
AutoCompleteUtils { @Nonnull public static ImmutableList<AutocompleteSuggestion> ipStringAutoComplete( @Nullable String query, Map<Ip, IpCompletionMetadata> ips) { String testQuery = query == null ? "" : query.toLowerCase(); String[] subQueries = testQuery.split("\\s+"); Set<Ip> ipMatches = ips.keySet().stream() .filter(e -> Arrays.stream(subQueries).allMatch(sq -> e.toString().contains(sq))) .collect(ImmutableSet.toImmutableSet()); List<AutocompleteSuggestion> relevanceMatches = ips.entrySet().stream() .filter(e -> !ipMatches.contains(e.getKey())) .map( e -> new SimpleEntry<>( e.getKey(), e.getValue().getRelevances().stream() .filter(r -> r.matches(subQueries, e.getKey())) .collect(ImmutableList.toImmutableList()))) .filter(e -> !e.getValue().isEmpty()) .map( e -> AutocompleteSuggestion.builder() .setText(e.getKey().toString()) .setDescription(toDescription(e.getValue())) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList()); return new ImmutableList.Builder<AutocompleteSuggestion>() .addAll( ipMatches.stream() .map( ip -> AutocompleteSuggestion.builder() .setText(ip.toString()) .setDescription(toDescription(ips.get(ip))) .setSuggestionType(SuggestionType.ADDRESS_LITERAL) .build()) .collect(ImmutableList.toImmutableList())) .addAll(relevanceMatches) .build(); }  @Nonnull static List<AutocompleteSuggestion> autoComplete(
      Variable.Type completionType, String query, int maxSuggestions); @Nonnull static List<AutocompleteSuggestion> autoComplete(
      @Nullable String network,
      @Nullable String snapshot,
      Variable.Type completionType,
      String query,
      int maxSuggestions,
      @Nullable CompletionMetadata completionMetadata,
      @Nullable NodeRolesData nodeRolesData,
      @Nullable ReferenceLibrary referenceLibrary); @Nonnull static List<AutocompleteSuggestion> autoComplete(
      @Nullable String network,
      @Nullable String snapshot,
      Variable.Type completionType,
      String query,
      int maxSuggestions,
      @Nullable CompletionMetadata completionMetadata,
      @Nullable NodeRolesData nodeRolesData,
      @Nullable ReferenceLibrary referenceLibrary,
      boolean fuzzyMatching); @Nonnull static List<AutocompleteSuggestion> baseAutoComplete(
      @Nullable String query, Set<String> allProperties); @Nonnull static List<AutocompleteSuggestion> stringAutoComplete(
      @Nullable String query, Set<String> strings); @Nonnull static List<AutocompleteSuggestion> stringAutoComplete(
      @Nullable String query, Map<String, Optional<String>> stringsWithDescriptions); @Nonnull static ImmutableList<AutocompleteSuggestion> ipStringAutoComplete(
      @Nullable String query, Map<Ip, IpCompletionMetadata> ips);  }