Class Printer
- java.lang.Object
-
- org.glassfish.pfl.basic.algorithm.Printer
-
- Direct Known Subclasses:
CodegenPrinter
public class Printer extends java.lang.ObjectManages 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
Fields Modifier and Type Field Description private java.lang.StringBuilderbldstatic intDEFAULT_INCREMENTprivate intincrementprivate intindentprivate char[]padprivate charpadCharprivate java.io.PrintStreampsprivate intrightJustificationSize
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidfill()Printerin()intindent()private booleanisPrintable(char c)Printernl()Printerout()Printerp(java.lang.Object obj)Printerp(java.lang.Object... args)Printerp(java.lang.String str)PrinterprintBuffer(byte[] buffer)private PrinterrightJustify(java.lang.String str)Printerrj(int size)Right-Justify the next call to p so that the total number of characters is at least size.
-
-
-
Field Detail
-
DEFAULT_INCREMENT
public static final int DEFAULT_INCREMENT
- See Also:
- Constant Field Values
-
ps
private java.io.PrintStream ps
-
increment
private int increment
-
padChar
private char padChar
-
indent
private int indent
-
pad
private char[] pad
-
bld
private java.lang.StringBuilder bld
-
rightJustificationSize
private int rightJustificationSize
-
-
Method Detail
-
rj
public Printer rj(int size)
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
private Printer rightJustify(java.lang.String str)
-
p
public Printer p(java.lang.String str)
-
p
public Printer p(java.lang.Object... args)
-
p
public Printer p(java.lang.Object obj)
-
in
public Printer in()
-
out
public Printer out()
-
indent
public int indent()
-
fill
private void fill()
-
nl
public Printer nl()
-
isPrintable
private boolean isPrintable(char c)
-
printBuffer
public Printer printBuffer(byte[] buffer)
-
-