1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.profile;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.search.query.profile.compiled.ValueWithSource;
import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileFieldType;
import com.yahoo.search.query.profile.types.QueryProfileType;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* @author bratseth
*/
final class AllValuesQueryProfileVisitor extends PrefixQueryProfileVisitor {
private Map<String, ValueWithSource> values = new HashMap<>();
/* Lists all values starting at prefix */
public AllValuesQueryProfileVisitor(CompoundName prefix) {
super(prefix);
}
@Override
public void onValue(String localName,
Object value,
DimensionBinding binding,
QueryProfile owner,
DimensionValues variant) {
putValue(localName, value, null, owner, variant, binding);
}
@Override
public void onQueryProfileInsidePrefix(QueryProfile profile,
DimensionBinding binding,
QueryProfile owner,
DimensionValues variant) {
putValue("", profile.getValue(), profile, owner, variant, binding);
}
private void putValue(String key,
Object value,
QueryProfile profile,
QueryProfile owner,
DimensionValues variant,
DimensionBinding binding) {
CompoundName fullName = currentPrefix.append(key);
if (values.containsKey(fullName.toString())) return; // The first value encountered has priority
Boolean isOverridable = owner != null ? owner.isLocalOverridable(key, binding) : null;
values.put(fullName.toString(), new ValueWithSource(value,
owner == null ? "anonymous" : owner.getSource(),
isOverridable != null && ! isOverridable,
profile != null,
profile == null ? null : profile.getType(),
variant));
}
/** Returns the values resulting from this visiting */
public Map<String, Object> values() {
Map<String, Object> values = new HashMap<>();
for (var entry : this.values.entrySet())
values.put(entry.getKey(), entry.getValue().value());
return values;
}
/** Returns the values with source resulting from this visiting */
public Map<String, ValueWithSource> valuesWithSource() { return Collections.unmodifiableMap(values); }
/** Returns false - we are not done until we have seen all */
public boolean isDone() { return false; }
}
|