|
sharkysoft.com | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sharkysoft.printf.PrintfData
Syntactic sugar for variable argument lists.
Details: PrintfData
offers an alternative method for
defining the data vector in Printf For Java. If you don't like the idea of
wrapping primitive types in their object counterparts and referencing them in
an Object
array, then perhaps you'll like the syntactic sugar
afforded by this helper class. Use of this class is entirely
optional.
To build a printf data vector using this class, first instantiate an
instance, and then chain together calls to its overloaded add
method, furnishing the printf input data one element at a time. (Each
add
call returns the same instance of this class, to facilitate
chaining.) After the last element has been added, the result can then be
supplied directly to most Printf
methods.
Example: The two
Printf
in this code are equivalent:String format = "My dog %s is %d years old."; String name = "Spot"; int age = 3; // With Object array: Printf.out(format, new Object[]{name, new Integer(age)}); // With PrintfData: Printf.out(format, new PrintfData().add(name).add(age));
In the first Printf
call above, an Object
array is
explicitely created, and the primitive type is explicitely wrapped. In the
second call, no Object
array is created, and no primitive type
is wrapped. Printf
accepts the data vector returned by the last
add
call.
Behind the scenes, Printf
simply converts the
PrintfData
to an Object[]
. Therefore, straight
Object
arrays are always more efficient. The choice is
yours.
Constructor Summary | |
PrintfData()
Initializes empty vector with undetermined length. |
|
PrintfData(int inLength)
Initializes empty vector with final length. |
Method Summary | |
PrintfData |
add(boolean izB)
Appends boolean data. |
PrintfData |
add(byte ibB)
Appends byte data. |
PrintfData |
add(char icC)
Appends char data. |
PrintfData |
add(double idD)
Appends double data. |
PrintfData |
add(float ifF)
Appends float data. |
PrintfData |
add(int inI)
Appends int data. |
PrintfData |
add(long ilL)
Appends long data. |
PrintfData |
add(java.lang.Object ipO)
Appends Object data. |
PrintfData |
add(short iwS)
Appends short data. |
java.lang.Object[] |
done()
Converts to Object array. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PrintfData()
Details: This constructor initializes an empty data vector. Use this constructor when the final length of the data vector is unknown at compile time.
public PrintfData(int inLength)
Details: This constructor initializes an empty data vector whose final length has already been determined. Use this constructor whenever possible to create more efficient code. If the predicted final length of this data vector ultimately differs from the value passed into this constructor, no harm is done.
inLength
- the estimated lengthMethod Detail |
public PrintfData add(java.lang.Object ipO)
Details: Use this method to append any type of object, including
String
s, to this data vector. The argument will not be
wrapped.
ipO
- the object
public PrintfData add(char icC)
Details: Use this method to append a char
to this
data vector. The argument will be wrapped in a Character
.
icC
- the char
public PrintfData add(short iwS)
Details: Use this method to append a short
to this
data vector. The argument will be wrapped in a Short
.
iwS
- the short
public PrintfData add(int inI)
Details: Use this method to append an int
to this
data vector. The argument will be wrapped in a Integer
.
inI
- the int
public PrintfData add(long ilL)
Details: Use this method to append a long
to this
data vector. The argument will be wrapped in a Long
.
ilL
- the long
public PrintfData add(float ifF)
Details: Use this method to append a float
to this
data vector. The argument will be wrapped in a Float
.
ifF
- the float
public PrintfData add(double idD)
Details: Use this method to append a double
to this
data vector. The argument will be wrapped in a Double
.
idD
- the double
public PrintfData add(byte ibB)
Details: Use this method to append a byte
to this
data vector. The argument will be wrapped in a Byte
.
ibB
- the byte
public PrintfData add(boolean izB)
Details: Use this method to append a boolean
to this
data vector. The argument will be wrapped in a Boolean
.
izB
- the boolean
public java.lang.Object[] done()
Details: Although it is not necessary in most cases, this method
can be used to convert this data vector into an Object
array.
|
sharkysoft.com | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1997-2004 Sharkysoft (sharkysoft.com). All rights reserved.