summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/schema/fieldoperation/DictionaryOperation.java
blob: a9a2ce7cbb18d676fd2bd5bf2d624c780bbbe62a (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

package com.yahoo.schema.fieldoperation;

import com.yahoo.schema.document.Case;
import com.yahoo.schema.document.Dictionary;
import com.yahoo.schema.document.SDField;

/**
 * Represents operations controlling setup of dictionary used for queries
 *
 * @author baldersheim
 */
public class DictionaryOperation implements FieldOperation {
    public enum Operation { HASH, BTREE, CASED, UNCASED }
    private final Operation operation;

    public DictionaryOperation(Operation type) {
        this.operation = type;
    }
    @Override
    public void apply(SDField field) {
        Dictionary dictionary = field.getOrSetDictionary();
        switch (operation) {
            case HASH:
                dictionary.updateType(Dictionary.Type.HASH);
                break;
            case BTREE:
                dictionary.updateType(Dictionary.Type.BTREE);
                break;
            case CASED:
                dictionary.updateMatch(Case.CASED);
                break;
            case UNCASED:
                dictionary.updateMatch(Case.UNCASED);
                break;
            default:
                throw new IllegalArgumentException("Unhandled operation " + operation);
        }
    }
}