edu.ull.cgunay.utils
Class StringTask

java.lang.Object
  |
  +--edu.ull.cgunay.utils.StringTask
All Implemented Interfaces:
Serializable, Task, TaskWithReturn

public class StringTask
extends Object
implements TaskWithReturn

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 $

Version:
$Revision: 1.8 $ for this file.
Author:
Cengiz Gunay
See Also:
Serialized Form

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

retval

protected String retval
Variable holding the String accumulated during iteration.


closing

protected String closing
A piece of string to be added before the accumulated string retval is returned. Empty string by default.


separator

protected String separator
String to be put between elements by default.


first

protected boolean first
Flag to indicate start of iteration.

Constructor Detail

StringTask

public StringTask()
Dummy constructor.


StringTask

public StringTask(String initialRetval)
Initialize the accumulated String to the argument.

Parameters:
initialRetval - a String value

StringTask

public StringTask(String initialRetval,
                  String closingAddition)
Wrap the accumulated 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().

Parameters:
initialRetval - assigned to retval
closingAddition - assigned to closing
See Also:
closing, getValue(), getString(java.util.Collection)

StringTask

public StringTask(String initialRetval,
                  String closingAddition,
                  String separator)
Also accepts a default separator string to put between elements.

Parameters:
initialRetval - a String value
closingAddition - a String value
separator - a String value
See Also:
StringTask(String,String)
Method Detail

getString

public String getString(Collection list)
Iterates on the list and returns the accumulated String. Gracefully trims the items if a BreakOutOfIterationException is encountered during iteration.

Returns:
a String value
See Also:
getValue(), UninterruptedIteration

getString

public String getString(Object[] array)
Convenience method, see other getStrings.

Parameters:
array - an Object[] value
Returns:
a String value
See Also:
getString(Collection)

getValue

public Object getValue()
Return the accumulated String appended by the closing.

Specified by:
getValue in interface TaskWithReturn
Returns:
See Also:
closing

job

public void job(Object o)
Job to be done on each Collection item o. By default adds the String representation of o to the accumulated String.

Specified by:
job in interface Task
Parameters:
o - the token of this iteration step
See Also:
Iteration.loop()