diff options
author | Harald Musum <musum@verizonmedia.com> | 2022-12-02 23:09:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 23:09:25 +0100 |
commit | afcf1bb71cb7b87a03149d197f724cfc7603ef92 (patch) | |
tree | fff1df3e68101edc3d3d3b98b5eb51b7758c209c /container-search/src/main/java/com/yahoo/prelude/IndexFacts.java | |
parent | 7f870bf3cb8dd0a3d015a448608ba7291a783932 (diff) | |
parent | fcf664e1a6bb9890bd54ff4f8b78497236152bf2 (diff) |
Merge pull request #25096 from vespa-engine/revert-25091-revert-25088-balder/immutablelist-2-listv8.94.46
Revert "Revert "Let list handling catch up with Java 17""
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/IndexFacts.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/IndexFacts.java | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java index c9a855c2f34..90194f3ba6a 100644 --- a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java +++ b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java @@ -1,10 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude; -import com.google.common.collect.ImmutableList; import com.yahoo.search.Query; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import static com.yahoo.text.Lowercase.toLowerCase; @@ -57,7 +63,6 @@ public class IndexFacts { public IndexFacts() {} - @SuppressWarnings({"deprecation"}) public IndexFacts(IndexModel indexModel) { if (indexModel.getSearchDefinitions() != null) { this.searchDefinitions = indexModel.getSearchDefinitions(); @@ -85,20 +90,16 @@ public class IndexFacts { } private static void addEntry(Map<String, List<String>> result, String key, String value) { - List<String> values = result.get(key); - if (values == null) { - values = new ArrayList<>(); - result.put(key, values); - } + List<String> values = result.computeIfAbsent(key, k -> new ArrayList<>()); values.add(value); } // Assumes that document names are equal to the search definition that contain them. public List<String> clustersHavingSearchDefinition(String searchDefinitionName) { - if (clusterByDocument == null) return Collections.emptyList(); + if (clusterByDocument == null) return List.of(); List<String> clusters = clusterByDocument.get(searchDefinitionName); - return clusters != null ? clusters : Collections.<String>emptyList(); + return clusters != null ? clusters : List.of(); } private boolean isInitialized() { @@ -168,9 +169,9 @@ public class IndexFacts { } private Collection<Index> getIndexes(String documentType) { - if ( ! isInitialized()) return Collections.emptyList(); + if ( ! isInitialized()) return List.of(); SearchDefinition sd = searchDefinitions.get(documentType); - if (sd == null) return Collections.emptyList(); + if (sd == null) return List.of(); return sd.indices().values(); } @@ -231,7 +232,7 @@ public class IndexFacts { } private Collection<String> emptyCollectionIfNull(Collection<String> collection) { - return collection == null ? Collections.<String>emptyList() : collection; + return collection == null ? List.of() : collection; } /** @@ -318,7 +319,7 @@ public class IndexFacts { private final List<String> documentTypes; private Session(Query query) { - documentTypes = ImmutableList.copyOf(resolveDocumentTypes(query)); + documentTypes = List.copyOf(resolveDocumentTypes(query)); } private Session(Collection<String> sources, Collection<String> restrict) { @@ -347,7 +348,7 @@ public class IndexFacts { // currently by the flat structure in IndexFacts. // That can be fixed without changing this API. public Index getIndex(String indexName, String documentType) { - return IndexFacts.this.getIndexFromDocumentTypes(indexName, Collections.singletonList(documentType)); + return IndexFacts.this.getIndexFromDocumentTypes(indexName, List.of(documentType)); } /** Returns all the indexes of a given search definition */ |