Skip to content

Commit 2dd1b1f

Browse files
Add groupIf to ConfigCategory.Builder (#215)
1 parent de5b98f commit 2dd1b1f

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/main/java/dev/isxander/yacl3/api/ConfigCategory.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ default Builder option(@NotNull Supplier<@NotNull Option<?>> optionSupplier) {
7575
* To add to another group, use {@link Builder#group(OptionGroup)}.
7676
* To construct an option, use {@link Option#createBuilder()}
7777
*
78-
* @param condition only if true is the option added
78+
* @param condition whether to add the option
7979
* @return this
8080
*/
8181
@Override
@@ -89,8 +89,8 @@ default Builder optionIf(boolean condition, @NotNull Option<?> option) {
8989
* To add to another group, use {@link Builder#group(OptionGroup)}.
9090
* To construct an option, use {@link Option#createBuilder()}
9191
*
92-
* @param condition only if true is the option added
93-
* @param optionSupplier to be called to initialise the option. called immediately only if condition is true
92+
* @param condition whether to add the option
93+
* @param optionSupplier to be called to initialise the option. called immediately if and only if condition is true
9494
* @return this
9595
*/
9696
@Override
@@ -117,6 +117,40 @@ default Builder optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>
117117
*/
118118
Builder group(@NotNull OptionGroup group);
119119

120+
/**
121+
* Adds an option group.
122+
* To add an option to the root group, use {@link Builder#option(Option)}
123+
* To construct a group, use {@link OptionGroup#createBuilder()}
124+
*
125+
* @param groupSupplier to be called to initialise the group. called immediately
126+
*/
127+
default Builder group(@NotNull Supplier<@NotNull OptionGroup> groupSupplier) {
128+
return group(groupSupplier.get());
129+
}
130+
131+
/**
132+
* Adds an option group if a condition is met.
133+
* To add an option to the root group, use {@link Builder#optionIf(boolean, Option)}.
134+
* To construct a group, use {@link OptionGroup#createBuilder()}
135+
*
136+
* @param condition whether to add the group
137+
*/
138+
default Builder groupIf(boolean condition, @NotNull OptionGroup group) {
139+
return condition ? group(group) : this;
140+
}
141+
142+
/**
143+
* Adds an option group if a condition is met.
144+
* To add an option to the root group, use {@link Builder#optionIf(boolean, Option)}.
145+
* To construct a group, use {@link OptionGroup#createBuilder()}
146+
*
147+
* @param condition whether to add the group
148+
* @param groupSupplier to be called to initialise the group. called immediately if and only if condition is true
149+
*/
150+
default Builder groupIf(boolean condition, @NotNull Supplier<@NotNull OptionGroup> groupSupplier) {
151+
return condition ? group(groupSupplier) : this;
152+
}
153+
120154
/**
121155
* Adds multiple option groups.
122156
* To add multiple options to the root group, use {@link Builder#options(Collection)}

src/main/java/dev/isxander/yacl3/api/OptionAddable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ default OptionAddable option(@NotNull Supplier<@NotNull Option<?>> optionSupplie
2424
/**
2525
* Adds an option to an abstract builder if a condition is met.
2626
* To construct an option, use {@link Option#createBuilder()}
27-
* @param condition only if true is the option added
27+
* @param condition whether to add the option
2828
* @param option the option to add
2929
* @return this
3030
*/
@@ -35,8 +35,8 @@ default OptionAddable optionIf(boolean condition, @NotNull Option<?> option) {
3535
/**
3636
* Adds an option to an abstract builder if a condition is met.
3737
* To construct an option, use {@link Option#createBuilder()}
38-
* @param condition only if true is the option added
39-
* @param optionSupplier to be called to initialise the option. called immediately only if condition is true
38+
* @param condition whether to add the option
39+
* @param optionSupplier to be called to initialise the option. called immediately if and only if condition is true
4040
* @return this
4141
*/
4242
default OptionAddable optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>> optionSupplier) {

0 commit comments

Comments
 (0)