Skip to content

Commit

Permalink
fix: Fix pattern order to ensure reproductability
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Rousseau committed Nov 9, 2024
1 parent 0d4829e commit 657484a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.romualdrousseau.archery.commons.dsf;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
Expand All @@ -13,4 +14,10 @@ public class DSFCollector {
public static <T> Collector<DSFObject, ?, Map<String, T>> toUnmodifiableMap(final String key, final String value) {
return Collectors.toUnmodifiableMap(x -> x.<String>get(key).get(), x -> x.<T>get(value).get());
}

public static <T> Collector<DSFObject, ?, Map<String, T>> toLinkedMap(final String key, final String value) {
return Collectors.toMap(x -> x.<String>get(key).get(), x -> x.<T>get(value).get(), (e1, e2) -> {
throw new RuntimeException();
}, LinkedHashMap::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public String anonymize(final String v, final String filter) {
@Override
public Optional<String> find(final String v) {
return (v == null) ? Optional.empty()
: this.compiledPatterns.values().stream()
.map(e -> e.matcher(v))
: this.patterns.entrySet().stream()
.map(p -> this.compiledPatterns.get(p.getKey()).matcher(v))
.filter(m -> m.find())
.map(m -> m.group())
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ModelData setList(final String key, final List<String> values) {
@Override
public Map<String, String> getMap(final String key) {
return this.backstore.<DSFArray>get(key)
.map(x -> x.<DSFObject>stream().collect(DSFCollector.<String>toUnmodifiableMap("key", "value")))
.map(x -> x.<DSFObject>stream().collect(DSFCollector.<String>toLinkedMap("key", "value")))
.orElse(Collections.emptyMap());
}

Expand Down

0 comments on commit 657484a

Please sign in to comment.