Polish org.springframework.core.env.PropertySource

See gh-30195
This commit is contained in:
Sam Brannen 2023-08-31 13:38:13 +02:00
parent 6876c284f4
commit 2e4e43b5bd
1 changed files with 12 additions and 9 deletions

View File

@ -92,6 +92,8 @@ public abstract class PropertySource<T> {
/** /**
* Return the name of this {@code PropertySource}. * Return the name of this {@code PropertySource}.
* <p>See the {@linkplain PropertySource class-level Javadoc} for details
* on property source identity and names.
*/ */
public String getName() { public String getName() {
return this.name; return this.name;
@ -170,21 +172,22 @@ public abstract class PropertySource<T> {
/** /**
* Return a {@code PropertySource} implementation intended for collection comparison purposes only. * Return a {@code PropertySource} implementation intended for collection
* <p>Primarily for internal use, but given a collection of {@code PropertySource} objects, may be * comparison purposes only.
* used as follows: * <p>Primarily for internal use, but given a collection of {@code PropertySource}
* objects, may be used as follows:
* <pre class="code"> * <pre class="code">
* {@code List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>(); * List&lt;PropertySource&lt;?&gt;&gt; sources = new ArrayList&lt;&gt;();
* sources.add(new MapPropertySource("sourceA", mapA)); * sources.add(new MapPropertySource("sourceA", mapA));
* sources.add(new MapPropertySource("sourceB", mapB)); * sources.add(new MapPropertySource("sourceB", mapB));
* assert sources.contains(PropertySource.named("sourceA")); * assert sources.contains(PropertySource.named("sourceA"));
* assert sources.contains(PropertySource.named("sourceB")); * assert sources.contains(PropertySource.named("sourceB"));
* assert !sources.contains(PropertySource.named("sourceC")); * assert !sources.contains(PropertySource.named("sourceC"));</pre>
* }</pre> * <p>The returned {@code PropertySource} will throw {@code UnsupportedOperationException}
* The returned {@code PropertySource} will throw {@code UnsupportedOperationException}
* if any methods other than {@code equals(Object)}, {@code hashCode()}, and {@code toString()} * if any methods other than {@code equals(Object)}, {@code hashCode()}, and {@code toString()}
* are called. * are called.
* @param name the name of the comparison {@code PropertySource} to be created and returned. * @param name the name of the comparison {@code PropertySource} to be created
* and returned
*/ */
public static PropertySource<?> named(String name) { public static PropertySource<?> named(String name) {
return new ComparisonPropertySource(name); return new ComparisonPropertySource(name);
@ -206,7 +209,7 @@ public abstract class PropertySource<T> {
public static class StubPropertySource extends PropertySource<Object> { public static class StubPropertySource extends PropertySource<Object> {
public StubPropertySource(String name) { public StubPropertySource(String name) {
super(name, new Object()); super(name);
} }
/** /**