diff options
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/query/profile/ChainedMap.java | 97 | ||||
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java | 8 |
2 files changed, 98 insertions, 7 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/ChainedMap.java b/container-search/src/main/java/com/yahoo/search/query/profile/ChainedMap.java new file mode 100644 index 00000000000..7da5441129c --- /dev/null +++ b/container-search/src/main/java/com/yahoo/search/query/profile/ChainedMap.java @@ -0,0 +1,97 @@ +// 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 java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * A read-only map which forwards lookups to a primary map, and then a secondary for + * keys not existing in the primary. + * + * @author bratseth + */ +class ChainedMap<K, V> implements Map<K, V> { + + private final Map<K, V> primary, secondary; + + ChainedMap(Map<K, V> primary, Map<K, V> secondary) { + this.primary = primary; + this.secondary = secondary; + } + + @Override + public int size() { + return keySet().size(); + } + + @Override + public boolean isEmpty() { + return primary.isEmpty() && secondary.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return primary.containsKey(key) || secondary.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return primary.containsValue(value) || secondary.containsValue(value); + } + + @Override + public V get(Object key) { + V value = primary.get(key); + return value != null ? value : secondary.get(key); + } + + @Override + public V put(K key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map<? extends K, ? extends V> m) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + @Override + public Set<K> keySet() { + var keys = new HashSet<>(secondary.keySet()); + keys.addAll(primary.keySet()); + return keys; + } + + @Override + public Collection<V> values() { + throw new UnsupportedOperationException(); + } + + @Override + public Set<Entry<K, V>> entrySet() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean equals(Object o) { + throw new UnsupportedOperationException(); + } + + @Override + public int hashCode() { + throw new UnsupportedOperationException(); + } + +} diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java index 7f5df94d020..da1eb5f7ecc 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java @@ -300,13 +300,7 @@ public class QueryProfileProperties extends Properties { if (zoneInfo == ZoneInfo.defaultInfo()) return context; if (context == null || context.isEmpty()) return zoneContext; if (context == zoneContext) return context; - if (context.containsKey(ENVIRONMENT) && context.containsKey(REGION) && context.containsKey(INSTANCE)) return context; - - Map<String, String> contextWithZoneInfo = new HashMap<>(context); - contextWithZoneInfo.putIfAbsent(ENVIRONMENT, zoneInfo.zone().environment().name()); - contextWithZoneInfo.putIfAbsent(REGION, zoneInfo.zone().region()); - contextWithZoneInfo.putIfAbsent(INSTANCE, zoneInfo.application().instance()); - return Collections.unmodifiableMap(contextWithZoneInfo); + return new ChainedMap(zoneContext, context); } private boolean reachableTypesAreComplete(CompoundName prefix, CompiledQueryProfile profile, StringBuilder firstMissingName, Map<String,String> context) { |