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