aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl3/config/v3/AbstractConfigEntry.java
diff options
context:
space:
mode:
authorisXander <xander@isxander.dev>2024-06-11 23:13:49 +0100
committerisXander <xander@isxander.dev>2024-06-11 23:13:57 +0100
commit305718e163f91802a4bc1c1ed6540febb2ce204e (patch)
treed72fe8b95dab1ef89f67b13a19f8c06fdb582c28 /src/main/java/dev/isxander/yacl3/config/v3/AbstractConfigEntry.java
parent65b4f7ba8374bbaebc6a431f8347ffc3e8afdced (diff)
downloadYetAnotherConfigLib-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/AbstractConfigEntry.java')
-rw-r--r--src/main/java/dev/isxander/yacl3/config/v3/AbstractConfigEntry.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl3/config/v3/AbstractConfigEntry.java b/src/main/java/dev/isxander/yacl3/config/v3/AbstractConfigEntry.java
new file mode 100644
index 0000000..8092f23
--- /dev/null
+++ b/src/main/java/dev/isxander/yacl3/config/v3/AbstractConfigEntry.java
@@ -0,0 +1,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;
+ }
+}