Class Printer
java.lang.Object
org.glassfish.pfl.basic.algorithm.Printer
- Direct Known Subclasses:
CodegenPrinter
Manages printing of indented source code.
Line numbers start at 1 and increase by 1
every time nl() is called. Note that the
proper use of this class requires calling nl()
at the START of every line (thanks, Harold!),
which make indentation much easier to manage. For example,
an if statement can be printed as
nl().p( "if (expr) {" ).in() ;
nl().p( "stmt" ).out() ;
nl().p( "} else {" ).in() ;
nl().p( "stmt" ).out() ;
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringBuilder
static final int
private int
private int
private char[]
private char
private PrintStream
private int
-
Constructor Summary
ConstructorsConstructorDescriptionPrinter
(PrintStream ps) Printer
(PrintStream ps, int increment, char padChar) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
fill()
in()
int
indent()
private boolean
isPrintable
(char c) nl()
out()
printBuffer
(byte[] buffer) private Printer
rightJustify
(String str) rj
(int size) Right-Justify the next call to p so that the total number of characters is at least size.
-
Field Details
-
DEFAULT_INCREMENT
public static final int DEFAULT_INCREMENT- See Also:
-
ps
-
increment
private int increment -
padChar
private char padChar -
indent
private int indent -
pad
private char[] pad -
bld
-
rightJustificationSize
private int rightJustificationSize
-
-
Constructor Details
-
Printer
-
Printer
-
-
Method Details
-
rj
Right-Justify the next call to p so that the total number of characters is at least size. Use leading spaces if necessary to ensure this. -
rightJustify
-
p
-
p
-
p
-
in
-
out
-
indent
public int indent() -
fill
private void fill() -
nl
-
isPrintable
private boolean isPrintable(char c) -
printBuffer
-