blob: 8092f2309c540bae48db683534471c1234e5bfa5 (
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
|
package dev.isxander.yacl3.config.v3;
import org.jetbrains.annotations.ApiStatus;
import java.util.function.Function;
import java.util.function.UnaryOperator;
@ApiStatus.Experimental
public abstract class AbstractConfigEntry<T> extends AbstractReadonlyConfigEntry<T> implements ConfigEntry<T> {
private T value;
private final T defaultValue;
private Function<T, T> setModifier;
public AbstractConfigEntry(String fieldName, T defaultValue) {
super(fieldName);
this.value = defaultValue;
this.defaultValue = defaultValue;
this.setModifier = UnaryOperator.identity();
}
@Override
protected T innerGet() {
return this.value;
}
@Override
public void set(T value) {
this.value = this.setModifier.apply(value);
}
@Override
public T defaultValue() {
return this.defaultValue;
}
@Override
public ConfigEntry<T> modifyGet(UnaryOperator<T> modifier) {
super.modifyGet(modifier);
return this;
}
@Override
public ConfigEntry<T> modifySet(UnaryOperator<T> modifier) {
this.setModifier = this.setModifier.andThen(modifier);
return this;
}
}
|