aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/VariableSection.java
blob: e5745483b31aff072346adcd2ec1f43979bc7ab1 (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.vespa.hosted.node.admin.task.util.template;

import com.yahoo.vespa.hosted.node.admin.task.util.text.Cursor;
import com.yahoo.vespa.hosted.node.admin.task.util.text.CursorRange;

import java.util.Objects;

/**
 * Represents a template variable section
 *
 * @see Template
 * @author hakonhall
 */
class VariableSection extends Section {
    private final String name;
    private final Cursor nameOffset;

    private String value = null;

    VariableSection(CursorRange range, String name, Cursor nameOffset) {
        super(range);
        this.name = name;
        this.nameOffset = nameOffset;
    }

    String name() { return name; }

    void set(String value) {
        this.value = Objects.requireNonNull(value);
    }

    @Override
    void appendTo(StringBuilder buffer) {
        if (value == null) {
            throw new TemplateNameNotSetException(this, name, nameOffset);
        }

        buffer.append(value);
    }
}