|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object bpp.Format
This class simplifies the generation of java source code by the preprocessor.
Field Summary | |
static java.util.Map |
DEFAULTS
Default initial values for primitives. |
static java.util.Map |
PRIMITIVES
Maps wrapped name to primitive name. |
static java.util.Map |
WRAPPERS
Maps primitive names to wrapped names. |
Constructor Summary | |
Format()
|
Method Summary | |
static java.lang.String |
defval(java.lang.String type)
Get default value for any type (as a string). |
static void |
encodeTo(char x,
java.lang.StringBuffer to)
Format a single char into a StringBuffer as part of a char or String literal. |
static java.lang.String |
getPrimitive(java.lang.String type)
getPrimitive("Character")="char" and getPrimitive("java.lang.Integer")="int". |
static java.lang.String |
getWrapper(java.lang.String type)
getWrapper("char")="Character". |
static boolean |
isPrimitive(java.lang.String type)
|
static boolean |
isWrapper(java.lang.String type)
|
static java.lang.String |
join(char separator,
java.util.Collection c)
Join the toString() representations of some objects together. |
static java.lang.String |
join(char separator,
java.lang.Object[] list)
Join the toString() representations of some objects together. |
static java.lang.String |
join(java.lang.String separator,
java.util.Collection c)
Join the toString() representations of some objects together. |
static java.lang.String |
join(java.lang.String separator,
java.lang.Object[] list)
Join the toString() representations of some objects together. |
static java.lang.String |
left(java.lang.String s,
int w)
Left justify s in a width of w chars and a pad of ' '. |
static java.lang.String |
left(java.lang.String s,
int w,
char pad)
Left justify format in a width w using the given pad char. |
static java.lang.String |
literal(boolean x)
Format boolean as a java literal. |
static java.lang.String |
literal(java.lang.Boolean x)
Format Boolean as a java literal. |
static java.lang.String |
literal(byte x)
/** |
static java.lang.String |
literal(java.lang.Byte x)
Format Byte as a java literal. |
static java.lang.String |
literal(char x)
Format char as a java literal. |
static java.lang.String |
literal(java.lang.Character x)
Format char as a java literal. |
static java.lang.String |
literal(double x)
Format double as a java literal. |
static java.lang.String |
literal(java.lang.Double x)
Format Double as a java literal. |
static java.lang.String |
literal(float x)
Format float as a java literal. |
static java.lang.String |
literal(java.lang.Float x)
Format float as a java literal. |
static java.lang.String |
literal(int x)
Format int as a java literal. |
static java.lang.String |
literal(java.lang.Integer x)
Format Integer as a java literal. |
static java.lang.String |
literal(long x)
Format long as a java literal. |
static java.lang.String |
literal(java.lang.Long x)
Format Long as a java literal. |
static java.lang.String |
literal(short x)
Format short as a java literal. |
static java.lang.String |
literal(java.lang.Short x)
Format short as a java literal. |
static java.lang.String |
literal(java.lang.String s)
Format String as a java literal. |
static java.lang.String |
N(double n,
java.lang.String f)
Format number. |
static java.lang.String |
N(java.lang.Number n,
java.lang.String f)
Format wrapped number. |
static java.lang.String |
right(java.lang.String s,
int w)
Right justify s with blanks for a pad character. |
static java.lang.String |
right(java.lang.String s,
int w,
char pad)
Right justify s in a width w with given pad char. |
static java.lang.String[] |
split(char separator,
java.lang.String joined,
boolean trim)
Split a string up. |
static java.lang.String[] |
split(java.lang.String separator,
java.lang.String joined,
boolean trim)
Split a string up. |
static java.lang.String |
typename(java.lang.Class c)
Get correct name of a class |
static java.lang.String |
typeof(boolean x)
Simple "typeof" operator for boolean primitives. |
static java.lang.String |
typeof(byte x)
Simple "typeof" operator for byte primitives. |
static java.lang.String |
typeof(char x)
Simple "typeof" operator for char primitives. |
static java.lang.String |
typeof(double x)
Simple "typeof" operator for double primitives. |
static java.lang.String |
typeof(float x)
Simple "typeof" operator for float primitives. |
static java.lang.String |
typeof(int x)
Simple "typeof" operator for int primitives. |
static java.lang.String |
typeof(long x)
Simple "typeof" operator for long primitives. |
static java.lang.String |
typeof(java.lang.Object o)
Simple "typeof" operator for Objects |
static java.lang.String |
typeof(short x)
Simple "typeof" operator for short primitives. |
static java.lang.String |
unwrap(java.lang.String type,
java.lang.String exp)
Selectively unwrap primitive types. |
static java.lang.String |
wrap(java.lang.String type,
java.lang.String exp)
Selectively wrap primitive types. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.util.Map WRAPPERS
public static final java.util.Map PRIMITIVES
public static final java.util.Map DEFAULTS
Default initial values for primitives. It goes from the name of the primitive to a wrapped version of the default value for that primitive type. The specific entries are:
key | value |
"boolean" | Boolean(false) |
"byte" | Byte(0) |
"char" | Character('\0') |
"short" | Short(0) |
"int" | Integer(0) |
"long" | Long(0L) |
"float" | Float(0E0f) |
"double" | Double(0E0) |
Constructor Detail |
public Format()
Method Detail |
public static boolean isPrimitive(java.lang.String type)
public static boolean isWrapper(java.lang.String type)
public static java.lang.String getWrapper(java.lang.String type)
public static java.lang.String getPrimitive(java.lang.String type)
public static java.lang.String wrap(java.lang.String type, java.lang.String exp)
Selectively wrap primitive types.
For example, wrap("String","x") will produce "x", while wrap("boolean","x") will produce "new Boolean(x)". The type name must be the primitive type.
public static java.lang.String unwrap(java.lang.String type, java.lang.String exp)
Selectively unwrap primitive types.
For example, unwrap("String","x") will produce "x", while unwrap("boolean","x") will produce "x.booleanValue()". The type name must be the primitive type.
public static java.lang.String defval(java.lang.String type)
Get default value for any type (as a string).
For example, defval("String") will produce "((String)null)". All non-primitive types, including wrapper types, are treated in this way. The primitive types produce the following values:
primitive | result |
"boolean" | "false" |
"byte" | "((byte) 0)" |
"char" | "'\\0'" |
"short" | "((short) 0)" |
"int" | "0" |
"long" | "0L" |
"float" | "0f" |
"double" | "0.0" |
public static java.lang.String typename(java.lang.Class c)
Get correct name of a class
This is better than using the java.lang.Class.getName directly, because that method returns strange names for array types.
public static java.lang.String typeof(java.lang.Object o)
Simple "typeof" operator for Objects
Returns typename(o.getClass())
public static java.lang.String typeof(boolean x)
Simple "typeof" operator for boolean primitives. Returns "boolean".
public static java.lang.String typeof(byte x)
Simple "typeof" operator for byte primitives. Returns "byte".
public static java.lang.String typeof(char x)
Simple "typeof" operator for char primitives. Returns "char".
public static java.lang.String typeof(short x)
Simple "typeof" operator for short primitives. Returns "short".
public static java.lang.String typeof(int x)
Simple "typeof" operator for int primitives. Returns "int".
public static java.lang.String typeof(long x)
Simple "typeof" operator for long primitives. Returns "long".
public static java.lang.String typeof(float x)
Simple "typeof" operator for float primitives. Returns "float".
public static java.lang.String typeof(double x)
Simple "typeof" operator for double primitives. Returns "double".
public static java.lang.String join(char separator, java.util.Collection c)
public static java.lang.String join(java.lang.String separator, java.util.Collection c)
public static java.lang.String join(char separator, java.lang.Object[] list)
public static java.lang.String join(java.lang.String separator, java.lang.Object[] list)
public static java.lang.String[] split(char separator, java.lang.String joined, boolean trim)
Split a string up.
After splitting by the given separator, each entry is trimmed (with String.trim()) if the trim argument is true. For example:
split(',',",1, 3, 4",false)={"","1"," 3"," 4"}while
split(',',",1, 3, 4",true)={"","1","3","4"}
public static java.lang.String[] split(java.lang.String separator, java.lang.String joined, boolean trim)
Split a string up.
Just like the char-separator version of split.
public static java.lang.String left(java.lang.String s, int w, char pad)
Left justify format in a width w using the given pad char.
If s is longer than abs(w), it is not trimmed. If w is negative, s is right justified instead.
public static java.lang.String left(java.lang.String s, int w)
public static java.lang.String right(java.lang.String s, int w, char pad)
public static java.lang.String right(java.lang.String s, int w)
public static java.lang.String N(java.lang.Number n, java.lang.String f)
Format wrapped number.
f is the argument to the java.text.DecimalFormat used to format the number. See that class for all that can be done
public static java.lang.String N(double n, java.lang.String f)
Format number.
f is the argument to the java.text.DecimalFormat used to format the number. See that class for all that can be done
public static java.lang.String literal(boolean x)
Format boolean as a java literal.
For example, literal(true)="true".
public static java.lang.String literal(java.lang.Boolean x)
Format Boolean as a java literal.
For example, literal(new Boolean(true))="true".
public static java.lang.String literal(byte x)
Format byte as a java literal.
For example, literal((byte) 3)="((byte) 3)".
public static java.lang.String literal(java.lang.Byte x)
Format Byte as a java literal.
For example, literal(new Byte(3))="((byte) 3)".
public static java.lang.String literal(short x)
Format short as a java literal.
For example, literal((short) 3)="((short) 3)".
public static java.lang.String literal(java.lang.Short x)
Format short as a java literal.
For example, literal(new Short(3))="((short) 3)".
public static java.lang.String literal(int x)
Format int as a java literal.
For example, literal(3)="3".
public static java.lang.String literal(java.lang.Integer x)
Format Integer as a java literal.
For example, literal(new Integer(3))="3".
public static java.lang.String literal(long x)
Format long as a java literal.
For example, literal(3L)="3L".
public static java.lang.String literal(java.lang.Long x)
Format Long as a java literal.
For example, literal(new Long(3L))="3L".
public static java.lang.String literal(float x)
Format float as a java literal.
For example, literal(3.0f))="3.0f".
public static java.lang.String literal(java.lang.Float x)
Format float as a java literal.
For example, literal(new Float(3.0f)))="3.0f".
public static java.lang.String literal(double x)
Format double as a java literal.
For example, literal(3.0))="3.0".
public static java.lang.String literal(java.lang.Double x)
Format Double as a java literal.
For example, literal(new Double(3.0)))="3.0".
public static void encodeTo(char x, java.lang.StringBuffer to)
public static java.lang.String literal(char x)
Format char as a java literal.
For example, literal('\'')="\'\\'\'".
public static java.lang.String literal(java.lang.Character x)
Format char as a java literal.
For example, literal(new Character('\''))="\'\\\'\'".
public static java.lang.String literal(java.lang.String s)
Format String as a java literal.
For example, literal("\tPress \'return\'\n")="\"\\tPress \\\'return\\\'\\n\"".
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |