Renamed VariableFormat to VariableFormatter since it is not a subclass of java.text.Format.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@209509 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2005-07-06 20:33:21 +00:00
parent 1aae68267d
commit f994c98c39
3 changed files with 25 additions and 25 deletions

View File

@ -95,7 +95,7 @@
* @version $Id$
* @since 2.2
*/
public class VariableFormat {
public class VariableFormatter {
/** Constant for the default variable prefix. */
static final String DEFAULT_PREFIX = "${";
@ -131,7 +131,7 @@ public class VariableFormat {
* @throws IllegalArgumentException
* if the map is undefined
*/
public VariableFormat(Map valueMap, String prefix, String suffix, char escape) {
public VariableFormatter(Map valueMap, String prefix, String suffix, char escape) {
setValueMap(valueMap);
setVariablePrefix(prefix);
setVariableSuffix(suffix);
@ -150,7 +150,7 @@ public VariableFormat(Map valueMap, String prefix, String suffix, char escape) {
* @throws IllegalArgumentException
* if the map is undefined
*/
public VariableFormat(Map valueMap, String prefix, String suffix) {
public VariableFormatter(Map valueMap, String prefix, String suffix) {
this(valueMap, prefix, suffix, DEFAULT_ESCAPE);
}
@ -163,7 +163,7 @@ public VariableFormat(Map valueMap, String prefix, String suffix) {
* @throws IllegalArgumentException
* if the map is undefined
*/
public VariableFormat(Map valueMap) {
public VariableFormatter(Map valueMap) {
this(valueMap, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE);
}
@ -298,7 +298,7 @@ public String replace(Object source) {
* @return the result of the replace operation
*/
public static String replace(Map valueMap, Object source) {
return new VariableFormat(valueMap).replace(source);
return new VariableFormatter(valueMap).replace(source);
}
/**
@ -316,7 +316,7 @@ public static String replace(Map valueMap, Object source) {
* @return the result of the replace operation
*/
public static String replace(Map valueMap, String prefix, String suffix, Object source) {
return new VariableFormat(valueMap, prefix, suffix).replace(source);
return new VariableFormatter(valueMap, prefix, suffix).replace(source);
}
/**
@ -327,7 +327,7 @@ public static String replace(Map valueMap, String prefix, String suffix, Object
* @return the result of the replace operation
*/
public static String replaceSystemProperties(Object source) {
return new VariableFormat(System.getProperties()).replace(source);
return new VariableFormatter(System.getProperties()).replace(source);
}
/**

View File

@ -51,7 +51,7 @@ public static Test suite() {
suite.addTest(InterpolationTest.suite());
suite.addTest(StrBuilderTest.suite());
suite.addTest(StrTokenizerTest.suite());
suite.addTestSuite(VariableFormatTest.class);
suite.addTestSuite(VariableFormatterTest.class);
return suite;
}

View File

@ -22,15 +22,15 @@
import junit.framework.TestCase;
/**
* Test class for VariableResolver.
* Test class for VariableFormatter.
*
* @author Oliver Heger
* @version $Id$
*/
public class VariableFormatTest extends TestCase {
public class VariableFormatterTest extends TestCase {
static final String REPLACE_TEMPLATE = "The ${animal} jumps over the ${target}.";
private VariableFormat format;
private VariableFormatter format;
private Map values;
@ -40,7 +40,7 @@ protected void setUp() throws Exception {
map.put("animal", "quick brown fox");
map.put("target", "lazy dog");
setValues(map);
setFormat(new VariableFormat(map));
setFormat(new VariableFormatter(map));
}
/**
@ -48,31 +48,31 @@ protected void setUp() throws Exception {
*/
public void testInitialize() {
assertNotNull(format.getValueMap());
assertEquals(VariableFormat.DEFAULT_PREFIX, format.getVariablePrefix());
assertEquals(VariableFormat.DEFAULT_SUFFIX, format.getVariableSuffix());
assertEquals(VariableFormat.DEFAULT_ESCAPE, format.getEscapeCharacter());
assertEquals(VariableFormatter.DEFAULT_PREFIX, format.getVariablePrefix());
assertEquals(VariableFormatter.DEFAULT_SUFFIX, format.getVariableSuffix());
assertEquals(VariableFormatter.DEFAULT_ESCAPE, format.getEscapeCharacter());
format = new VariableFormat(values, "<<", ">>", '\\');
format = new VariableFormatter(values, "<<", ">>", '\\');
assertEquals("<<", format.getVariablePrefix());
assertEquals(">>", format.getVariableSuffix());
assertEquals('\\', format.getEscapeCharacter());
try {
format = new VariableFormat(null);
format = new VariableFormatter(null);
fail("Could create format object with null map!");
} catch (IllegalArgumentException iex) {
// ok
}
try {
format = new VariableFormat(values, "${", null);
format = new VariableFormatter(values, "${", null);
fail("Could create format object with undefined suffix!");
} catch (IllegalArgumentException iex) {
// ok
}
try {
format = new VariableFormat(values, null, "]");
format = new VariableFormatter(values, null, "]");
fail("Could create format object with undefined prefix!");
} catch (IllegalArgumentException iex) {
// ok
@ -163,7 +163,7 @@ public void testReplaceObject() {
* Tests chaning variable prefix and suffix and the escaping character.
*/
public void testNonDefaultTokens() {
format = new VariableFormat(values, "<<", ">>", '\\');
format = new VariableFormatter(values, "<<", ">>", '\\');
assertEquals("The quick brown fox jumps over the lazy dog.", format
.replace("The <<animal>> jumps over the <<target>>."));
assertEquals("The quick brown fox jumps over the <<target>>.", format
@ -174,10 +174,10 @@ public void testNonDefaultTokens() {
* Tests invoking the static convenience methods.
*/
public void testNonInstanceMethods() {
assertEquals("The quick brown fox jumps over the lazy dog.", VariableFormat.replace(values, REPLACE_TEMPLATE));
assertEquals("The quick brown fox jumps over the lazy dog.", VariableFormatter.replace(values, REPLACE_TEMPLATE));
values.put("animal", "cow");
values.put("target", "moon");
assertEquals("The cow jumps over the moon.", VariableFormat.replace(values, "&", ";",
assertEquals("The cow jumps over the moon.", VariableFormatter.replace(values, "&", ";",
"The &animal; jumps over the &target;."));
}
@ -191,7 +191,7 @@ public void testReplaceSystemProperties() {
buf.append(System.getProperty("os.name"));
buf.append(", your home directory is ");
buf.append(System.getProperty("user.home")).append('.');
assertEquals(buf.toString(), VariableFormat.replaceSystemProperties("Hi ${user.name}, you are "
assertEquals(buf.toString(), VariableFormatter.replaceSystemProperties("Hi ${user.name}, you are "
+ "working with ${os.name}, your home "
+ "directory is ${user.home}."));
}
@ -204,11 +204,11 @@ void setValues(Map values) {
this.values = values;
}
VariableFormat getFormat() {
VariableFormatter getFormat() {
return this.format;
}
void setFormat(VariableFormat format) {
void setFormat(VariableFormatter format) {
this.format = format;
}
}