Skip to content

Commit 629a9d6

Browse files
committed
Avoid redundancy: call tail(path) once, add else block (#127)
1 parent fffb6d9 commit 629a9d6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

metafix/src/main/java/org/metafacture/metafix/FixPath.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,15 @@ else if (isReference(field)) {
279279
}
280280
else {
281281
if (!hash.containsField(field)) {
282-
if (ReservedField.$prepend.name().equals(tail(path)[0]) || ReservedField.$append.name().equals(tail(path)[0])) {
283-
hash.put(field, Value.newArray().withPathSet(newValue.getPath()));
284-
}
285-
else {
286-
hash.put(field, Value.newHash().withPathSet(newValue.getPath()));
287-
}
282+
final Value value = Arrays.asList(ReservedField.$prepend.name(), ReservedField.$append.name())
283+
.contains(tail(path)[0]) ? Value.newArray() : Value.newHash();
284+
hash.put(field, value.withPathSet(newValue.getPath()));
288285
}
289-
final Value value = hash.get(field);
290-
if (value.isString()) {
291-
hash.put(field, Value.newArray(a -> a.add(value)));
286+
else {
287+
final Value value = hash.get(field);
288+
if (value.isString()) {
289+
hash.put(field, Value.newArray(a -> a.add(value)));
290+
}
292291
}
293292
insertInto(hash.get(field), mode, newValue, field, tail(path));
294293
}

0 commit comments

Comments
 (0)