blob: fb9638a958b9338fd6ec3627032a3821f1d05751 (
plain) (
blame)
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
|
// Copyright 2016 Yahoo Inc. 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.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileFieldType;
import com.yahoo.search.query.profile.types.QueryProfileType;
import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="mailto:bratseth@yahoo-inc.com">Jon Bratseth</a>
*/
final class AllTypesQueryProfileVisitor extends PrefixQueryProfileVisitor {
/** A map of query profile types */
private Map<CompoundName, QueryProfileType> types = new HashMap<>();
public AllTypesQueryProfileVisitor(CompoundName prefix) {
super(prefix);
}
@Override
public void onValue(String name, Object value, DimensionBinding binding, QueryProfile owner) {}
@Override
public void onQueryProfileInsidePrefix(QueryProfile profile, DimensionBinding binding, QueryProfile owner) {
if (profile.getType() != null)
addReachableTypes(currentPrefix, profile.getType());
}
private void addReachableTypes(CompoundName name, QueryProfileType type) {
types.put(name, type);
for (FieldDescription fieldDescription : type.fields().values()) {
if ( ! (fieldDescription.getType() instanceof QueryProfileFieldType)) continue;
QueryProfileFieldType fieldType = (QueryProfileFieldType)fieldDescription.getType();
if (fieldType.getQueryProfileType() !=null) {
addReachableTypes(name.append(fieldDescription.getName()), fieldType.getQueryProfileType());
}
}
}
/** Returns the values resulting from this visiting */
public Map<CompoundName, QueryProfileType> getResult() { return types; }
/** Returns false - we are not done until we have seen all */
public boolean isDone() { return false; }
}
|