diff options
author | isXander <xander@isxander.dev> | 2024-10-19 19:22:45 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2024-10-19 19:22:45 +0100 |
commit | e73a08e6672fb380cab8db71340158969c5ef56b (patch) | |
tree | dd08a311f4eff9a91b465ef1854caa1286fc6f9a /src/main/java/dev/isxander/yacl3/impl/NotNullBinding.java | |
parent | 519ac2fc0e23587defcf4a8259979961d35d0ce2 (diff) | |
download | YetAnotherConfigLib-e73a08e6672fb380cab8db71340158969c5ef56b.tar.gz YetAnotherConfigLib-e73a08e6672fb380cab8db71340158969c5ef56b.tar.bz2 YetAnotherConfigLib-e73a08e6672fb380cab8db71340158969c5ef56b.zip |
3.6.0
Diffstat (limited to 'src/main/java/dev/isxander/yacl3/impl/NotNullBinding.java')
-rw-r--r-- | src/main/java/dev/isxander/yacl3/impl/NotNullBinding.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl3/impl/NotNullBinding.java b/src/main/java/dev/isxander/yacl3/impl/NotNullBinding.java new file mode 100644 index 0000000..d367b06 --- /dev/null +++ b/src/main/java/dev/isxander/yacl3/impl/NotNullBinding.java @@ -0,0 +1,31 @@ +package dev.isxander.yacl3.impl; + +import dev.isxander.yacl3.api.Binding; +import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +public class NotNullBinding<T> implements Binding<T> { + private final Binding<T> binding; + + public NotNullBinding(Binding<T> binding) { + this.binding = binding; + } + + @Override + public @NotNull T getValue() { + return Validate.notNull(binding.getValue(), "Binding's value must not be null, please use Optionals if you want null behaviour."); + } + + @Override + public void setValue(@NotNull T value) { + Validate.notNull(value, "Binding's value must not be set to null, please use Optionals if you want null behaviour."); + binding.setValue(value); + } + + @Override + public @NotNull T defaultValue() { + return Validate.notNull(binding.defaultValue(), "Binding's default value must not be null, please use Optionals if you want null behaviour."); + } +} |