Skip to content

Commit

Permalink
Add new function add_array and add_hash #374
Browse files Browse the repository at this point in the history
The are a copy of the current implementation of set_array and set_hash. This is a preparation for #309
  • Loading branch information
TobiasNx committed Oct 16, 2024
1 parent 9b4a6c1 commit 618844a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions metafix/src/main/java/org/metafacture/metafix/FixMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,29 @@ public void apply(final Metafix metafix, final Record record, final List<String>

// RECORD-LEVEL METHODS:

add_array {
@Override
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
final String field = params.get(0);
final Value newValue = newArray(params.subList(1, params.size()).stream().map(Value::new));
record.set(field, newValue);
newValue.asArray().forEach(value -> value.withPathSet(newValue.getPath() + "." + value.getPath()));
}
},
add_field {
@Override
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
record.set(params.get(0), new Value(params.get(1)));
}
},
add_hash {
@Override
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
final String field = params.get(0);
final Value newValue = Value.newHash(h -> options.forEach((f, v) -> h.put(f, new Value(v))));
record.set(field, newValue);
}
},
array { // array-from-hash
@Override
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
Expand Down

0 comments on commit 618844a

Please sign in to comment.