From 657484a30820d8df5114b63aa3de45e446f59ebe Mon Sep 17 00:00:00 2001 From: Romuald Rousseau Date: Sun, 10 Nov 2024 01:56:41 +0800 Subject: [PATCH] fix: Fix pattern order to ensure reproductability --- .../romualdrousseau/archery/commons/dsf/DSFCollector.java | 7 +++++++ .../commons/preprocessing/comparer/RegexComparer.java | 4 ++-- .../romualdrousseau/archery/modeldata/JsonModelData.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/dsf/DSFCollector.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/dsf/DSFCollector.java index b25ff446..b510e813 100644 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/dsf/DSFCollector.java +++ b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/dsf/DSFCollector.java @@ -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; @@ -13,4 +14,10 @@ public class DSFCollector { public static Collector> toUnmodifiableMap(final String key, final String value) { return Collectors.toUnmodifiableMap(x -> x.get(key).get(), x -> x.get(value).get()); } + + public static Collector> toLinkedMap(final String key, final String value) { + return Collectors.toMap(x -> x.get(key).get(), x -> x.get(value).get(), (e1, e2) -> { + throw new RuntimeException(); + }, LinkedHashMap::new); + } } diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/preprocessing/comparer/RegexComparer.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/preprocessing/comparer/RegexComparer.java index c223c3ba..c182be0a 100644 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/preprocessing/comparer/RegexComparer.java +++ b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/preprocessing/comparer/RegexComparer.java @@ -48,8 +48,8 @@ public String anonymize(final String v, final String filter) { @Override public Optional 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(); diff --git a/archery/src/main/java/com/github/romualdrousseau/archery/modeldata/JsonModelData.java b/archery/src/main/java/com/github/romualdrousseau/archery/modeldata/JsonModelData.java index cc34d41c..838e7006 100644 --- a/archery/src/main/java/com/github/romualdrousseau/archery/modeldata/JsonModelData.java +++ b/archery/src/main/java/com/github/romualdrousseau/archery/modeldata/JsonModelData.java @@ -49,7 +49,7 @@ public ModelData setList(final String key, final List values) { @Override public Map getMap(final String key) { return this.backstore.get(key) - .map(x -> x.stream().collect(DSFCollector.toUnmodifiableMap("key", "value"))) + .map(x -> x.stream().collect(DSFCollector.toLinkedMap("key", "value"))) .orElse(Collections.emptyMap()); }