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:
parent
1aae68267d
commit
f994c98c39
|
@ -95,7 +95,7 @@
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
public class VariableFormat {
|
public class VariableFormatter {
|
||||||
/** Constant for the default variable prefix. */
|
/** Constant for the default variable prefix. */
|
||||||
static final String DEFAULT_PREFIX = "${";
|
static final String DEFAULT_PREFIX = "${";
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public class VariableFormat {
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* if the map is undefined
|
* 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);
|
setValueMap(valueMap);
|
||||||
setVariablePrefix(prefix);
|
setVariablePrefix(prefix);
|
||||||
setVariableSuffix(suffix);
|
setVariableSuffix(suffix);
|
||||||
|
@ -150,7 +150,7 @@ public VariableFormat(Map valueMap, String prefix, String suffix, char escape) {
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* if the map is undefined
|
* 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);
|
this(valueMap, prefix, suffix, DEFAULT_ESCAPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ public VariableFormat(Map valueMap, String prefix, String suffix) {
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* if the map is undefined
|
* if the map is undefined
|
||||||
*/
|
*/
|
||||||
public VariableFormat(Map valueMap) {
|
public VariableFormatter(Map valueMap) {
|
||||||
this(valueMap, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE);
|
this(valueMap, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ public String replace(Object source) {
|
||||||
* @return the result of the replace operation
|
* @return the result of the replace operation
|
||||||
*/
|
*/
|
||||||
public static String replace(Map valueMap, Object source) {
|
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
|
* @return the result of the replace operation
|
||||||
*/
|
*/
|
||||||
public static String replace(Map valueMap, String prefix, String suffix, Object source) {
|
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
|
* @return the result of the replace operation
|
||||||
*/
|
*/
|
||||||
public static String replaceSystemProperties(Object source) {
|
public static String replaceSystemProperties(Object source) {
|
||||||
return new VariableFormat(System.getProperties()).replace(source);
|
return new VariableFormatter(System.getProperties()).replace(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -51,7 +51,7 @@ public static Test suite() {
|
||||||
suite.addTest(InterpolationTest.suite());
|
suite.addTest(InterpolationTest.suite());
|
||||||
suite.addTest(StrBuilderTest.suite());
|
suite.addTest(StrBuilderTest.suite());
|
||||||
suite.addTest(StrTokenizerTest.suite());
|
suite.addTest(StrTokenizerTest.suite());
|
||||||
suite.addTestSuite(VariableFormatTest.class);
|
suite.addTestSuite(VariableFormatterTest.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,15 @@
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for VariableResolver.
|
* Test class for VariableFormatter.
|
||||||
*
|
*
|
||||||
* @author Oliver Heger
|
* @author Oliver Heger
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class VariableFormatTest extends TestCase {
|
public class VariableFormatterTest extends TestCase {
|
||||||
static final String REPLACE_TEMPLATE = "The ${animal} jumps over the ${target}.";
|
static final String REPLACE_TEMPLATE = "The ${animal} jumps over the ${target}.";
|
||||||
|
|
||||||
private VariableFormat format;
|
private VariableFormatter format;
|
||||||
|
|
||||||
private Map values;
|
private Map values;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ protected void setUp() throws Exception {
|
||||||
map.put("animal", "quick brown fox");
|
map.put("animal", "quick brown fox");
|
||||||
map.put("target", "lazy dog");
|
map.put("target", "lazy dog");
|
||||||
setValues(map);
|
setValues(map);
|
||||||
setFormat(new VariableFormat(map));
|
setFormat(new VariableFormatter(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,31 +48,31 @@ protected void setUp() throws Exception {
|
||||||
*/
|
*/
|
||||||
public void testInitialize() {
|
public void testInitialize() {
|
||||||
assertNotNull(format.getValueMap());
|
assertNotNull(format.getValueMap());
|
||||||
assertEquals(VariableFormat.DEFAULT_PREFIX, format.getVariablePrefix());
|
assertEquals(VariableFormatter.DEFAULT_PREFIX, format.getVariablePrefix());
|
||||||
assertEquals(VariableFormat.DEFAULT_SUFFIX, format.getVariableSuffix());
|
assertEquals(VariableFormatter.DEFAULT_SUFFIX, format.getVariableSuffix());
|
||||||
assertEquals(VariableFormat.DEFAULT_ESCAPE, format.getEscapeCharacter());
|
assertEquals(VariableFormatter.DEFAULT_ESCAPE, format.getEscapeCharacter());
|
||||||
|
|
||||||
format = new VariableFormat(values, "<<", ">>", '\\');
|
format = new VariableFormatter(values, "<<", ">>", '\\');
|
||||||
assertEquals("<<", format.getVariablePrefix());
|
assertEquals("<<", format.getVariablePrefix());
|
||||||
assertEquals(">>", format.getVariableSuffix());
|
assertEquals(">>", format.getVariableSuffix());
|
||||||
assertEquals('\\', format.getEscapeCharacter());
|
assertEquals('\\', format.getEscapeCharacter());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
format = new VariableFormat(null);
|
format = new VariableFormatter(null);
|
||||||
fail("Could create format object with null map!");
|
fail("Could create format object with null map!");
|
||||||
} catch (IllegalArgumentException iex) {
|
} catch (IllegalArgumentException iex) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
format = new VariableFormat(values, "${", null);
|
format = new VariableFormatter(values, "${", null);
|
||||||
fail("Could create format object with undefined suffix!");
|
fail("Could create format object with undefined suffix!");
|
||||||
} catch (IllegalArgumentException iex) {
|
} catch (IllegalArgumentException iex) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
format = new VariableFormat(values, null, "]");
|
format = new VariableFormatter(values, null, "]");
|
||||||
fail("Could create format object with undefined prefix!");
|
fail("Could create format object with undefined prefix!");
|
||||||
} catch (IllegalArgumentException iex) {
|
} catch (IllegalArgumentException iex) {
|
||||||
// ok
|
// ok
|
||||||
|
@ -163,7 +163,7 @@ public void testReplaceObject() {
|
||||||
* Tests chaning variable prefix and suffix and the escaping character.
|
* Tests chaning variable prefix and suffix and the escaping character.
|
||||||
*/
|
*/
|
||||||
public void testNonDefaultTokens() {
|
public void testNonDefaultTokens() {
|
||||||
format = new VariableFormat(values, "<<", ">>", '\\');
|
format = new VariableFormatter(values, "<<", ">>", '\\');
|
||||||
assertEquals("The quick brown fox jumps over the lazy dog.", format
|
assertEquals("The quick brown fox jumps over the lazy dog.", format
|
||||||
.replace("The <<animal>> jumps over the <<target>>."));
|
.replace("The <<animal>> jumps over the <<target>>."));
|
||||||
assertEquals("The quick brown fox jumps over the <<target>>.", format
|
assertEquals("The quick brown fox jumps over the <<target>>.", format
|
||||||
|
@ -174,10 +174,10 @@ public void testNonDefaultTokens() {
|
||||||
* Tests invoking the static convenience methods.
|
* Tests invoking the static convenience methods.
|
||||||
*/
|
*/
|
||||||
public void testNonInstanceMethods() {
|
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("animal", "cow");
|
||||||
values.put("target", "moon");
|
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 ⌖."));
|
"The &animal; jumps over the ⌖."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ public void testReplaceSystemProperties() {
|
||||||
buf.append(System.getProperty("os.name"));
|
buf.append(System.getProperty("os.name"));
|
||||||
buf.append(", your home directory is ");
|
buf.append(", your home directory is ");
|
||||||
buf.append(System.getProperty("user.home")).append('.');
|
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 "
|
+ "working with ${os.name}, your home "
|
||||||
+ "directory is ${user.home}."));
|
+ "directory is ${user.home}."));
|
||||||
}
|
}
|
||||||
|
@ -204,11 +204,11 @@ void setValues(Map values) {
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableFormat getFormat() {
|
VariableFormatter getFormat() {
|
||||||
return this.format;
|
return this.format;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFormat(VariableFormat format) {
|
void setFormat(VariableFormatter format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue