com.jstatcom.util
Class FArg

java.lang.Object
  extended by com.jstatcom.util.FArg

public final class FArg
extends java.lang.Object

Since Java 1.5 one should rather use Formatter.format instead of this class. However, this one is a bit more tolerant against wrongly specified input.

Formatting argument class that originally served as an adapter to PrintfFormat. whith a more convenient and shorter syntax.

Usage note:
One should use the static method sprintf and construct a new FArg instance to hold parameters. Further arguments can be appended very C-like with a varargs argument, for example:

FArg.sprintf("%-13s %- 8.4f", "statistic:", 2.345)

Author:
Markus Kraetzig
See Also:
PrintfFormat

Constructor Summary
FArg(double arg)
          FArg double constructor.
FArg(int arg)
          FArg int constructor.
FArg(java.lang.Object arg)
          FArg Object constructor.
 
Method Summary
 FArg add(double arg)
          Adds a new double argument to be formatted.
 FArg add(int arg)
          Adds a new int argument to be formatted.
 FArg add(java.lang.Object arg)
          Adds a new Object argument to be formatted.
 java.lang.Object[] getArgs()
          Gets the stored arguments as an object array that can be used with PrintfFormat.sprintf.
static java.lang.String sprintf(java.lang.String formatString, FArg args)
          A wrapper method for the PrintfFormat.sprintf method.
static java.lang.String sprintf(java.lang.String formatString, java.lang.Object... args)
          A wrapper method for the PrintfFormat.sprintf method with a convenient vararg argument.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FArg

public FArg(double arg)
FArg double constructor.

Parameters:
arg - double to be formatted

FArg

public FArg(int arg)
FArg int constructor.

Parameters:
arg - int to be formatted

FArg

public FArg(java.lang.Object arg)
FArg Object constructor.

Parameters:
arg - object to be formatted
Method Detail

add

public FArg add(double arg)
Adds a new double argument to be formatted.

Parameters:
arg - the element to be formatted
Returns:
this after adding arg

add

public FArg add(int arg)
Adds a new int argument to be formatted.

Parameters:
arg - the element to be formatted
Returns:
this after adding arg

add

public FArg add(java.lang.Object arg)
Adds a new Object argument to be formatted.

Parameters:
arg - the element to be formatted
Returns:
this after adding arg

getArgs

public java.lang.Object[] getArgs()
Gets the stored arguments as an object array that can be used with PrintfFormat.sprintf.

Returns:
the object array

sprintf

public static java.lang.String sprintf(java.lang.String formatString,
                                       FArg args)
A wrapper method for the PrintfFormat.sprintf method. It is slightly shorter and that resembles the syntax used by the com.braju toolset (by exchanging Format and Parameters with FArg).

Parameters:
formatString - the string for formatting args, see the PrinfFormat documentation
args - the object containing the arguments in the correct order according to the formatting string
Returns:
the formatted string
Throws:
java.lang.IllegalArgumentException - if (formatString == null || args == null)
See Also:
PrintfFormat

sprintf

public static java.lang.String sprintf(java.lang.String formatString,
                                       java.lang.Object... args)
A wrapper method for the PrintfFormat.sprintf method with a convenient vararg argument.

Parameters:
formatString - the string for formatting args, see the PrinfFormat documentation
args - strings or numbers to be formated
Returns:
the formatted string
Throws:
java.lang.IllegalArgumentException - if (formatString == null)
See Also:
PrintfFormat