aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-08-12 14:41:48 +0100
committerisXander <xandersmith2008@gmail.com>2023-08-12 14:41:48 +0100
commitaf472c8304c9e1864b5c2a1ab8472533fe8f5950 (patch)
treefd8d69f3e3780c6042a8145aa749d17fc34b947e
parentb45c9417a422827b351c8a797fd158f885b3ce05 (diff)
downloadYetAnotherConfigLib-af472c8304c9e1864b5c2a1ab8472533fe8f5950.tar.gz
YetAnotherConfigLib-af472c8304c9e1864b5c2a1ab8472533fe8f5950.tar.bz2
YetAnotherConfigLib-af472c8304c9e1864b5c2a1ab8472533fe8f5950.zip
`ListOption.Builder#initial` overload to supply initial values based on context. (close #94)
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/ListOption.java5
-rw-r--r--common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java6
2 files changed, 8 insertions, 3 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/api/ListOption.java b/common/src/main/java/dev/isxander/yacl3/api/ListOption.java
index 0371c35..1f4adfa 100644
--- a/common/src/main/java/dev/isxander/yacl3/api/ListOption.java
+++ b/common/src/main/java/dev/isxander/yacl3/api/ListOption.java
@@ -76,6 +76,11 @@ public interface ListOption<T> extends OptionGroup, Option<List<T>> {
/**
* Sets the value that is used when creating new entries
*/
+ Builder<T> initial(@NotNull Supplier<T> initialValue);
+
+ /**
+ * Sets the value that is used when creating new entries
+ */
Builder<T> initial(@NotNull T initialValue);
Builder<T> controller(@NotNull Function<Option<T>, ControllerBuilder<T>> controller);
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 25ff7ba..12842c1 100644
--- a/common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java
@@ -21,7 +21,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
private final Component name;
private final OptionDescription description;
private final Binding<List<T>> binding;
- private final T initialValue;
+ private final Supplier<T> initialValue;
private final List<ListOptionEntry<T>> entries;
private final boolean collapsed;
private boolean available;
@@ -33,7 +33,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
private final List<BiConsumer<Option<List<T>>, List<T>>> listeners;
private final List<Runnable> refreshListeners;
- public ListOptionImpl(@NotNull Component name, @NotNull OptionDescription description, @NotNull Binding<List<T>> binding, @NotNull 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) {
+ 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;
@@ -105,7 +105,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
@Override
public ListOptionEntry<T> insertNewEntry() {
- ListOptionEntry<T> newEntry = entryFactory.create(initialValue);
+ ListOptionEntry<T> newEntry = entryFactory.create(initialValue.get());
if (insertEntriesAtEnd) {
entries.add(newEntry);
} else {