From a505fc5316e147d792760e46e06634265e4d5959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=BClte?= Date: Mon, 9 Sep 2024 12:09:27 +0200 Subject: [PATCH] Adjust delete function as suggested by @blackwinter #333 --- .../main/java/org/metafacture/metafix/FixMethod.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java index a8045a34..81b7a9ad 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java +++ b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java @@ -517,10 +517,10 @@ public void apply(final Metafix metafix, final Record record, final List 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 = c -> record.transform(params.get(0), oldValue -> { final String newValue = map.get(oldValue); @@ -531,11 +531,7 @@ public void apply(final Metafix metafix, final Record record, final List 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; } });