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;
|
import java.util.Arrays;
|
||||||
|
|
||||||
class WriterContext {
|
class WriterContext {
|
||||||
private String key = "";
|
|
||||||
private String currentTableIndent = "";
|
|
||||||
private String currentFieldIndent = "";
|
|
||||||
private String arrayKey = null;
|
private String arrayKey = null;
|
||||||
private boolean isArrayOfTable = false;
|
private boolean isArrayOfTable = false;
|
||||||
private boolean empty = true;
|
private boolean empty = true;
|
||||||
|
private final String key;
|
||||||
|
private final String currentTableIndent;
|
||||||
|
private final String currentFieldIndent;
|
||||||
private final TomlWriter tomlWriter;
|
private final TomlWriter tomlWriter;
|
||||||
private final Writer output;
|
private final Writer output;
|
||||||
|
private final WriterIndentationPolicy indentationPolicy;
|
||||||
|
|
||||||
WriterContext(TomlWriter tomlWriter, Writer output) {
|
WriterContext(TomlWriter tomlWriter, Writer output) {
|
||||||
this.tomlWriter = tomlWriter;
|
this("", "", output, tomlWriter);
|
||||||
this.output = output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WriterContext pushTable(String newKey) {
|
WriterContext pushTable(String newKey) {
|
||||||
String newIndent = "";
|
String newIndent = "";
|
||||||
if (!key.isEmpty()) {
|
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);
|
WriterContext subContext = new WriterContext(fullKey, newIndent, output, tomlWriter);
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
|
@ -94,7 +94,7 @@ class WriterContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeArrayDelimiterPadding() {
|
void writeArrayDelimiterPadding() {
|
||||||
for (int i = 0; i < tomlWriter.getIndentationPolicy().getArrayDelimiterPadding(); i++) {
|
for (int i = 0; i < indentationPolicy.getArrayDelimiterPadding(); i++) {
|
||||||
write(' ');
|
write(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,9 +123,10 @@ class WriterContext {
|
||||||
|
|
||||||
private WriterContext(String key, String tableIndent, Writer output, TomlWriter tomlWriter) {
|
private WriterContext(String key, String tableIndent, Writer output, TomlWriter tomlWriter) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.currentTableIndent = tableIndent;
|
|
||||||
this.currentFieldIndent = tableIndent + fillStringWithSpaces(tomlWriter.getIndentationPolicy().getKeyValueIndent());
|
|
||||||
this.output = output;
|
this.output = output;
|
||||||
|
this.indentationPolicy = tomlWriter.getIndentationPolicy();
|
||||||
|
this.currentTableIndent = tableIndent;
|
||||||
|
this.currentFieldIndent = tableIndent + fillStringWithSpaces(this.indentationPolicy.getKeyValueIndent());
|
||||||
this.tomlWriter = tomlWriter;
|
this.tomlWriter = tomlWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue