|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--edu.ull.cgunay.utils.StringTask
Iteration task that accumulates a String value. Constructors allow
optionally starting and ending Strings to wrap the
String created by iterating the Collection
given to the getString() method.
Example to display contents of a Vector holding
double values in parenthesis:
String inParens = new StringTask("(", ")") {
public void job(Object o) {
super.job(o + ", "); // Add the string representation of object and a comma
}
}.getString(doubleVector); // Iterate on doubleVector
Created: Tue Apr 9 13:40:54 2002
Modified: $Date: 2002/11/14 05:00:10 $
| Field Summary | |
protected String |
closing
A piece of string to be added before the accumulated string retval is returned. |
protected boolean |
first
Flag to indicate start of iteration. |
protected String |
retval
Variable holding the String accumulated
during iteration. |
protected String |
separator
String to be put between elements by default. |
| Constructor Summary | |
StringTask()
Dummy constructor. |
|
StringTask(String initialRetval)
Initialize the accumulated String to the argument. |
|
StringTask(String initialRetval,
String closingAddition)
Wrap the accumulated String with an initial prefix and a final appendix.
|
|
StringTask(String initialRetval,
String closingAddition,
String separator)
Also accepts a default separator string to put between elements. |
|
| Method Summary | |
String |
getString(Collection list)
Iterates on the list and returns the accumulated String.
|
String |
getString(Object[] array)
Convenience method, see other getStrings. |
Object |
getValue()
Return the accumulated String appended by the closing. |
void |
job(Object o)
Job to be done on each Collection item o.
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected String retval
String accumulated
during iteration.
protected String closing
retval is returned. Empty string by default.
protected String separator
protected boolean first
| Constructor Detail |
public StringTask()
public StringTask(String initialRetval)
String to the argument.
initialRetval - a String value
public StringTask(String initialRetval,
String closingAddition)
String with an initial prefix and a final appendix.
Initialize retval to initialRetval and
closing to closingAddition. The latter is added
to retval before being returned from
getValue() or getString().
initialRetval - assigned to retvalclosingAddition - assigned to closingclosing,
getValue(),
getString(java.util.Collection)
public StringTask(String initialRetval,
String closingAddition,
String separator)
initialRetval - a String valueclosingAddition - a String valueseparator - a String valueStringTask(String,String)| Method Detail |
public String getString(Collection list)
list and returns the accumulated String.
Gracefully trims the items if a BreakOutOfIterationException is encountered
during iteration.
String valuegetValue(),
UninterruptedIterationpublic String getString(Object[] array)
getStrings.
array - an Object[] value
String valuegetString(Collection)public Object getValue()
String appended by the closing.
getValue in interface TaskWithReturnclosingpublic void job(Object o)
Collection item o.
By default adds the String representation of o
to the accumulated String.
job in interface Tasko - the token of this iteration stepIteration.loop()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||