aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/profile/FieldDescriptionQueryProfileVisitor.java
blob: 99a6704e02cdb66fd5f9e7bf12d9ffef00f69c32 (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
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
77
// Copyright Vespa.ai. 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.search.query.profile.types.FieldDescription;

import java.util.List;

/**
 * @author bratseth
 */
final class FieldDescriptionQueryProfileVisitor extends QueryProfileVisitor {

    /** The result, or null if none */
    private FieldDescription result = null;

    private final List<String> name;

    private int nameIndex=-1;

    private boolean enteringContent=false;

    public FieldDescriptionQueryProfileVisitor(List<String> name) {
        this.name=name;
    }

    @Override
    public String getLocalKey() {
        return name.get(nameIndex);
    }

    @Override
    public boolean enter(String name) {
        if (nameIndex+2<this.name.size()) {
            nameIndex++;
            enteringContent=true;
        }
        else {
            enteringContent=false;
        }
        return enteringContent;
    }

    @Override
    public void leave(String name) {
        nameIndex--;
    }

    @Override
    public void onValue(String name,
                        Object value,
                        DimensionBinding binding,
                        QueryProfile owner,
                        DimensionValues variant) {
    }

    @Override
    public void onQueryProfile(QueryProfile profile,
                               DimensionBinding binding,
                               QueryProfile owner,
                               DimensionValues variant) {
        if (enteringContent) return; // not at leaf query profile
        if (profile.getType() == null) return;
        result = profile.getType().getField(name.get(name.size() - 1));
    }

    @Override
    public boolean isDone() {
        return result != null;
    }

    public FieldDescription result() { return result; }

    @Override
    public String toString() {
        return "a query profile type visitor (hash " + hashCode() + ") with current value " + result;
    }
}