diff options
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query')
5 files changed, 33 insertions, 29 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java index b58bd64209b..e3ab49f0e32 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile; +import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; import com.yahoo.component.provider.FreezableSimpleComponent; import com.yahoo.processing.IllegalInputException; @@ -419,7 +420,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable content.freeze(); - inherited= inherited==null ? List.of() : List.copyOf(inherited); + inherited= inherited==null ? ImmutableList.of() : ImmutableList.copyOf(inherited); super.freeze(); } @@ -615,7 +616,8 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable * be added (usually because the new value was added to the existing). */ static Object combineValues(Object newValue, Object existingValue) { - if (newValue instanceof QueryProfile newProfile) { + if (newValue instanceof QueryProfile) { + QueryProfile newProfile = (QueryProfile)newValue; if ( ! (existingValue instanceof QueryProfile)) { if ( ! isModifiable(newProfile)) { // Make the query profile reference overridable @@ -629,7 +631,8 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable return combineProfiles(newProfile, (QueryProfile)existingValue); } else { - if (existingValue instanceof QueryProfile existingProfile) { // we need to set a non-leaf value on a query profile + if (existingValue instanceof QueryProfile) { // we need to set a non-leaf value on a query profile + QueryProfile existingProfile = (QueryProfile)existingValue; if (isModifiable(existingProfile)) { existingProfile.setValue(newValue); return null; diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java index 57aa3516dfc..7fc8bfd40ab 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariant.java @@ -1,13 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.yahoo.search.query.profile.types.QueryProfileType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import java.util.*; /** * A variant of a query profile @@ -42,7 +40,7 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa public Map<String, Object> values() { if (values == null) { if (frozen) - return Map.of(); + return Collections.emptyMap(); else values = new HashMap<>(); } @@ -56,7 +54,7 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa public List<QueryProfile> inherited() { if (inherited == null) { if (frozen) - return List.of(); + return Collections.emptyList(); else inherited = new ArrayList<>(); } @@ -142,9 +140,9 @@ public class QueryProfileVariant implements Cloneable, Comparable<QueryProfileVa public void freeze() { if (frozen) return; if (inherited != null) - inherited = List.copyOf(inherited); + inherited = ImmutableList.copyOf(inherited); if (values != null) - values = Map.copyOf(values); + values = ImmutableMap.copyOf(values); frozen=true; } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java index 1b0472c5b17..845c2cfd384 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileVariants.java @@ -1,15 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.yahoo.component.provider.Freezable; import com.yahoo.search.query.profile.types.QueryProfileType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * This class represent a set of query profiles virtually - rather @@ -57,7 +54,7 @@ public class QueryProfileVariants implements Freezable, Cloneable { * on lookup time to influence the value returned. */ public QueryProfileVariants(String[] dimensions, QueryProfile owner) { - this(List.of(dimensions), owner); + this(Arrays.asList(dimensions), owner); } /** @@ -80,13 +77,13 @@ public class QueryProfileVariants implements Freezable, Cloneable { if (frozen) return; for (FieldValues fieldValues : fieldValuesByName.values()) fieldValues.freeze(); - fieldValuesByName = Map.copyOf(fieldValuesByName); + fieldValuesByName = ImmutableMap.copyOf(fieldValuesByName); inheritedProfiles.freeze(); Collections.sort(variants); for (QueryProfileVariant variant : variants) variant.freeze(); - variants = List.copyOf(variants); + variants = ImmutableList.copyOf(variants); frozen=true; } @@ -334,7 +331,7 @@ public class QueryProfileVariants implements Freezable, Cloneable { if (frozen) return; sort(); if (resolutionList != null) - resolutionList = List.copyOf(resolutionList); + resolutionList = ImmutableList.copyOf(resolutionList); frozen = true; } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java index 8fdbf8b2281..f30a3cc5ae6 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java @@ -1,9 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile.types; +import com.google.common.collect.ImmutableList; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.query.profile.QueryProfile; +import java.util.Arrays; import java.util.List; /** @@ -94,14 +96,14 @@ public class FieldDescription implements Comparable<FieldDescription> { if (name.isCompound() && ! aliases.isEmpty()) throw new IllegalArgumentException("Aliases are not allowed with compound names"); - this.aliases = List.copyOf(aliases); + this.aliases = ImmutableList.copyOf(aliases); this.mandatory = mandatory; this.overridable = overridable; } private static List<String> toList(String string) { - if (string == null || string.isEmpty()) return List.of(); - return List.of(string.split(" ")); + if (string == null || string.isEmpty()) return ImmutableList.of(); + return ImmutableList.copyOf(Arrays.asList(string.split(" "))); } /** Returns the full name of this as a string */ diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java index 3da2ad53f9a..02a4199d32e 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java @@ -1,9 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile.types; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.yahoo.component.ComponentId; import com.yahoo.component.provider.FreezableSimpleComponent; import com.yahoo.processing.request.CompoundName; +import com.yahoo.search.query.profile.OverridableQueryProfile; import com.yahoo.search.query.profile.QueryProfile; import java.util.ArrayList; @@ -80,7 +83,8 @@ public class QueryProfileType extends FreezableSimpleComponent { Map<String, FieldDescription> unfrozenFields = new LinkedHashMap<>(); for (Map.Entry<String, FieldDescription> field : fields.entrySet()) { FieldDescription unfrozenFieldValue = field.getValue(); - if (field.getValue().getType() instanceof QueryProfileFieldType queryProfileFieldType) { + if (field.getValue().getType() instanceof QueryProfileFieldType) { + QueryProfileFieldType queryProfileFieldType = (QueryProfileFieldType)field.getValue().getType(); if (queryProfileFieldType.getQueryProfileType() != null) { QueryProfileFieldType unfrozenType = new QueryProfileFieldType(queryProfileFieldType.getQueryProfileType().unfrozen()); @@ -181,8 +185,8 @@ public class QueryProfileType extends FreezableSimpleComponent { fields.put(field.getName(), field); } } - fields = Collections.unmodifiableMap(fields); - inherited = List.copyOf(inherited); + fields = ImmutableMap.copyOf(fields); + inherited = ImmutableList.copyOf(inherited); strict = isStrict(); matchAsPath = getMatchAsPath(); super.freeze(); @@ -378,7 +382,7 @@ public class QueryProfileType extends FreezableSimpleComponent { */ public Map<String, String> aliases() { if (isFrozen()) return aliases; - if (aliases == null) return Map.of(); + if (aliases == null) return Collections.emptyMap(); return Collections.unmodifiableMap(aliases); } |