summaryrefslogtreecommitdiff
path: root/dicore3/command/src/main/java/io/dico/dicore/command/ExtendedCommand.java
blob: 602760ccd76cfd5673e29251f377491bbb870488 (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
50
51
52
package io.dico.dicore.command;

import io.dico.dicore.command.parameter.IArgumentPreProcessor;
import io.dico.dicore.command.parameter.Parameter;

@SuppressWarnings("unchecked")
public abstract class ExtendedCommand<T extends ExtendedCommand<T>> extends Command {
    protected final boolean modifiable;

    public ExtendedCommand() {
        this(true);
    }

    public ExtendedCommand(boolean modifiable) {
        this.modifiable = modifiable;
    }

    protected T newModifiableInstance() {
        return (T) this;
    }

    @Override
    public T addParameter(Parameter<?, ?> parameter) {
        return modifiable ? (T) super.addParameter(parameter) : newModifiableInstance().addParameter(parameter);
    }

    @Override
    public T requiredParameters(int requiredParameters) {
        return modifiable ? (T) super.requiredParameters(requiredParameters) : newModifiableInstance().requiredParameters(requiredParameters);
    }

    @Override
    public T repeatFinalParameter() {
        return modifiable ? (T) super.repeatFinalParameter() : newModifiableInstance().repeatFinalParameter();
    }

    @Override
    public T setDescription(String... description) {
        return modifiable ? (T) super.setDescription(description) : newModifiableInstance().setDescription(description);
    }

    @Override
    public T setShortDescription(String shortDescription) {
        return modifiable ? (T) super.setShortDescription(shortDescription) : newModifiableInstance().setShortDescription(shortDescription);
    }

    @Override
    public T preprocessArguments(IArgumentPreProcessor processor) {
        return modifiable ? (T) super.preprocessArguments(processor) : newModifiableInstance().preprocessArguments(processor);
    }

}