Skip to content

Commit

Permalink
Integrate feedback from #170 (see #102)
Browse files Browse the repository at this point in the history
Co-authored-by: Jens Wille <jens.wille@hbz-nrw.de>
  • Loading branch information
fsteeg and blackwinter committed Mar 4, 2022
1 parent e9dd4ab commit 1bcc5ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,5 @@ public void apply(final Metafix metafix, final Record record, final List<String>
private static final Random RANDOM = new Random();

private static final Map<String, Fix> INCLUDE_FIX = new HashMap<>();

}
8 changes: 5 additions & 3 deletions metafix/src/main/java/org/metafacture/metafix/FixPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Our goal here is something like https://metacpan.org/pod/Catmandu::Path::simple
Expand Down Expand Up @@ -118,7 +117,7 @@ public String toString() {
// (e.g. take care of handling repeated fields and their paths)

/*package-private*/ FixPath to(final Value value, final int i) {
FixPath result = this;
final FixPath result;
// One *: replace with index of current result
if (countAsterisks() == 1) {
result = new FixPath(replaceInPath(ASTERISK, i));
Expand All @@ -127,11 +126,14 @@ public String toString() {
else if (value.getPath() != null && (countAsterisks() >= 2) || hasWildcard()) {
result = new FixPath(value.getPath());
}
else {
result = this;
}
return result;
}

private String[] replaceInPath(final String find, final int i) {
return Arrays.asList(path).stream().map(s -> s.equals(find) ? String.valueOf(i + 1) : s).collect(Collectors.toList()).toArray(new String[] {});
return Arrays.asList(path).stream().map(s -> s.equals(find) ? String.valueOf(i + 1) : s).toArray(String[]::new);
}

private boolean hasWildcard() {
Expand Down

0 comments on commit 1bcc5ca

Please sign in to comment.