Skip to content

Commit

Permalink
Minor format adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
cleishm committed Oct 18, 2022
1 parent 3307743 commit d0bf4bf
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/main/java/org/tomlj/TomlSerializer.java
Expand Up @@ -36,8 +36,7 @@ static void toToml(TomlTable table, Appendable appendable) throws IOException {
toToml(table, appendable, -2, "");
}

private static void toToml(TomlTable table, Appendable appendable, int indent, String path)
throws IOException {
private static void toToml(TomlTable table, Appendable appendable, int indent, String path) throws IOException {
for (Map.Entry<String, Object> entry : table.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
Expand All @@ -61,7 +60,6 @@ private static void toToml(TomlTable table, Appendable appendable, int indent, S
append(appendable, indent + 2, key + "=");
}

assert value != null;
appendTomlValue(value, appendable, indent, newPath);
if (!tomlType.get().equals(TABLE) && !isTableArray) {
appendable.append(System.lineSeparator());
Expand All @@ -75,8 +73,7 @@ static void toToml(TomlArray array, Appendable appendable) throws IOException {
toToml(array, appendable, 0, "");
}

private static void toToml(TomlArray array, Appendable appendable, int indent, String path)
throws IOException {
private static void toToml(TomlArray array, Appendable appendable, int indent, String path) throws IOException {
boolean tableArray = isTableArray(array);
if (!tableArray) {
appendable.append("[");
Expand All @@ -85,10 +82,9 @@ private static void toToml(TomlArray array, Appendable appendable, int indent, S
}
}

Optional<TomlType> tomlType = Optional.empty();
for (Iterator<Object> iterator = array.toList().iterator(); iterator.hasNext(); ) {
for (Iterator<Object> iterator = array.toList().iterator(); iterator.hasNext();) {
Object tomlValue = iterator.next();
tomlType = typeFor(tomlValue);
Optional<TomlType> tomlType = typeFor(tomlValue);
assert tomlType.isPresent();
if (tomlType.get().equals(TABLE)) {
append(appendable, indent, "[[" + path + "]]");
Expand All @@ -111,8 +107,7 @@ private static void toToml(TomlArray array, Appendable appendable, int indent, S
}
}

private static void appendTomlValue(Object value, Appendable appendable, int indent, String path)
throws IOException {
private static void appendTomlValue(Object value, Appendable appendable, int indent, String path) throws IOException {
Optional<TomlType> tomlType = typeFor(value);
assert tomlType.isPresent();
switch (tomlType.get()) {
Expand All @@ -124,8 +119,7 @@ private static void appendTomlValue(Object value, Appendable appendable, int ind
append(appendable, 0, value.toString());
break;
case OFFSET_DATE_TIME:
append(
appendable, 0, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((OffsetDateTime) value));
append(appendable, 0, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((OffsetDateTime) value));
break;
case LOCAL_DATE_TIME:
append(appendable, 0, DateTimeFormatter.ISO_LOCAL_DATE_TIME.format((LocalDateTime) value));
Expand Down Expand Up @@ -160,9 +154,8 @@ private static void indentLine(Appendable appendable, int indent) throws IOExcep
}

private static boolean isTableArray(TomlArray array) {
Optional<TomlType> tomlType = Optional.empty();
for (Object tomlValue : array.toList()) {
tomlType = typeFor(tomlValue);
Optional<TomlType> tomlType = typeFor(tomlValue);
assert tomlType.isPresent();
if (tomlType.get().equals(TABLE)) {
return true;
Expand Down

0 comments on commit d0bf4bf

Please sign in to comment.