File tree 2 files changed +33
-2
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/context/config
test/java/org/springframework/boot/context/config
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 23
23
import java .util .EnumSet ;
24
24
import java .util .List ;
25
25
import java .util .Set ;
26
+ import java .util .function .Consumer ;
26
27
27
28
import org .springframework .core .env .Environment ;
28
29
import org .springframework .core .env .PropertySource ;
@@ -224,10 +225,24 @@ public String toString() {
224
225
* @param option the option to exclude
225
226
* @return a new {@link Options} instance
226
227
*/
227
- Options without (Option option ) {
228
+ public Options without (Option option ) {
229
+ return copy ((options ) -> options .remove (option ));
230
+ }
231
+
232
+ /**
233
+ * Create a new {@link Options} instance that contains the options in this set
234
+ * including the given option.
235
+ * @param option the option to include
236
+ * @return a new {@link Options} instance
237
+ */
238
+ public Options with (Option option ) {
239
+ return copy ((options ) -> options .add (option ));
240
+ }
241
+
242
+ private Options copy (Consumer <EnumSet <Option >> processor ) {
228
243
EnumSet <Option > options = EnumSet .noneOf (Option .class );
229
244
options .addAll (this .options );
230
- options . remove ( option );
245
+ processor . accept ( options );
231
246
return new Options (options );
232
247
}
233
248
Original file line number Diff line number Diff line change @@ -129,6 +129,22 @@ void optionsNoneReturnsEmptyOptions() {
129
129
assertThat (Options .NONE .asSet ()).isEmpty ();
130
130
}
131
131
132
+ @ Test
133
+ void optionsWithoutReturnsNewOptions () {
134
+ Options options = Options .of (Option .IGNORE_IMPORTS , Option .IGNORE_PROFILES );
135
+ Options without = options .without (Option .IGNORE_PROFILES );
136
+ assertThat (options .asSet ()).containsExactly (Option .IGNORE_IMPORTS , Option .IGNORE_PROFILES );
137
+ assertThat (without .asSet ()).containsExactly (Option .IGNORE_IMPORTS );
138
+ }
139
+
140
+ @ Test
141
+ void optionsWithReturnsNewOptions () {
142
+ Options options = Options .of (Option .IGNORE_IMPORTS );
143
+ Options with = options .with (Option .IGNORE_PROFILES );
144
+ assertThat (options .asSet ()).containsExactly (Option .IGNORE_IMPORTS );
145
+ assertThat (with .asSet ()).containsExactly (Option .IGNORE_IMPORTS , Option .IGNORE_PROFILES );
146
+ }
147
+
132
148
@ Test
133
149
void propertySourceOptionsAlwaysReturnsSameOptionsEachTime () {
134
150
PropertySourceOptions options = PropertySourceOptions .always (Option .IGNORE_IMPORTS , Option .IGNORE_PROFILES );
You can’t perform that action at this time.
0 commit comments