aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev/isxander/yacl/impl/GenericBindingImpl.java
blob: 0d668c642468d2b1d1a8eafcd54367d619a65da7 (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
package dev.isxander.yacl.impl;

import dev.isxander.yacl.api.Binding;

import java.util.function.Consumer;
import java.util.function.Supplier;

public final class GenericBindingImpl<T> implements Binding<T> {
    private final T def;
    private final Supplier<T> getter;
    private final Consumer<T> setter;

    public GenericBindingImpl(T def, Supplier<T> getter, Consumer<T> setting) {
        this.def = def;
        this.getter = getter;
        this.setter = setting;
    }


    @Override
    public void setValue(T value) {
        setter.accept(value);
    }

    @Override
    public T getValue() {
        return getter.get();
    }

    @Override
    public T defaultValue() {
        return def;
    }

}