aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/yaml/snakeyaml/tokens/DirectiveToken.java
blob: f016ed9512eae1444074e1ef7d5a288b5f46bb82 (plain)
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
/*
 * See LICENSE file in distribution for copyright and licensing information.
 */
package org.yaml.snakeyaml.tokens;

import java.util.List;

import org.yaml.snakeyaml.error.Mark;
import org.yaml.snakeyaml.error.YAMLException;

/**
 * @see <a href="http://pyyaml.org/wiki/PyYAML">PyYAML</a> for more information
 */
public final class DirectiveToken extends Token {
    private final String name;
    private final List<?> value;

    public DirectiveToken(String name, List<?> value, Mark startMark, Mark endMark) {
        super(startMark, endMark);
        this.name = name;
        if (value != null && value.size() != 2) {
            throw new YAMLException("Two strings must be provided instead of "
                    + String.valueOf(value.size()));
        }
        this.value = value;
    }

    public String getName() {
        return this.name;
    }

    public List<?> getValue() {
        return this.value;
    }

    @Override
    protected String getArguments() {
        if (value != null) {
            return "name=" + name + ", value=[" + value.get(0) + ", " + value.get(1) + "]";
        } else {
            return "name=" + name;
        }
    }

    @Override
    public String getTokenId() {
        return "<directive>";
    }
}