aboutsummaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorisXander <xander@isxander.dev>2023-08-18 11:43:52 +0100
committerisXander <xander@isxander.dev>2023-08-18 11:43:52 +0100
commitd7a9d31706a30c8b66dcd0587f6c82cf7c6118c9 (patch)
tree3464ddc568505ecd3095523bb7c8d2e70de00127 /common/src
parent39bc5b5d8b8e6d4369ea71a7787907521e11ad34 (diff)
downloadYetAnotherConfigLib-d7a9d31706a30c8b66dcd0587f6c82cf7c6118c9.tar.gz
YetAnotherConfigLib-d7a9d31706a30c8b66dcd0587f6c82cf7c6118c9.tar.bz2
YetAnotherConfigLib-d7a9d31706a30c8b66dcd0587f6c82cf7c6118c9.zip
Enforce NotNull on bindings
Diffstat (limited to 'common/src')
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/Option.java2
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java2
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/HiddenNameListOptionEntry.java2
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/LabelOptionImpl.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/ListOptionEntryImpl.java2
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java4
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java6
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/SafeBinding.java29
8 files changed, 42 insertions, 9 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/api/Option.java b/common/src/main/java/dev/isxander/yacl3/api/Option.java
index 31b7756..38bd8ca 100644
--- a/common/src/main/java/dev/isxander/yacl3/api/Option.java
+++ b/common/src/main/java/dev/isxander/yacl3/api/Option.java
@@ -72,7 +72,7 @@ public interface Option<T> {
/**
* Sets the pending value
*/
- void requestSet(T value);
+ void requestSet(@NotNull T value);
/**
* Applies the pending value to the bound value.
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java
index 7451f7c..170b8e0 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java
@@ -93,7 +93,7 @@ public final class ButtonOptionImpl implements ButtonOption {
}
@Override
- public void requestSet(BiConsumer<YACLScreen, ButtonOption> value) {
+ public void requestSet(@NotNull BiConsumer<YACLScreen, ButtonOption> value) {
throw new UnsupportedOperationException();
}
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/HiddenNameListOptionEntry.java b/common/src/main/java/dev/isxander/yacl3/impl/HiddenNameListOptionEntry.java
index 6ff2669..64588f2 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/HiddenNameListOptionEntry.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/HiddenNameListOptionEntry.java
@@ -71,7 +71,7 @@ public class HiddenNameListOptionEntry<T> implements ListOptionEntry<T> {
}
@Override
- public void requestSet(T value) {
+ public void requestSet(@NotNull T value) {
option.requestSet(value);
}
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/LabelOptionImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/LabelOptionImpl.java
index c8287bd..2bd2e10 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/LabelOptionImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/LabelOptionImpl.java
@@ -25,6 +25,8 @@ public final class LabelOptionImpl implements LabelOption {
private final Binding<Component> binding;
public LabelOptionImpl(Component label) {
+ Validate.notNull(label, "`label` must not be null");
+
this.label = label;
this.labelController = new LabelController(this);
this.binding = Binding.immutable(label);
@@ -89,7 +91,7 @@ public final class LabelOptionImpl implements LabelOption {
}
@Override
- public void requestSet(Component value) {
+ public void requestSet(@NotNull Component value) {
}
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/ListOptionEntryImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/ListOptionEntryImpl.java
index 72254cf..1cd5e55 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/ListOptionEntryImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/ListOptionEntryImpl.java
@@ -79,7 +79,7 @@ public final class ListOptionEntryImpl<T> implements ListOptionEntry<T> {
}
@Override
- public void requestSet(T value) {
+ public void requestSet(@NotNull T value) {
binding.setValue(value);
}
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java
index f45e368..c77d55f 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java
@@ -39,7 +39,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
public ListOptionImpl(@NotNull Component name, @NotNull OptionDescription description, @NotNull Binding<List<T>> binding, @NotNull Supplier<T> initialValue, @NotNull Function<ListOptionEntry<T>, Controller<T>> controllerFunction, ImmutableSet<OptionFlag> flags, boolean collapsed, boolean available, int minimumNumberOfEntries, int maximumNumberOfEntries, boolean insertEntriesAtEnd, Collection<BiConsumer<Option<List<T>>, List<T>>> listeners) {
this.name = name;
this.description = description;
- this.binding = binding;
+ this.binding = new SafeBinding<>(binding);
this.initialValue = initialValue;
this.entryFactory = new EntryFactory(controllerFunction);
this.entries = createEntries(binding().getValue());
@@ -131,7 +131,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
}
@Override
- public void requestSet(List<T> value) {
+ public void requestSet(@NotNull List<T> value) {
entries.clear();
entries.addAll(createEntries(value));
onRefresh();
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java
index 165f38d..37a626b 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java
@@ -41,7 +41,7 @@ public final class OptionImpl<T> implements Option<T> {
@NotNull Collection<BiConsumer<Option<T>, T>> listeners
) {
this.name = name;
- this.binding = binding;
+ this.binding = new SafeBinding<>(binding);
this.available = available;
this.flags = flags;
this.listeners = new ArrayList<>(listeners);
@@ -108,7 +108,9 @@ public final class OptionImpl<T> implements Option<T> {
}
@Override
- public void requestSet(T value) {
+ public void requestSet(@NotNull T value) {
+ Validate.notNull(value, "`value` cannot be null");
+
pendingValue = value;
this.triggerListeners(true);
}
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/SafeBinding.java b/common/src/main/java/dev/isxander/yacl3/impl/SafeBinding.java
new file mode 100644
index 0000000..c55d2be
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl3/impl/SafeBinding.java
@@ -0,0 +1,29 @@
+package dev.isxander.yacl3.impl;
+
+import dev.isxander.yacl3.api.Binding;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Objects;
+
+public class SafeBinding<T> implements Binding<T> {
+ private final Binding<T> binding;
+
+ public SafeBinding(Binding<T> binding) {
+ this.binding = binding;
+ }
+
+ @Override
+ public @NotNull T getValue() {
+ return Objects.requireNonNull(binding.getValue());
+ }
+
+ @Override
+ public void setValue(@NotNull T value) {
+ binding.setValue(Objects.requireNonNull(value));
+ }
+
+ @Override
+ public @NotNull T defaultValue() {
+ return Objects.requireNonNull(binding.defaultValue());
+ }
+}