mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 11:40:27 +00:00
Streamline WriterContext constructors. Make instance variables final
where possible.
This commit is contained in:
parent
6340d39ba7
commit
ea36399255
1 changed files with 11 additions and 10 deletions
|
@ -5,27 +5,27 @@ import java.io.Writer;
|
|||
import java.util.Arrays;
|
||||
|
||||
class WriterContext {
|
||||
private String key = "";
|
||||
private String currentTableIndent = "";
|
||||
private String currentFieldIndent = "";
|
||||
private String arrayKey = null;
|
||||
private boolean isArrayOfTable = false;
|
||||
private boolean empty = true;
|
||||
private final String key;
|
||||
private final String currentTableIndent;
|
||||
private final String currentFieldIndent;
|
||||
private final TomlWriter tomlWriter;
|
||||
private final Writer output;
|
||||
private final WriterIndentationPolicy indentationPolicy;
|
||||
|
||||
WriterContext(TomlWriter tomlWriter, Writer output) {
|
||||
this.tomlWriter = tomlWriter;
|
||||
this.output = output;
|
||||
this("", "", output, tomlWriter);
|
||||
}
|
||||
|
||||
WriterContext pushTable(String newKey) {
|
||||
String newIndent = "";
|
||||
if (!key.isEmpty()) {
|
||||
newIndent = growIndent(tomlWriter.getIndentationPolicy());
|
||||
newIndent = growIndent(indentationPolicy);
|
||||
}
|
||||
|
||||
String fullKey = key + (key.isEmpty() ? newKey : "." + newKey);
|
||||
String fullKey = key.isEmpty() ? newKey : key + "." + newKey;
|
||||
|
||||
WriterContext subContext = new WriterContext(fullKey, newIndent, output, tomlWriter);
|
||||
if (!empty) {
|
||||
|
@ -94,7 +94,7 @@ class WriterContext {
|
|||
}
|
||||
|
||||
void writeArrayDelimiterPadding() {
|
||||
for (int i = 0; i < tomlWriter.getIndentationPolicy().getArrayDelimiterPadding(); i++) {
|
||||
for (int i = 0; i < indentationPolicy.getArrayDelimiterPadding(); i++) {
|
||||
write(' ');
|
||||
}
|
||||
}
|
||||
|
@ -123,9 +123,10 @@ class WriterContext {
|
|||
|
||||
private WriterContext(String key, String tableIndent, Writer output, TomlWriter tomlWriter) {
|
||||
this.key = key;
|
||||
this.currentTableIndent = tableIndent;
|
||||
this.currentFieldIndent = tableIndent + fillStringWithSpaces(tomlWriter.getIndentationPolicy().getKeyValueIndent());
|
||||
this.output = output;
|
||||
this.indentationPolicy = tomlWriter.getIndentationPolicy();
|
||||
this.currentTableIndent = tableIndent;
|
||||
this.currentFieldIndent = tableIndent + fillStringWithSpaces(this.indentationPolicy.getKeyValueIndent());
|
||||
this.tomlWriter = tomlWriter;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue