You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2006/07/07 01:31:00 UTC
svn commit: r419739 -
/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/VariableFormatter.java
Author: scolebourne
Date: Thu Jul 6 16:31:00 2006
New Revision: 419739
URL: http://svn.apache.org/viewvc?rev=419739&view=rev
Log:
Layout action methods to match general lang formatting
Modified:
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/VariableFormatter.java
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/VariableFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/VariableFormatter.java?rev=419739&r1=419738&r2=419739&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/VariableFormatter.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/VariableFormatter.java Thu Jul 6 16:31:00 2006
@@ -605,27 +605,91 @@
this.setEscapeCharacter(escape);
}
+ //-----------------------------------------------------------------------
/**
- * Creates a parser object for tokenizing the input data.
+ * Replaces the occurrences of all variables in the given source array by
+ * their current values.
*
* @param data
- * the input data
+ * a character array with the source data
+ * @return the result of the replace operation
+ */
+ public String replace(char[] data) {
+ return replace(data, 0, data == null ? 0 : data.length);
+ }
+
+ /**
+ * Replaces the occurrences of all variables in the given source array by their
+ * current values. Only the specified portion of the array will be processed.
+ *
+ * @param data
+ * a character array with the source data
* @param offset
- * the offset in the source array
+ * the start offset; processing will start at this position
* @param length
- * the length of the data to be processed
- * @return the parser
+ * the length of the portion to be processed
+ * @return the result of the replace operation
*/
- protected VariableParser createParser(char[] data, int offset, int length) {
- return new VariableParser(
- StrMatcher.stringMatcher(getVariablePrefix()),
- StrMatcher.stringMatcher(getVariableSuffix()),
- StrMatcher.stringMatcher(String.valueOf(getEscapeCharacter()) + getVariablePrefix()), offset, length);
+ public String replace(char[] data, int offset, int length) {
+ Object result = doReplace(data, offset, length, null, null);
+ return result == null ? null : result.toString();
}
/**
- * Recursive handler for multiple levels of interpolation. This is the main interpolation method, which resolves the
- * values of all variable references contained in the passed in text.
+ * Replaces the occurrences of all variables in the given source data by
+ * their current values.
+ *
+ * @param source
+ * the text to be interpolated; this can be an arbitrary object
+ * whose <code>toString()</code> method will be called
+ * @return the result of the replace operation
+ */
+ public String replace(Object source) {
+ Object result = replaceObject(source);
+ return result == null ? null : result.toString();
+ }
+
+ /**
+ * Replaces the occurrences of all variables in the given source data by
+ * their current values. If the source consists only of a single variable
+ * reference, this method directly returns the value of this variable
+ * (which can be an arbitrary object). If the source contains multiple
+ * variable references or static text, the return value will always be a
+ * String with the concatenation of all these elements.
+ *
+ * @param source
+ * the text to be interpolated; this can be an arbitrary object
+ * whose <code>toString()</code> method will be called
+ * @return the result of the replace operation
+ */
+ public Object replaceObject(Object source) {
+ return doReplace(source, null);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Recursive handler for multiple levels of interpolation. This is the main
+ * interpolation method for interpolating objects. It is called for recursively
+ * processing the values of resolved variables.
+ *
+ * @param obj
+ * the data to be interpolated (as object)
+ * @param priorVariables
+ * keeps track of the replaced variables
+ * @return the result of the interpolation process
+ */
+ private Object doReplace(Object obj, List priorVariables) {
+ if (obj == null) {
+ return null;
+ }
+ char[] data = obj.toString().toCharArray();
+ return doReplace(data, 0, data.length, obj, priorVariables);
+ }
+
+ /**
+ * Recursive handler for multiple levels of interpolation. This is the main
+ * interpolation method, which resolves the values of all variable references
+ * contained in the passed in text.
*
* @param data
* the text to be interpolated (as character array)
@@ -720,88 +784,39 @@
}
/**
- * Recursive handler for multiple levels of interpolation. This is the main interpolation method for interpolating
- * objects. It is called for recursively processing the values of resolved variables.
+ * Gets the length from the parsed token.
*
- * @param obj
- * the data to be interpolated (as object)
- * @param priorVariables
- * keeps track of the replaced variables
- * @return the result of the interpolation process
+ * @param tok the token
+ * @return the length
*/
- private Object doReplace(Object obj, List priorVariables) {
- if (obj == null) {
- return null;
- }
- char[] data = obj.toString().toCharArray();
- return doReplace(data, 0, data.length, obj, priorVariables);
- }
-
private int getLength(FieldPosition tok) {
return tok.getEndIndex() - tok.getBeginIndex();
}
/**
- * Replaces the occurrences of all variables in the given source array by their current values.
- *
- * @param data
- * a character array with the source data
- * @return the result of the replace operation
- */
- public String replace(char[] data) {
- return replace(data, 0, data == null ? 0 : data.length);
- }
-
- /**
- * Replaces the occurrences of all variables in the given source array by their current values. Only the specified
- * portion of the array will be processed.
+ * Creates a parser object for tokenizing the input data.
*
* @param data
- * a character array with the source data
+ * the input data
* @param offset
- * the start offset; processing will start at this position
+ * the offset in the source array
* @param length
- * the length of the portion to be processed
- * @return the result of the replace operation
- */
- public String replace(char[] data, int offset, int length) {
- Object result = doReplace(data, offset, length, null, null);
- return result == null ? null : result.toString();
- }
-
- /**
- * Replaces the occurrences of all variables in the given source data by their current values.
- *
- * @param source
- * the text to be interpolated; this can be an arbitrary object whose <code>toString()</code> method
- * will be called
- * @return the result of the replace operation
- */
- public String replace(Object source) {
- Object result = replaceObject(source);
- return result == null ? null : result.toString();
- }
-
- /**
- * Replaces the occurrences of all variables in the given source data by their current values. If the source
- * consists only of a single variable reference, this method directly returns the value of this variable (which can
- * be an arbitrary object). If the source contains multiple variable references or static text, the return value
- * will always be a String with the concatenation of all these elements.
- *
- * @param source
- * the text to be interpolated; this can be an arbitrary object whose <code>toString()</code> method
- * will be called
- * @return the result of the replace operation
+ * the length of the data to be processed
+ * @return the parser
*/
- public Object replaceObject(Object source) {
- return doReplace(source, null);
+ protected VariableParser createParser(char[] data, int offset, int length) {
+ return new VariableParser(
+ StrMatcher.stringMatcher(getVariablePrefix()),
+ StrMatcher.stringMatcher(getVariableSuffix()),
+ StrMatcher.stringMatcher(String.valueOf(getEscapeCharacter()) + getVariablePrefix()), offset, length);
}
/**
- * Resolves the specified variable. This method is called whenever a variable reference is detected in the source
- * text. It is passed the variable's name and must return the corresponding value. This implementation accesses the
- * value map using the variable's name as key. Derived classes may override this method to implement a different
- * strategy for resolving variables.
+ * Resolves the specified variable. This method is called whenever a variable
+ * reference is detected in the source text. It is passed the variable's name
+ * and must return the corresponding value. This implementation accesses the
+ * value map using the variable's name as key. Derived classes may override
+ * this method to implement a different strategy for resolving variables.
*
* @param name
* the name of the variable
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org