All methods of Printer return this (for chaining).

This commit is contained in:
Evgeny Gerashchenko
2012-12-06 22:18:50 +04:00
parent 6c6abab033
commit d349bca42c
@@ -30,40 +30,58 @@ public class Printer {
this.out = out; this.out = out;
} }
public void println(Object... objects) { @NotNull
public Printer println(Object... objects) {
print(objects); print(objects);
printLineSeparator(); printLineSeparator();
return this;
} }
private void printLineSeparator() { private void printLineSeparator() {
out.append(System.getProperty("line.separator")); out.append(System.getProperty("line.separator"));
} }
public void print(Object... objects) { @NotNull
public Printer print(Object... objects) {
out.append(indent); out.append(indent);
printWithNoIndent(objects); printWithNoIndent(objects);
return this;
} }
public void printWithNoIndent(Object... objects) { @NotNull
public Printer printWithNoIndent(Object... objects) {
for (Object object : objects) { for (Object object : objects) {
out.append(object); out.append(object);
} }
return this;
} }
public void printlnWithNoIndent(Object... objects) { @NotNull
public Printer printlnWithNoIndent(Object... objects) {
printWithNoIndent(objects); printWithNoIndent(objects);
printLineSeparator(); printLineSeparator();
return this;
} }
public void pushIndent() { @NotNull
public Printer pushIndent() {
indent += INDENTATION_UNIT; indent += INDENTATION_UNIT;
return this;
} }
public void popIndent() { @NotNull
public Printer popIndent() {
if (indent.length() < INDENTATION_UNIT.length()) { if (indent.length() < INDENTATION_UNIT.length()) {
throw new IllegalStateException("No indentation to pop"); throw new IllegalStateException("No indentation to pop");
} }
indent = indent.substring(INDENTATION_UNIT.length()); indent = indent.substring(INDENTATION_UNIT.length());
return this;
} }
} }