Top Description Fields Constructors Methods
org.glassfish.pfl.basic.algorithm

public Class Printer

extends Object
Class Inheritance
Imports
java.io.PrintStream

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

Modifier and TypeField and Description
private StringBuilder
public static final int
private int
private int
private char[]
private char
private PrintStream
private int

Constructor Summary

AccessConstructor and Description
public
public
Printer(PrintStream ps, int increment, char padChar)

Method Summary

Modifier and TypeMethod and Description
private void
fill()

public Printer
in()

public int
private boolean
isPrintable(char c)

public Printer
nl()

public Printer
out()

public Printer
p(String str)

public Printer
p(Object... args)

public Printer
p(Object obj)

public Printer
printBuffer(byte[] buffer)

private Printer
public Printer
rj(int size)

Right-Justify the next call to p so that the total number of characters is at least size.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bldback to summary
private StringBuilder bld
DEFAULT_INCREMENTback to summary
public static final int DEFAULT_INCREMENT
incrementback to summary
private int increment
indentback to summary
private int indent
padback to summary
private char[] pad
padCharback to summary
private char padChar
psback to summary
private PrintStream ps
rightJustificationSizeback to summary
private int rightJustificationSize

Constructor Detail

Printerback to summary
public Printer(PrintStream ps)
Printerback to summary
public Printer(PrintStream ps, int increment, char padChar)

Method Detail

fillback to summary
private void fill()
inback to summary
public Printer in()
indentback to summary
public int indent()
isPrintableback to summary
private boolean isPrintable(char c)
nlback to summary
public Printer nl()
outback to summary
public Printer out()
pback to summary
public Printer p(String str)
pback to summary
public Printer p(Object... args)
pback to summary
public Printer p(Object obj)
printBufferback to summary
public Printer printBuffer(byte[] buffer)
rightJustifyback to summary
private Printer rightJustify(String str)
rjback to summary
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.