aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/profile/AllUnoverridableQueryProfileVisitor.java
blob: 6db6ebb994b28c9cb3b998d28f7a6e9fd02801fc (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
// 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 java.util.HashSet;
import java.util.Set;

/**
 * @author bratseth
 */
final class AllUnoverridableQueryProfileVisitor extends PrefixQueryProfileVisitor {

    /** A map of query profile types */
    private Set<CompoundName> unoverridables = new HashSet<>();

    public AllUnoverridableQueryProfileVisitor(CompoundName prefix) {
        super(prefix);
    }

    @Override
    public void onValue(String name, Object value, DimensionBinding binding, QueryProfile owner) {
        addUnoverridable(name, currentPrefix.append(name), binding, owner);
    }

    @Override
    public void onQueryProfileInsidePrefix(QueryProfile profile, DimensionBinding binding, QueryProfile owner) {
        addUnoverridable(currentPrefix.last(), currentPrefix, binding, owner);
    }

    private void addUnoverridable(String localName, CompoundName fullName, DimensionBinding binding, QueryProfile owner) {
        if (owner == null) return;

        Boolean isOverridable = owner.isLocalOverridable(localName, binding);
        if (isOverridable != null &&  ! isOverridable)
            unoverridables.add(fullName);
    }

    /** Returns the values resulting from this visiting */
    public Set<CompoundName> getResult() { return unoverridables; }

    /** Returns false - we are not done until we have seen all */
    public boolean isDone() { return false; }

}