Use 'name' vs 'key' consistently in PropertySource
This commit is contained in:
parent
03f6d23536
commit
a53d592f62
|
@ -87,8 +87,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
/**
|
/**
|
||||||
* Set the given property on the underlying {@link Properties} object.
|
* Set the given property on the underlying {@link Properties} object.
|
||||||
*/
|
*/
|
||||||
public void setProperty(String key, Object value) {
|
public void setProperty(String name, Object value) {
|
||||||
this.source.put(key, value);
|
this.source.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,8 +96,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
* Useful for method chaining and fluent-style use.
|
* Useful for method chaining and fluent-style use.
|
||||||
* @return this {@link MockPropertySource} instance
|
* @return this {@link MockPropertySource} instance
|
||||||
*/
|
*/
|
||||||
public MockPropertySource withProperty(String key, Object value) {
|
public MockPropertySource withProperty(String name, Object value) {
|
||||||
this.setProperty(key, value);
|
this.setProperty(name, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,24 +220,24 @@ public abstract class CommandLinePropertySource<T> extends PropertySource<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether this {@code PropertySource} contains the given key.
|
* Return whether this {@code PropertySource} contains a property with the given name.
|
||||||
* <p>This implementation first checks to see if the key specified is the special
|
* <p>This implementation first checks to see if the name specified is the special
|
||||||
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
|
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
|
||||||
* and if so delegates to the abstract {@link #getNonOptionArgs()} method
|
* and if so delegates to the abstract {@link #getNonOptionArgs()} method
|
||||||
* checking to see whether it returns an empty collection. Otherwise delegates to and
|
* checking to see whether it returns an empty collection. Otherwise delegates to and
|
||||||
* returns the value of the abstract {@link #containsOption(String)} method.
|
* returns the value of the abstract {@link #containsOption(String)} method.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final boolean containsProperty(String key) {
|
public final boolean containsProperty(String name) {
|
||||||
if (this.nonOptionArgsPropertyName.equals(key)) {
|
if (this.nonOptionArgsPropertyName.equals(name)) {
|
||||||
return !this.getNonOptionArgs().isEmpty();
|
return !this.getNonOptionArgs().isEmpty();
|
||||||
}
|
}
|
||||||
return this.containsOption(key);
|
return this.containsOption(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* <p>This implementation first checks to see if the key specified is the special
|
* <p>This implementation first checks to see if the name specified is the special
|
||||||
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
|
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
|
||||||
* and if so delegates to the abstract {@link #getNonOptionArgs()} method. If so
|
* and if so delegates to the abstract {@link #getNonOptionArgs()} method. If so
|
||||||
* and the collection of non-option arguments is empty, this method returns {@code
|
* and the collection of non-option arguments is empty, this method returns {@code
|
||||||
|
@ -246,8 +246,8 @@ public abstract class CommandLinePropertySource<T> extends PropertySource<T> {
|
||||||
* #getOptionValues(String)} method.
|
* #getOptionValues(String)} method.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final String getProperty(String key) {
|
public final String getProperty(String name) {
|
||||||
if (this.nonOptionArgsPropertyName.equals(key)) {
|
if (this.nonOptionArgsPropertyName.equals(name)) {
|
||||||
Collection<String> nonOptionArguments = this.getNonOptionArgs();
|
Collection<String> nonOptionArguments = this.getNonOptionArgs();
|
||||||
if (nonOptionArguments.isEmpty()) {
|
if (nonOptionArguments.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -256,7 +256,7 @@ public abstract class CommandLinePropertySource<T> extends PropertySource<T> {
|
||||||
return StringUtils.collectionToCommaDelimitedString(nonOptionArguments);
|
return StringUtils.collectionToCommaDelimitedString(nonOptionArguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collection<String> optionValues = this.getOptionValues(key);
|
Collection<String> optionValues = this.getOptionValues(name);
|
||||||
if (optionValues == null) {
|
if (optionValues == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link PropertySource} implementation capable of interrogating its
|
* A {@link PropertySource} implementation capable of interrogating its
|
||||||
* underlying source object to enumerate all possible property key/value
|
* underlying source object to enumerate all possible property name/value
|
||||||
* pairs. Exposes the {@link #getPropertyNames()} method to allow callers
|
* pairs. Exposes the {@link #getPropertyNames()} method to allow callers
|
||||||
* to introspect available properties without having to access the underlying
|
* to introspect available properties without having to access the underlying
|
||||||
* source object. This also facilitates a more efficient implementation of
|
* source object. This also facilitates a more efficient implementation of
|
||||||
|
@ -56,10 +56,10 @@ public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
|
||||||
public abstract String[] getPropertyNames();
|
public abstract String[] getPropertyNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether this {@code PropertySource} contains the given key.
|
* Return whether this {@code PropertySource} contains a property with the given name.
|
||||||
* <p>This implementation checks for the presence of the given key within
|
* <p>This implementation checks for the presence of the given name within
|
||||||
* the {@link #getPropertyNames()} array.
|
* the {@link #getPropertyNames()} array.
|
||||||
* @param key the property key to find
|
* @param name the property to find
|
||||||
*/
|
*/
|
||||||
public boolean containsProperty(String name) {
|
public boolean containsProperty(String name) {
|
||||||
Assert.notNull(name, "property name must not be null");
|
Assert.notNull(name, "property name must not be null");
|
||||||
|
|
|
@ -73,13 +73,13 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean containsOption(String key) {
|
protected boolean containsOption(String name) {
|
||||||
return this.source.has(key);
|
return this.source.has(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getOptionValues(String key) {
|
public List<String> getOptionValues(String name) {
|
||||||
List<?> argValues = this.source.valuesOf(key);
|
List<?> argValues = this.source.valuesOf(name);
|
||||||
List<String> stringArgValues = new ArrayList<String>();
|
List<String> stringArgValues = new ArrayList<String>();
|
||||||
for(Object argValue : argValues) {
|
for(Object argValue : argValues) {
|
||||||
if (!(argValue instanceof String)) {
|
if (!(argValue instanceof String)) {
|
||||||
|
@ -88,7 +88,7 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
|
||||||
stringArgValues.add((String)argValue);
|
stringArgValues.add((String)argValue);
|
||||||
}
|
}
|
||||||
if (stringArgValues.size() == 0) {
|
if (stringArgValues.size() == 0) {
|
||||||
if (this.source.has(key)) {
|
if (this.source.has(name)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class MapPropertySource extends EnumerablePropertySource<Map<String, Obje
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getProperty(String key) {
|
public Object getProperty(String name) {
|
||||||
return this.source.get(key);
|
return this.source.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,12 +20,14 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link PropertySource} implementation that extracts properties from a {@link java.util.Properties} object.
|
* {@link PropertySource} implementation that extracts properties from a
|
||||||
|
* {@link java.util.Properties} object.
|
||||||
*
|
*
|
||||||
* <p>Note that because a {@code Properties} object is technically an {@code <Object, Object>}
|
* <p>Note that because a {@code Properties} object is technically an
|
||||||
* {@link java.util.Hashtable Hashtable}, one may contain non-{@code String} keys or values. This
|
* {@code <Object, Object>} {@link java.util.Hashtable Hashtable}, one may contain
|
||||||
* implementation, however is restricted to accessing only {@code String}-based keys and values, in
|
* non-{@code String} keys or values. This implementation, however is restricted to
|
||||||
* the same fashion as {@link Properties#getProperty} and {@link Properties#setProperty}.
|
* accessing only {@code String}-based keys and values, in the same fashion as
|
||||||
|
* {@link Properties#getProperty} and {@link Properties#setProperty}.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class representing a source of key/value property pairs. The underlying
|
* Abstract base class representing a source of name/value property pairs. The underlying
|
||||||
* {@linkplain #getSource() source object} may be of any type {@code T} that encapsulates
|
* {@linkplain #getSource() source object} may be of any type {@code T} that encapsulates
|
||||||
* properties. Examples include {@link java.util.Properties} objects, {@link java.util.Map}
|
* properties. Examples include {@link java.util.Properties} objects, {@link java.util.Map}
|
||||||
* objects, {@code ServletContext} and {@code ServletConfig} objects (for access to init
|
* objects, {@code ServletContext} and {@code ServletConfig} objects (for access to init
|
||||||
|
@ -98,22 +98,22 @@ public abstract class PropertySource<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether this {@code PropertySource} contains the given key.
|
* Return whether this {@code PropertySource} contains the given name.
|
||||||
* <p>This implementation simply checks for a null return value
|
* <p>This implementation simply checks for a null return value
|
||||||
* from {@link #getProperty(String)}. Subclasses may wish to
|
* from {@link #getProperty(String)}. Subclasses may wish to
|
||||||
* implement a more efficient algorithm if possible.
|
* implement a more efficient algorithm if possible.
|
||||||
* @param key the property key to find
|
* @param name the property name to find
|
||||||
*/
|
*/
|
||||||
public boolean containsProperty(String key) {
|
public boolean containsProperty(String name) {
|
||||||
return this.getProperty(key) != null;
|
return this.getProperty(name) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the value associated with the given key, {@code null} if not found.
|
* Return the value associated with the given name, {@code null} if not found.
|
||||||
* @param key the property key to find
|
* @param name the property to find
|
||||||
* @see PropertyResolver#getRequiredProperty(String)
|
* @see PropertyResolver#getRequiredProperty(String)
|
||||||
*/
|
*/
|
||||||
public abstract Object getProperty(String key);
|
public abstract Object getProperty(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hashcode derived from the {@code name} property of this {@code PropertySource}
|
* Return a hashcode derived from the {@code name} property of this {@code PropertySource}
|
||||||
|
@ -154,13 +154,13 @@ public abstract class PropertySource<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce concise output (type and name) if the current log level does not include debug.
|
* Produce concise output (type and name) if the current log level does not include
|
||||||
* If debug is enabled, produce verbose output including hashcode of the PropertySource instance
|
* debug. If debug is enabled, produce verbose output including hashcode of the
|
||||||
* and every key/value property pair.
|
* PropertySource instance and every name/value property pair.
|
||||||
*
|
*
|
||||||
* This variable verbosity is useful as a property source such as system properties
|
* This variable verbosity is useful as a property source such as system properties
|
||||||
* or environment variables may contain an arbitrary number of property pairs, potentially
|
* or environment variables may contain an arbitrary number of property pairs,
|
||||||
* leading to difficult to read exception and log messages.
|
* potentially leading to difficult to read exception and log messages.
|
||||||
*
|
*
|
||||||
* @see Log#isDebugEnabled()
|
* @see Log#isDebugEnabled()
|
||||||
*/
|
*/
|
||||||
|
@ -226,7 +226,7 @@ public abstract class PropertySource<T> {
|
||||||
* Always return {@code null}.
|
* Always return {@code null}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getProperty(String key) {
|
public String getProperty(String name) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,12 +251,12 @@ public abstract class PropertySource<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsProperty(String key) {
|
public boolean containsProperty(String name) {
|
||||||
throw new UnsupportedOperationException(USAGE_ERROR);
|
throw new UnsupportedOperationException(USAGE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProperty(String key) {
|
public String getProperty(String name) {
|
||||||
throw new UnsupportedOperationException(USAGE_ERROR);
|
throw new UnsupportedOperationException(USAGE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,13 +96,13 @@ public class SimpleCommandLinePropertySource extends CommandLinePropertySource<C
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean containsOption(String key) {
|
protected boolean containsOption(String name) {
|
||||||
return this.source.containsOption(key);
|
return this.source.containsOption(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getOptionValues(String key) {
|
protected List<String> getOptionValues(String name) {
|
||||||
return this.source.getOptionValues(key);
|
return this.source.getOptionValues(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -87,8 +87,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
/**
|
/**
|
||||||
* Set the given property on the underlying {@link Properties} object.
|
* Set the given property on the underlying {@link Properties} object.
|
||||||
*/
|
*/
|
||||||
public void setProperty(String key, Object value) {
|
public void setProperty(String name, Object value) {
|
||||||
this.source.put(key, value);
|
this.source.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,8 +96,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
* Useful for method chaining and fluent-style use.
|
* Useful for method chaining and fluent-style use.
|
||||||
* @return this {@link MockPropertySource} instance
|
* @return this {@link MockPropertySource} instance
|
||||||
*/
|
*/
|
||||||
public MockPropertySource withProperty(String key, Object value) {
|
public MockPropertySource withProperty(String name, Object value) {
|
||||||
this.setProperty(key, value);
|
this.setProperty(name, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
/**
|
/**
|
||||||
* Set the given property on the underlying {@link Properties} object.
|
* Set the given property on the underlying {@link Properties} object.
|
||||||
*/
|
*/
|
||||||
public void setProperty(String key, Object value) {
|
public void setProperty(String name, Object value) {
|
||||||
this.source.put(key, value);
|
this.source.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,8 +95,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
* Useful for method chaining and fluent-style use.
|
* Useful for method chaining and fluent-style use.
|
||||||
* @return this {@link MockPropertySource} instance
|
* @return this {@link MockPropertySource} instance
|
||||||
*/
|
*/
|
||||||
public MockPropertySource withProperty(String key, Object value) {
|
public MockPropertySource withProperty(String name, Object value) {
|
||||||
this.setProperty(key, value);
|
this.setProperty(name, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
/**
|
/**
|
||||||
* Set the given property on the underlying {@link Properties} object.
|
* Set the given property on the underlying {@link Properties} object.
|
||||||
*/
|
*/
|
||||||
public void setProperty(String key, Object value) {
|
public void setProperty(String name, Object value) {
|
||||||
this.source.put(key, value);
|
this.source.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,8 +96,8 @@ public class MockPropertySource extends PropertiesPropertySource {
|
||||||
* Useful for method chaining and fluent-style use.
|
* Useful for method chaining and fluent-style use.
|
||||||
* @return this {@link MockPropertySource} instance
|
* @return this {@link MockPropertySource} instance
|
||||||
*/
|
*/
|
||||||
public MockPropertySource withProperty(String key, Object value) {
|
public MockPropertySource withProperty(String name, Object value) {
|
||||||
this.setProperty(key, value);
|
this.setProperty(name, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue