diff options
author | isXander <xander@isxander.dev> | 2024-06-11 23:13:49 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2024-06-11 23:13:57 +0100 |
commit | 305718e163f91802a4bc1c1ed6540febb2ce204e (patch) | |
tree | d72fe8b95dab1ef89f67b13a19f8c06fdb582c28 /src/main/java/dev/isxander/yacl3/config/v3/ConfigEntry.java | |
parent | 65b4f7ba8374bbaebc6a431f8347ffc3e8afdced (diff) | |
download | YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.tar.gz YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.tar.bz2 YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.zip |
codec config and rewritten kotlin dsl
Diffstat (limited to 'src/main/java/dev/isxander/yacl3/config/v3/ConfigEntry.java')
-rw-r--r-- | src/main/java/dev/isxander/yacl3/config/v3/ConfigEntry.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl3/config/v3/ConfigEntry.java b/src/main/java/dev/isxander/yacl3/config/v3/ConfigEntry.java new file mode 100644 index 0000000..c22d796 --- /dev/null +++ b/src/main/java/dev/isxander/yacl3/config/v3/ConfigEntry.java @@ -0,0 +1,38 @@ +package dev.isxander.yacl3.config.v3; + +import dev.isxander.yacl3.api.Binding; +import org.jetbrains.annotations.ApiStatus; + +import java.util.function.Consumer; +import java.util.function.UnaryOperator; + +@ApiStatus.Experimental +public interface ConfigEntry<T> extends ReadonlyConfigEntry<T> { + + void set(T value); + + T defaultValue(); + + @Override + ConfigEntry<T> modifyGet(UnaryOperator<T> modifier); + + @Override + default ConfigEntry<T> onGet(Consumer<T> consumer) { + return this.modifyGet(v -> { + consumer.accept(v); + return v; + }); + } + + ConfigEntry<T> modifySet(UnaryOperator<T> modifier); + default ConfigEntry<T> onSet(Consumer<T> consumer) { + return this.modifySet(v -> { + consumer.accept(v); + return v; + }); + } + + default Binding<T> asBinding() { + return Binding.generic(this.defaultValue(), this::get, this::set); + } +} |