aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/schema/parser/ParsedAttribute.java
blob: 56eff4cd1713777ee8c7e503025981ef02ceda69 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.parser;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * This class holds the extracted information after parsing a
 * "attribute" block, using simple data structures as far as
 * possible.  Do not put advanced logic here!
 * @author arnej27959
 **/
class ParsedAttribute extends ParsedBlock {

    private boolean enableOnlyBitVector = false;
    private boolean enableFastAccess = false;
    private boolean enableFastRank = false;
    private boolean enableFastSearch = false;
    private boolean enableMutable = false;
    private boolean enablePaged = false;
    private final Map<String, String> aliases = new LinkedHashMap<>();
    private ParsedSorting sortSettings = null;
    private String distanceMetric = null;

    ParsedAttribute(String name) {
        super(name, "attribute");
    }

    List<String> getAliases() { return List.copyOf(aliases.keySet()); }
    String lookupAliasedFrom(String alias) { return aliases.get(alias); }
    Optional<String> getDistanceMetric() { return Optional.ofNullable(distanceMetric); }
    boolean getEnableOnlyBitVector() { return this.enableOnlyBitVector; }
    boolean getFastAccess() { return this.enableFastAccess; }
    boolean getFastRank() { return this.enableFastRank; }
    boolean getFastSearch() { return this.enableFastSearch; }
    boolean getMutable() { return this.enableMutable; }
    boolean getPaged() { return this.enablePaged; }
    Optional<ParsedSorting> getSorting() { return Optional.ofNullable(sortSettings); }

    void addAlias(String from, String to) {
        verifyThat(! aliases.containsKey(to), "already has alias", to);
        aliases.put(to, from);
    }

    void setDistanceMetric(String value) {
        verifyThat(distanceMetric == null, "already has distance-metric", distanceMetric);
        this.distanceMetric = value;
    }

    ParsedSorting sortInfo() {
        if (sortSettings == null) sortSettings = new ParsedSorting(name(), "attribute.sorting");
        return this.sortSettings;
    }

    void setEnableOnlyBitVector(boolean value) { this.enableOnlyBitVector = value; }
    void setFastAccess(boolean value) { this.enableFastAccess = true; }
    void setFastRank(boolean value) { this.enableFastRank = true; }
    void setFastSearch(boolean value) { this.enableFastSearch = true; }
    void setMutable(boolean value) { this.enableMutable = true; }
    void setPaged(boolean value) { this.enablePaged = true; }
}