From d938dd97bfbf20f8b0ee2cb0b27766200652080c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 8 Apr 2021 13:21:14 -0700 Subject: [PATCH] Add with/without methods to ConfigData.Options Add convenience methods to ConfigData.Options to allow new Options instances to be created with options excluded or included. See gh-25766 --- .../boot/context/config/ConfigData.java | 19 +++++++++++++++++-- .../boot/context/config/ConfigDataTests.java | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java index fcb5eb83fc0b..d9a7628ec6a8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java @@ -23,6 +23,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; +import java.util.function.Consumer; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertySource; @@ -224,10 +225,24 @@ public String toString() { * @param option the option to exclude * @return a new {@link Options} instance */ - Options without(Option option) { + public Options without(Option option) { + return copy((options) -> options.remove(option)); + } + + /** + * Create a new {@link Options} instance that contains the options in this set + * including the given option. + * @param option the option to include + * @return a new {@link Options} instance + */ + public Options with(Option option) { + return copy((options) -> options.add(option)); + } + + private Options copy(Consumer> processor) { EnumSet