lp.struct.util
Class LpPrinter<W extends Writer>

java.lang.Object
  extended by java.io.Writer
      extended by lp.struct.util.LpPrinter<W>
All Implemented Interfaces:
Closeable, Flushable, Appendable, LpStructureUnitVisitor
Direct Known Subclasses:
LpEncoder, LpPrettyPrinter

public abstract class LpPrinter<W extends Writer>
extends Writer
implements LpStructureUnitVisitor

A base class for various printers of object representations of logic programs. The implementing classes implement the methods from LpStructureUnitVisitor to customize the textual representation of LpStructureUnits. The class as a regular Writer with the added possibility to write/append a textual representation of a LpStructureUnit (see the append(LpStructureUnit) and write(LpStructureUnit) methods).

Version:
1.0.0
Author:
Martin Slota
See Also:
LpStructureUnitVisitor

Field Summary
private  W out
          The underlying Writer into which the class writes.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
protected LpPrinter(W out)
          Creates a new instance that writes everything into W.
 
Method Summary
 LpPrinter append(char c)
          Appends a single character to the underlying Writer.
 LpPrinter append(CharSequence csq)
          Appends a character sequence to the underlying Writer.
 LpPrinter append(CharSequence csq, int start, int end)
          Appends a portion of a character sequence to the underlying Writer.
 LpPrinter append(LpStructureUnit unit)
          Appends a textual representation of unit to this LpPrinter.
 void close()
          Closes the underlying Writer.
 void flush()
          Flushes the underlying Writer.
 W getOut()
          Returns the underlying Writer into which this writes the output.
 void setOut(W out)
          Sets the underlying Writer into which this writes the output.
 void write(char[] cbuf)
          Writes a character array to the underlying Writer.
 void write(char[] cbuf, int off, int len)
          Writes a portion of a character array to the underlying Writer instance.
 void write(int c)
          Writes a single character to the underlying Writer.
 void write(LpStructureUnit unit)
          Writes a textual representation of unit to this LpPrinter.
 void write(String str)
          Writes a string to the underlying Writer.
 void write(String str, int off, int len)
          Writes a string to the underlying Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface lp.struct.LpStructureUnitVisitor
visit, visit, visit, visit, visit, visit, visit, visit
 

Field Detail

out

private W extends Writer out
The underlying Writer into which the class writes.

Constructor Detail

LpPrinter

protected LpPrinter(W out)
Creates a new instance that writes everything into W.

Parameters:
out - the Writer into which this instance will write
Method Detail

getOut

public W getOut()
Returns the underlying Writer into which this writes the output.

Returns:
the underlying Writer into which this writes the output
See Also:
setOut(Writer)

setOut

public void setOut(W out)
Sets the underlying Writer into which this writes the output.

Parameters:
out - the new Writer into which this LpPrinter writes its output
See Also:
getOut()

append

public LpPrinter append(LpStructureUnit unit)
Appends a textual representation of unit to this LpPrinter. The string is constructed in the #visit() methods. If unit is null, the string "null" is appended.

Parameters:
unit - the LpStructureUnit that should be represented as a string and appended to the underlying Writer
Returns:
a reference to this object after appending
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

write

public void write(LpStructureUnit unit)
Writes a textual representation of unit to this LpPrinter. The string is constructed in the #visit() methods.

Parameters:
unit - the LpStructureUnit that should be represented as a string and appended to the underlying Writer
Throws:
IllegalArgumentException - if unit is null
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

write

public void write(int c)
Writes a single character to the underlying Writer.

Overrides:
write in class Writer
Parameters:
c - int specifying a character to be written
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

write

public void write(char[] cbuf)
Writes a character array to the underlying Writer.

Overrides:
write in class Writer
Parameters:
cbuf - array of characters to be written
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

write

public void write(char[] cbuf,
                  int off,
                  int len)
Writes a portion of a character array to the underlying Writer instance.

Specified by:
write in class Writer
Parameters:
cbuf - array of characters to be written
off - offset from which to start writing characters
len - number of characters to write
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

write

public void write(String str)
Writes a string to the underlying Writer.

Overrides:
write in class Writer
Parameters:
str - string to be written
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

write

public void write(String str,
                  int off,
                  int len)
Writes a string to the underlying Writer.

Overrides:
write in class Writer
Parameters:
str - string to be written
off - offset from which to start writing characters
len - number of characters to write
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

append

public LpPrinter append(CharSequence csq)
Appends a character sequence to the underlying Writer.

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Parameters:
csq - character sequence to be written
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

append

public LpPrinter append(CharSequence csq,
                        int start,
                        int end)
Appends a portion of a character sequence to the underlying Writer.

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Parameters:
csq - character sequence to be written
start - the index of the first character in the subsequence
end - the index of the character following the last character in the subsequence
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

append

public LpPrinter append(char c)
Appends a single character to the underlying Writer.

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Parameters:
c - character to be written
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while writing to the underlying Writer

flush

public void flush()
Flushes the underlying Writer.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while flushing the underlying Writer instance

close

public void close()
Closes the underlying Writer.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O exception occurs while closing the underlying Writer instance