@@ -39,32 +39,16 @@ public interface ConfigCategory {
3939 * Creates a builder to construct a {@link ConfigCategory}
4040 */
4141 static Builder createBuilder () {
42- return new Builder ();
42+ return new ConfigCategoryImpl . BuilderImpl ();
4343 }
4444
45- class Builder {
46- private Text name ;
47-
48- private final List <Option <?>> rootOptions = new ArrayList <>();
49- private final List <OptionGroup > groups = new ArrayList <>();
50-
51- private final List <Text > tooltipLines = new ArrayList <>();
52-
53- private Builder () {
54-
55- }
56-
45+ interface Builder {
5746 /**
5847 * Sets name of the category
5948 *
6049 * @see ConfigCategory#name()
6150 */
62- public Builder name (@ NotNull Text name ) {
63- Validate .notNull (name , "`name` cannot be null" );
64-
65- this .name = name ;
66- return this ;
67- }
51+ Builder name (@ NotNull Text name );
6852
6953 /**
7054 * Adds an option to the root group of the category.
@@ -74,17 +58,7 @@ public Builder name(@NotNull Text name) {
7458 * @see ConfigCategory#groups()
7559 * @see OptionGroup#isRoot()
7660 */
77- public Builder option (@ NotNull Option <?> option ) {
78- Validate .notNull (option , "`option` must not be null" );
79-
80- if (option instanceof ListOption <?> listOption ) {
81- YACLConstants .LOGGER .warn ("Adding list option as an option is not supported! Rerouting to group!" );
82- return group (listOption );
83- }
84-
85- this .rootOptions .add (option );
86- return this ;
87- }
61+ Builder option (@ NotNull Option <?> option );
8862
8963 /**
9064 * Adds multiple options to the root group of the category.
@@ -94,39 +68,21 @@ public Builder option(@NotNull Option<?> option) {
9468 * @see ConfigCategory#groups()
9569 * @see OptionGroup#isRoot()
9670 */
97- public Builder options (@ NotNull Collection <Option <?>> options ) {
98- Validate .notNull (options , "`options` must not be null" );
99-
100- if (options .stream ().anyMatch (ListOption .class ::isInstance ))
101- throw new UnsupportedOperationException ("List options must not be added as an option but a group!" );
102-
103- this .rootOptions .addAll (options );
104- return this ;
105- }
71+ Builder options (@ NotNull Collection <Option <?>> options );
10672
10773 /**
10874 * Adds an option group.
10975 * To add an option to the root group, use {@link Builder#option(Option)}
11076 * To construct a group, use {@link OptionGroup#createBuilder()}
11177 */
112- public Builder group (@ NotNull OptionGroup group ) {
113- Validate .notNull (group , "`group` must not be null" );
114-
115- this .groups .add (group );
116- return this ;
117- }
78+ Builder group (@ NotNull OptionGroup group );
11879
11980 /**
12081 * Adds multiple option groups.
12182 * To add multiple options to the root group, use {@link Builder#options(Collection)}
12283 * To construct a group, use {@link OptionGroup#createBuilder()}
12384 */
124- public Builder groups (@ NotNull Collection <OptionGroup > groups ) {
125- Validate .notEmpty (groups , "`groups` must not be empty" );
126-
127- this .groups .addAll (groups );
128- return this ;
129- }
85+ Builder groups (@ NotNull Collection <OptionGroup > groups );
13086
13187 /**
13288 * Sets the tooltip to be used by the category.
@@ -135,32 +91,8 @@ public Builder groups(@NotNull Collection<OptionGroup> groups) {
13591 *
13692 * @param tooltips text lines - merged with a new-line on {@link Builder#build()}.
13793 */
138- public Builder tooltip (@ NotNull Text ... tooltips ) {
139- Validate .notEmpty (tooltips , "`tooltips` cannot be empty" );
140-
141- tooltipLines .addAll (List .of (tooltips ));
142- return this ;
143- }
144-
145- public ConfigCategory build () {
146- Validate .notNull (name , "`name` must not be null to build `ConfigCategory`" );
147-
148- List <OptionGroup > combinedGroups = new ArrayList <>();
149- combinedGroups .add (new OptionGroupImpl (Text .empty (), Text .empty (), ImmutableList .copyOf (rootOptions ), false , true ));
150- combinedGroups .addAll (groups );
151-
152- Validate .notEmpty (combinedGroups , "at least one option must be added to build `ConfigCategory`" );
153-
154- MutableText concatenatedTooltip = Text .empty ();
155- boolean first = true ;
156- for (Text line : tooltipLines ) {
157- if (!first ) concatenatedTooltip .append ("\n " );
158- first = false ;
159-
160- concatenatedTooltip .append (line );
161- }
94+ Builder tooltip (@ NotNull Text ... tooltips );
16295
163- return new ConfigCategoryImpl (name , ImmutableList .copyOf (combinedGroups ), concatenatedTooltip );
164- }
96+ ConfigCategory build ();
16597 }
16698}
0 commit comments