Skip to content

Commit 455d8ac

Browse files
committed
Correct code example for YamlProcessor.setDocumentMatchers
Issue: SPR-16849 (cherry picked from commit 7ece0e2)
1 parent b80c13b commit 455d8ac

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ public abstract class YamlProcessor {
8080
* name: My Cool App
8181
* </pre>
8282
* when mapped with
83-
* <code>documentMatchers = YamlProcessor.mapMatcher({"environment": "prod"})</code>
83+
* <pre class="code">
84+
* setDocumentMatchers(properties ->
85+
* ("prod".equals(properties.getProperty("environment")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND));
86+
* </pre>
8487
* would end up as
8588
* <pre class="code">
8689
* environment=prod
8790
* url=http://foo.bar.com
8891
* name=My Cool App
89-
* url=http://dev.bar.com
9092
* </pre>
91-
* @param matchers a map of keys to value patterns (regular expressions)
9293
*/
9394
public void setDocumentMatchers(DocumentMatcher... matchers) {
9495
this.documentMatchers = Arrays.asList(matchers);
@@ -97,8 +98,7 @@ public void setDocumentMatchers(DocumentMatcher... matchers) {
9798
/**
9899
* Flag indicating that a document for which all the
99100
* {@link #setDocumentMatchers(DocumentMatcher...) document matchers} abstain will
100-
* nevertheless match.
101-
* @param matchDefault the flag to set (default true)
101+
* nevertheless match. Default is {@code true}.
102102
*/
103103
public void setMatchDefault(boolean matchDefault) {
104104
this.matchDefault = matchDefault;
@@ -107,9 +107,7 @@ public void setMatchDefault(boolean matchDefault) {
107107
/**
108108
* Method to use for resolving resources. Each resource will be converted to a Map,
109109
* so this property is used to decide which map entries to keep in the final output
110-
* from this factory.
111-
* @param resolutionMethod the resolution method to set (defaults to
112-
* {@link ResolutionMethod#OVERRIDE}).
110+
* from this factory. Default is {@link ResolutionMethod#OVERRIDE}.
113111
*/
114112
public void setResolutionMethod(ResolutionMethod resolutionMethod) {
115113
Assert.notNull(resolutionMethod, "ResolutionMethod must not be null");

spring-beans/src/test/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBeanTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testLoadResourceWithSelectedDocuments() {
107107
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
108108
factory.setResources(new ByteArrayResource(
109109
"foo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
110-
factory.setDocumentMatchers((DocumentMatcher) properties -> ("bag".equals(properties.getProperty("foo")) ?
110+
factory.setDocumentMatchers(properties -> ("bag".equals(properties.getProperty("foo")) ?
111111
MatchStatus.FOUND : MatchStatus.NOT_FOUND));
112112
Properties properties = factory.getObject();
113113
assertThat(properties.getProperty("foo"), equalTo("bag"));
@@ -120,7 +120,7 @@ public void testLoadResourceWithDefaultMatch() {
120120
factory.setMatchDefault(true);
121121
factory.setResources(new ByteArrayResource(
122122
"one: two\n---\nfoo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
123-
factory.setDocumentMatchers((DocumentMatcher) properties -> {
123+
factory.setDocumentMatchers(properties -> {
124124
if (!properties.containsKey("foo")) {
125125
return MatchStatus.ABSTAIN;
126126
}
@@ -161,7 +161,7 @@ public void testLoadResourceWithDefaultMatchSkippingMissedMatch() {
161161
factory.setMatchDefault(true);
162162
factory.setResources(new ByteArrayResource(
163163
"one: two\n---\nfoo: bag\nspam: bad\n---\nfoo: bar\nspam: baz".getBytes()));
164-
factory.setDocumentMatchers((DocumentMatcher) properties -> {
164+
factory.setDocumentMatchers(properties -> {
165165
if (!properties.containsKey("foo")) {
166166
return MatchStatus.ABSTAIN;
167167
}

0 commit comments

Comments
 (0)