You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/05/15 09:34:17 UTC
svn commit: r775048 - in
/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text:
StrLookup.java StrSubstitutor.java
Author: bayard
Date: Fri May 15 07:34:17 2009
New Revision: 775048
URL: http://svn.apache.org/viewvc?rev=775048&view=rev
Log:
Commiting my variant patch from LANG-336 to Henrik Maryn's genericizing code
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrLookup.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrSubstitutor.java
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrLookup.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrLookup.java?rev=775048&r1=775047&r2=775048&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrLookup.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrLookup.java Fri May 15 07:34:17 2009
@@ -35,16 +35,16 @@
* @since 2.2
* @version $Id$
*/
-public abstract class StrLookup {
+public abstract class StrLookup<V> {
/**
* Lookup that always returns null.
*/
- private static final StrLookup NONE_LOOKUP;
+ private static final StrLookup<?> NONE_LOOKUP;
/**
* Lookup that uses System properties.
*/
- private static final StrLookup SYSTEM_PROPERTIES_LOOKUP;
+ private static final StrLookup<Object> SYSTEM_PROPERTIES_LOOKUP;
static {
NONE_LOOKUP = new MapStrLookup(null);
StrLookup lookup = null;
@@ -62,7 +62,7 @@
*
* @return a lookup that always returns null, not null
*/
- public static StrLookup noneLookup() {
+ public static StrLookup<?> noneLookup() {
return NONE_LOOKUP;
}
@@ -77,7 +77,7 @@
*
* @return a lookup using system properties, not null
*/
- public static StrLookup systemPropertiesLookup() {
+ public static StrLookup<Object> systemPropertiesLookup() {
return SYSTEM_PROPERTIES_LOOKUP;
}
@@ -90,8 +90,8 @@
* @param map the map of keys to values, may be null
* @return a lookup using the map, not null
*/
- public static StrLookup mapLookup(Map map) {
- return new MapStrLookup(map);
+ public static <V> StrLookup mapLookup(Map<String, V> map) {
+ return new MapStrLookup<V>(map);
}
//-----------------------------------------------------------------------
@@ -122,19 +122,19 @@
//-----------------------------------------------------------------------
/**
- * Lookup imnplementation that uses a Map.
+ * Lookup implementation that uses a Map.
*/
- static class MapStrLookup extends StrLookup {
+ static class MapStrLookup<V> extends StrLookup {
/** Map keys are variable names and value. */
- private final Map map;
+ private final Map<String, V> map;
/**
* Creates a new instance backed by a Map.
*
* @param map the map of keys to values, may be null
*/
- MapStrLookup(Map map) {
+ MapStrLookup(Map<String, V> map) {
this.map = map;
}
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrSubstitutor.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrSubstitutor.java?rev=775048&r1=775047&r2=775048&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrSubstitutor.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrSubstitutor.java Fri May 15 07:34:17 2009
@@ -130,7 +130,7 @@
* @param valueMap the map with the values, may be null
* @return the result of the replace operation
*/
- public static String replace(Object source, Map valueMap) {
+ public static <V> String replace(Object source, Map<String, V> valueMap) {
return new StrSubstitutor(valueMap).replace(source);
}
@@ -146,7 +146,7 @@
* @return the result of the replace operation
* @throws IllegalArgumentException if the prefix or suffix is null
*/
- public static String replace(Object source, Map valueMap, String prefix, String suffix) {
+ public static <V> String replace(Object source, Map<String, V> valueMap, String prefix, String suffix) {
return new StrSubstitutor(valueMap, prefix, suffix).replace(source);
}
@@ -176,7 +176,7 @@
*
* @param valueMap the map with the variables' values, may be null
*/
- public StrSubstitutor(Map valueMap) {
+ public <V> StrSubstitutor(Map<String, V> valueMap) {
this(StrLookup.mapLookup(valueMap), DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE);
}
@@ -188,7 +188,7 @@
* @param suffix the suffix for variables, not null
* @throws IllegalArgumentException if the prefix or suffix is null
*/
- public StrSubstitutor(Map valueMap, String prefix, String suffix) {
+ public <V> StrSubstitutor(Map<String, V> valueMap, String prefix, String suffix) {
this(StrLookup.mapLookup(valueMap), prefix, suffix, DEFAULT_ESCAPE);
}
@@ -201,7 +201,7 @@
* @param escape the escape character
* @throws IllegalArgumentException if the prefix or suffix is null
*/
- public StrSubstitutor(Map valueMap, String prefix, String suffix, char escape) {
+ public <V> StrSubstitutor(Map<String, V> valueMap, String prefix, String suffix, char escape) {
this(StrLookup.mapLookup(valueMap), prefix, suffix, escape);
}