Layout action methods to match general lang formatting
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@419739 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3d6bdcae69
commit
7d0e5c002e
|
@ -605,27 +605,91 @@ public class VariableFormatter {
|
||||||
this.setEscapeCharacter(escape);
|
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
|
* @param data
|
||||||
* the input data
|
* a character array with the source data
|
||||||
* @param offset
|
* @return the result of the replace operation
|
||||||
* the offset in the source array
|
|
||||||
* @param length
|
|
||||||
* the length of the data to be processed
|
|
||||||
* @return the parser
|
|
||||||
*/
|
*/
|
||||||
protected VariableParser createParser(char[] data, int offset, int length) {
|
public String replace(char[] data) {
|
||||||
return new VariableParser(
|
return replace(data, 0, data == null ? 0 : data.length);
|
||||||
StrMatcher.stringMatcher(getVariablePrefix()),
|
|
||||||
StrMatcher.stringMatcher(getVariableSuffix()),
|
|
||||||
StrMatcher.stringMatcher(String.valueOf(getEscapeCharacter()) + getVariablePrefix()), offset, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursive handler for multiple levels of interpolation. This is the main interpolation method, which resolves the
|
* Replaces the occurrences of all variables in the given source array by their
|
||||||
* values of all variable references contained in the passed in text.
|
* current values. Only the specified portion of the array will be processed.
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* a character array with the source data
|
||||||
|
* @param offset
|
||||||
|
* the start offset; processing will start at this position
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
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
|
* @param data
|
||||||
* the text to be interpolated (as character array)
|
* the text to be interpolated (as character array)
|
||||||
|
@ -720,88 +784,39 @@ public class VariableFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursive handler for multiple levels of interpolation. This is the main interpolation method for interpolating
|
* Gets the length from the parsed token.
|
||||||
* objects. It is called for recursively processing the values of resolved variables.
|
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param tok the token
|
||||||
* the data to be interpolated (as object)
|
* @return the length
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getLength(FieldPosition tok) {
|
private int getLength(FieldPosition tok) {
|
||||||
return tok.getEndIndex() - tok.getBeginIndex();
|
return tok.getEndIndex() - tok.getBeginIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the occurrences of all variables in the given source array by their current values.
|
* Creates a parser object for tokenizing the input data.
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
* a character array with the source data
|
* the input 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
|
* @param offset
|
||||||
* the start offset; processing will start at this position
|
* the offset in the source array
|
||||||
* @param length
|
* @param length
|
||||||
* the length of the portion to be processed
|
* the length of the data to be processed
|
||||||
* @return the result of the replace operation
|
* @return the parser
|
||||||
*/
|
*/
|
||||||
public String replace(char[] data, int offset, int length) {
|
protected VariableParser createParser(char[] data, int offset, int length) {
|
||||||
Object result = doReplace(data, offset, length, null, null);
|
return new VariableParser(
|
||||||
return result == null ? null : result.toString();
|
StrMatcher.stringMatcher(getVariablePrefix()),
|
||||||
|
StrMatcher.stringMatcher(getVariableSuffix()),
|
||||||
|
StrMatcher.stringMatcher(String.valueOf(getEscapeCharacter()) + getVariablePrefix()), offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the occurrences of all variables in the given source data by their current values.
|
* 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
|
||||||
* @param source
|
* and must return the corresponding value. This implementation accesses the
|
||||||
* the text to be interpolated; this can be an arbitrary object whose <code>toString()</code> method
|
* value map using the variable's name as key. Derived classes may override
|
||||||
* will be called
|
* this method to implement a different strategy for resolving variables.
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
* @param name
|
||||||
* the name of the variable
|
* the name of the variable
|
||||||
|
|
Loading…
Reference in New Issue