Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.util

public final Class TwoColumnOutput

extends Object
Class Inheritance
Imports
java.io.*

Class that takes a combined output destination and provides two output writers, one of which ends up writing to the left column and one which goes on the right.

Field Summary

Modifier and TypeField and Description
private final StringBuffer
leftBuf

non-null; pending left column output

private final IndentingWriter
leftColumn

non-null; left column writer

private final int
leftWidth

> 0; the left column width

private final Writer
out

non-null; underlying writer for final output

private final StringBuffer
rightBuf

non-null; pending right column output

private final IndentingWriter
rightColumn

non-null; right column writer

Constructor Summary

AccessConstructor and Description
public
TwoColumnOutput(Writer
non-null; writer to send final output to
out
,
int
> 0; width of the left column, in characters
leftWidth
,
int
> 0; width of the right column, in characters
rightWidth
,
String
non-null; spacer string to sit between the two columns
spacer
)

Constructs an instance.

public
TwoColumnOutput(OutputStream
non-null; stream to send final output to
out
,
int
>= 1; width of the left column, in characters
leftWidth
,
int
>= 1; width of the right column, in characters
rightWidth
,
String
non-null; spacer string to sit between the two columns
spacer
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
private static void
appendNewlineIfNecessary(StringBuffer
non-null; the buffer in question
buf
,
Writer
non-null; the writer to use
out
)

Appends a newline to the given buffer via the given writer, but only if it isn't empty and doesn't already end with one.

public void
flush()

Flushes the output.

private void
flushLeft()

Flushes the left column buffer, printing it and clearing the buffer.

private void
flushRight()

Flushes the right column buffer, printing it and clearing the buffer.

public Writer

Returns:

non-null; the left column writer
getLeft
()

Gets the writer to use to write to the left column.

public Writer

Returns:

non-null; the right column writer
getRight
()

Gets the writer to use to write to the right column.

private void
outputFullLines()

Outputs to the final destination as many full line pairs as there are in the pending output, removing those lines from their respective buffers.

public static String

Returns:

non-null; an appropriately-formatted string
toString
(String
non-null; first string
s1
,
int
> 0; width of the first column
width1
,
String
non-null; spacer string
spacer
,
String
non-null; second string
s2
,
int
> 0; width of the second column
width2
)

Turns the given two strings (with widths) and spacer into a formatted two-column string.

private static void
writeSpaces(Writer
non-null; where to write
out
,
int
>= 0; the number of spaces to write
amt
)

Writes the given number of spaces to the given writer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

leftBufback to summary
private final StringBuffer leftBuf

non-null; pending left column output

leftColumnback to summary
private final IndentingWriter leftColumn

non-null; left column writer

leftWidthback to summary
private final int leftWidth

> 0; the left column width

outback to summary
private final Writer out

non-null; underlying writer for final output

rightBufback to summary
private final StringBuffer rightBuf

non-null; pending right column output

rightColumnback to summary
private final IndentingWriter rightColumn

non-null; right column writer

Constructor Detail

TwoColumnOutputback to summary
public TwoColumnOutput(Writer out, int leftWidth, int rightWidth, String spacer)

Constructs an instance.

Parameters
out:Writer

non-null; writer to send final output to

leftWidth:int

> 0; width of the left column, in characters

rightWidth:int

> 0; width of the right column, in characters

spacer:String

non-null; spacer string to sit between the two columns

TwoColumnOutputback to summary
public TwoColumnOutput(OutputStream out, int leftWidth, int rightWidth, String spacer)

Constructs an instance.

Parameters
out:OutputStream

non-null; stream to send final output to

leftWidth:int

>= 1; width of the left column, in characters

rightWidth:int

>= 1; width of the right column, in characters

spacer:String

non-null; spacer string to sit between the two columns

Method Detail

appendNewlineIfNecessaryback to summary
private static void appendNewlineIfNecessary(StringBuffer buf, Writer out) throws IOException

Appends a newline to the given buffer via the given writer, but only if it isn't empty and doesn't already end with one.

Parameters
buf:StringBuffer

non-null; the buffer in question

out:Writer

non-null; the writer to use

flushback to summary
public void flush()

Flushes the output. If there are more lines of pending output in one column, then the other column will get filled with blank lines.

flushLeftback to summary
private void flushLeft() throws IOException

Flushes the left column buffer, printing it and clearing the buffer. If the buffer is already empty, this does nothing.

flushRightback to summary
private void flushRight() throws IOException

Flushes the right column buffer, printing it and clearing the buffer. If the buffer is already empty, this does nothing.

getLeftback to summary
public Writer getLeft()

Gets the writer to use to write to the left column.

Returns:Writer

non-null; the left column writer

getRightback to summary
public Writer getRight()

Gets the writer to use to write to the right column.

Returns:Writer

non-null; the right column writer

outputFullLinesback to summary
private void outputFullLines() throws IOException

Outputs to the final destination as many full line pairs as there are in the pending output, removing those lines from their respective buffers. This method terminates when at least one of the two column buffers is empty.

toStringback to summary
public static String toString(String s1, int width1, String spacer, String s2, int width2)

Turns the given two strings (with widths) and spacer into a formatted two-column string.

Parameters
s1:String

non-null; first string

width1:int

> 0; width of the first column

spacer:String

non-null; spacer string

s2:String

non-null; second string

width2:int

> 0; width of the second column

Returns:String

non-null; an appropriately-formatted string

writeSpacesback to summary
private static void writeSpaces(Writer out, int amt) throws IOException

Writes the given number of spaces to the given writer.

Parameters
out:Writer

non-null; where to write

amt:int

>= 0; the number of spaces to write