aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl3/api/OptionAddable.java
blob: 606e8ca8659b40a710c07fc6976f04cf88e2a031 (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
package dev.isxander.yacl3.api;

import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.function.Supplier;

public interface OptionAddable {
    /**
     * Adds an option to an abstract builder.
     * To construct an option, use {@link Option#createBuilder()}
     */
    OptionAddable option(@NotNull Option<?> option);

    /**
     * Adds an option to an abstract builder.
     * To construct an option, use {@link Option#createBuilder()}
     * @param optionSupplier to be called to initialise the option. called immediately
     */
    default OptionAddable option(@NotNull Supplier<@NotNull Option<?>> optionSupplier) {
        return option(optionSupplier.get());
    }

    /**
     * Adds an option to an abstract builder if a condition is met.
     * To construct an option, use {@link Option#createBuilder()}
     * @param condition only if true is the option added
     * @param option the option to add
     * @return this
     */
    default OptionAddable optionIf(boolean condition, @NotNull Option<?> option) {
        return condition ? option(option) : this;
    }

    /**
     * Adds an option to an abstract builder if a condition is met.
     * To construct an option, use {@link Option#createBuilder()}
     * @param condition only if true is the option added
     * @param optionSupplier to be called to initialise the option. called immediately only if condition is true
     * @return this
     */
    default OptionAddable optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>> optionSupplier) {
        return condition ? option(optionSupplier) : this;
    }

    /**
     * Adds multiple options to an abstract builder.
     * To construct an option, use {@link Option#createBuilder()}
     */
    OptionAddable options(@NotNull Collection<? extends Option<?>> options);
}