aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java
blob: 4fc9dfa03cda00e7f9f691ab025695822dfa2130 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.properties;

import com.yahoo.processing.request.CompoundName;
import com.yahoo.processing.request.Properties;

import java.util.Map;

/**
 * A wrapper around a chain of property objects that prefixes all gets/sets with a given path
 *
 * @author Arne Bergene Fossaa
 * @deprecated Unused and will go away on vespa 9
 */
@Deprecated (forRemoval = true)
public class SubProperties extends com.yahoo.search.query.Properties {

    final private CompoundName pathPrefix;
    final private Properties parent;

    public SubProperties(String pathPrefix, Properties properties) {
        this(CompoundName.from(pathPrefix), properties);
    }

    public SubProperties(CompoundName pathPrefix, Properties properties) {
        this.pathPrefix = pathPrefix;
        this.parent = properties;
    }

    @Override
    public Object get(CompoundName key, Map<String,String> context,
                      com.yahoo.processing.request.Properties substitution) {
        if(key == null) return null;
        Object result = parent.get(getPathPrefix() + "." + key,context,substitution);
        if(result == null) {
            return super.get(key,context,substitution);
        } else {
            return result;
        }
    }

    @Override
    public void set(CompoundName key, Object obj, Map<String,String> context) {
        if(key == null) return;
        parent.set(getPathPrefix() + "." + key, obj, context);
    }

    @Override
    public Map<String, Object> listProperties(CompoundName path,Map<String,String> context,
                                              com.yahoo.processing.request.Properties substitution) {
        Map<String, Object> map = super.listProperties(path,context,substitution);
        if(path.isEmpty()) {
            map.putAll(parent.listProperties(getPathPrefix(),context,substitution));
        } else {
            map.putAll(parent.listProperties(getPathPrefix() + "." + path,context,substitution));
        }
        return map;
    }

    public CompoundName getPathPrefixCompound() {
        return pathPrefix;
    }

    /** Returns getPatchPrefixCompound.toString() */
    public String getPathPrefix() {
        return getPathPrefixCompound().toString();
    }

}