minor: allow specifying indentation unit in Printer
This commit is contained in:
committed by
Dmitry Petrov
parent
1600037625
commit
520a3133bc
@@ -23,13 +23,14 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Printer {
|
||||
private static final String INDENTATION_UNIT = " ";
|
||||
private static final String DEFAULT_INDENTATION_UNIT = " ";
|
||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
|
||||
protected final Appendable out;
|
||||
private final int maxBlankLines;
|
||||
|
||||
private String indent = "";
|
||||
private final String indentUnit;
|
||||
private int blankLineCountIncludingCurrent = 0;
|
||||
private boolean withholdIndentOnce = false;
|
||||
|
||||
@@ -37,9 +38,18 @@ public class Printer {
|
||||
this(out, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public Printer(@NotNull Appendable out, @NotNull String indentUnit) {
|
||||
this(out, Integer.MAX_VALUE, indentUnit);
|
||||
}
|
||||
|
||||
public Printer(@NotNull Appendable out, int maxBlankLines) {
|
||||
this(out, maxBlankLines, DEFAULT_INDENTATION_UNIT);
|
||||
}
|
||||
|
||||
public Printer(@NotNull Appendable out, int maxBlankLines, @NotNull String indentUnit) {
|
||||
this.out = out;
|
||||
this.maxBlankLines = maxBlankLines;
|
||||
this.indentUnit = indentUnit;
|
||||
}
|
||||
|
||||
private void append(Object o) {
|
||||
@@ -109,18 +119,18 @@ public class Printer {
|
||||
|
||||
@NotNull
|
||||
public Printer pushIndent() {
|
||||
indent += INDENTATION_UNIT;
|
||||
indent += indentUnit;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Printer popIndent() {
|
||||
if (indent.length() < INDENTATION_UNIT.length()) {
|
||||
if (indent.length() < indentUnit.length()) {
|
||||
throw new IllegalStateException("No indentation to pop");
|
||||
}
|
||||
|
||||
indent = indent.substring(INDENTATION_UNIT.length());
|
||||
indent = indent.substring(indentUnit.length());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user