summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2022-12-02 14:52:26 +0100
committerGitHub <noreply@github.com>2022-12-02 14:52:26 +0100
commit81b884ac555806ae2f0a75773accfd8fe27ecbe1 (patch)
tree0f92b9ef73a90854cacc96796562d3f21ff1cff6 /container-search/src/main/java/com/yahoo/prelude
parentc956ac4cb73b329243072aabe35f0da508c02d0f (diff)
Revert "Let list handling catch up with Java 17"
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/IndexFacts.java31
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java8
2 files changed, 20 insertions, 19 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 90194f3ba6a..c9a855c2f34 100644
--- a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java
+++ b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java
@@ -1,16 +1,10 @@
// 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.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 java.util.*;
import static com.yahoo.text.Lowercase.toLowerCase;
@@ -63,6 +57,7 @@ public class IndexFacts {
public IndexFacts() {}
+ @SuppressWarnings({"deprecation"})
public IndexFacts(IndexModel indexModel) {
if (indexModel.getSearchDefinitions() != null) {
this.searchDefinitions = indexModel.getSearchDefinitions();
@@ -90,16 +85,20 @@ public class IndexFacts {
}
private static void addEntry(Map<String, List<String>> result, String key, String value) {
- List<String> values = result.computeIfAbsent(key, k -> new ArrayList<>());
+ List<String> values = result.get(key);
+ if (values == null) {
+ values = new ArrayList<>();
+ result.put(key, values);
+ }
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 List.of();
+ if (clusterByDocument == null) return Collections.emptyList();
List<String> clusters = clusterByDocument.get(searchDefinitionName);
- return clusters != null ? clusters : List.of();
+ return clusters != null ? clusters : Collections.<String>emptyList();
}
private boolean isInitialized() {
@@ -169,9 +168,9 @@ public class IndexFacts {
}
private Collection<Index> getIndexes(String documentType) {
- if ( ! isInitialized()) return List.of();
+ if ( ! isInitialized()) return Collections.emptyList();
SearchDefinition sd = searchDefinitions.get(documentType);
- if (sd == null) return List.of();
+ if (sd == null) return Collections.emptyList();
return sd.indices().values();
}
@@ -232,7 +231,7 @@ public class IndexFacts {
}
private Collection<String> emptyCollectionIfNull(Collection<String> collection) {
- return collection == null ? List.of() : collection;
+ return collection == null ? Collections.<String>emptyList() : collection;
}
/**
@@ -319,7 +318,7 @@ public class IndexFacts {
private final List<String> documentTypes;
private Session(Query query) {
- documentTypes = List.copyOf(resolveDocumentTypes(query));
+ documentTypes = ImmutableList.copyOf(resolveDocumentTypes(query));
}
private Session(Collection<String> sources, Collection<String> restrict) {
@@ -348,7 +347,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, List.of(documentType));
+ return IndexFacts.this.getIndexFromDocumentTypes(indexName, Collections.singletonList(documentType));
}
/** Returns all the indexes of a given search definition */
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java b/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java
index ea78b2365c5..59dad29ab5c 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java
@@ -9,6 +9,7 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
+import com.google.common.collect.ImmutableList;
import com.yahoo.compress.IntegerCompressor;
/**
@@ -29,7 +30,7 @@ public class WordAlternativesItem extends TermItem {
this.alternatives = uniqueAlternatives(terms);
}
- private static List<Alternative> uniqueAlternatives(Collection<Alternative> terms) {
+ private static ImmutableList<Alternative> uniqueAlternatives(Collection<Alternative> terms) {
List<Alternative> uniqueTerms = new ArrayList<>(terms.size());
for (Alternative term : terms) {
int i = Collections.binarySearch(uniqueTerms, term, (t0, t1) -> t0.word.compareTo(t1.word));
@@ -42,7 +43,7 @@ public class WordAlternativesItem extends TermItem {
uniqueTerms.add(~i, term);
}
}
- return List.copyOf(uniqueTerms);
+ return ImmutableList.copyOf(uniqueTerms);
}
@Override
@@ -176,7 +177,8 @@ public class WordAlternativesItem extends TermItem {
@Override
public boolean equals(Object o) {
- if ( ! (o instanceof Alternative other)) return false;
+ if ( ! (o instanceof Alternative)) return false;
+ var other = (Alternative)o;
if ( ! Objects.equals(this.word, other.word)) return false;
if (this.exactness != other.exactness) return false;
return true;