diff options
author | isXander <xander@isxander.dev> | 2024-04-14 23:31:43 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2024-04-14 23:31:43 +0100 |
commit | 08193720d93f809e988d0e37821937de3c1be8d7 (patch) | |
tree | 43de1541f6444a96b26c14ad652492aeba4437a0 | |
parent | 97bbc5a3d91ed57e55796777bbfc117ff28e2221 (diff) | |
download | YetAnotherConfigLib-08193720d93f809e988d0e37821937de3c1be8d7.tar.gz YetAnotherConfigLib-08193720d93f809e988d0e37821937de3c1be8d7.tar.bz2 YetAnotherConfigLib-08193720d93f809e988d0e37821937de3c1be8d7.zip |
Add util to get a flat stream of all options
-rw-r--r-- | src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java b/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java index cf33f0f..be56f77 100644 --- a/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java +++ b/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java @@ -4,8 +4,17 @@ import dev.isxander.yacl3.api.*; import java.util.function.Consumer; import java.util.function.Function; +import java.util.stream.Stream; public class OptionUtils { + public static Stream<Option<?>> getFlatOptions(YetAnotherConfigLib yacl) { + return yacl.categories().stream() + .flatMap(category -> category.groups().stream()) + .flatMap(group -> group instanceof ListOption<?> list + ? Stream.of(list) + : group.options().stream()); + } + /** * Consumes all options, ignoring groups and categories. * When consumer returns true, this function stops iterating. |