Skip to content

Commit

Permalink
Adjust delete function as suggested by @blackwinter #333
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasNx committed Sep 18, 2024
1 parent 5cb5e66 commit a505fc5
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions metafix/src/main/java/org/metafacture/metafix/FixMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,10 @@ public void apply(final Metafix metafix, final Record record, final List<String>
map = metafix.getMap(mapName);
}

final String defaultValue = map.get(Maps.DEFAULT_MAP_KEY); // TODO: Catmandu uses 'default'
final String defaultOption = options.get("default");
final String defaultValue = options.getOrDefault(Maps.DEFAULT_MAP_KEY, map.get(Maps.DEFAULT_MAP_KEY));
final boolean delete = getBoolean(options, "delete");
final boolean printUnknown = getBoolean(options, "print_unknown");
final String defaultOption = options.get("default");

final Consumer<Consumer<String>> consumer = c -> record.transform(params.get(0), oldValue -> {
final String newValue = map.get(oldValue);
Expand All @@ -531,11 +531,7 @@ public void apply(final Metafix metafix, final Record record, final List<String>
if (c != null) {
c.accept(oldValue);
}
elsif (defaultOption != null){
return defaultOption;
}
return defaultValue != null ? defaultValue : delete ? null : oldValue;

return defaultOption != null ? defaultOption : defaultValue != null ? defaultValue : delete ? null : oldValue;
}
});

Expand Down

0 comments on commit a505fc5

Please sign in to comment.