Skip to content

Commit 7ece0e2

Browse files
committed
Correct code example for YamlProcessor.setDocumentMatchers
Issue: SPR-16849
1 parent bfcc1a1 commit 7ece0e2

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
@@ -75,15 +75,16 @@ public abstract class YamlProcessor {
7575
* name: My Cool App
7676
* </pre>
7777
* when mapped with
78-
* <code>documentMatchers = YamlProcessor.mapMatcher({"environment": "prod"})</code>
78+
* <pre class="code">
79+
* setDocumentMatchers(properties ->
80+
* ("prod".equals(properties.getProperty("environment")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND));
81+
* </pre>
7982
* would end up as
8083
* <pre class="code">
8184
* environment=prod
8285
* url=http://foo.bar.com
8386
* name=My Cool App
84-
* url=http://dev.bar.com
8587
* </pre>
86-
* @param matchers a map of keys to value patterns (regular expressions)
8788
*/
8889
public void setDocumentMatchers(DocumentMatcher... matchers) {
8990
this.documentMatchers = Arrays.asList(matchers);
@@ -92,8 +93,7 @@ public void setDocumentMatchers(DocumentMatcher... matchers) {
9293
/**
9394
* Flag indicating that a document for which all the
9495
* {@link #setDocumentMatchers(DocumentMatcher...) document matchers} abstain will
95-
* nevertheless match.
96-
* @param matchDefault the flag to set (default true)
96+
* nevertheless match. Default is {@code true}.
9797
*/
9898
public void setMatchDefault(boolean matchDefault) {
9999
this.matchDefault = matchDefault;
@@ -102,9 +102,7 @@ public void setMatchDefault(boolean matchDefault) {
102102
/**
103103
* Method to use for resolving resources. Each resource will be converted to a Map,
104104
* so this property is used to decide which map entries to keep in the final output
105-
* from this factory.
106-
* @param resolutionMethod the resolution method to set (defaults to
107-
* {@link ResolutionMethod#OVERRIDE}).
105+
* from this factory. Default is {@link ResolutionMethod#OVERRIDE}.
108106
*/
109107
public void setResolutionMethod(ResolutionMethod resolutionMethod) {
110108
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)