From bf0938f91516cfd6c2e200833a75de5ee3aaaea7 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 18 Dec 2024 13:31:38 +0900 Subject: [PATCH] refactor: fix merge error when split PR#963 Signed-off-by: Hiroshi Miura --- .../core/statistics/CalcMatchStatistics.java | 10 +++++++--- .../statistics/CalcMatchStatisticsTest.java | 18 ++++++------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/org/omegat/core/statistics/CalcMatchStatistics.java b/src/org/omegat/core/statistics/CalcMatchStatistics.java index 2aa2e4fc7a..674e4ddabd 100644 --- a/src/org/omegat/core/statistics/CalcMatchStatistics.java +++ b/src/org/omegat/core/statistics/CalcMatchStatistics.java @@ -51,6 +51,7 @@ import org.omegat.core.threads.LongProcessThread; import org.omegat.util.OConsts; import org.omegat.util.OStrings; +import org.omegat.util.Preferences; import org.omegat.util.StringUtil; import org.omegat.util.Token; import org.omegat.util.gui.TextUtil; @@ -107,15 +108,18 @@ public class CalcMatchStatistics extends LongProcessThread { private final IProject project; public CalcMatchStatistics(IStatsConsumer callback, boolean perFile) { - this(Core.getProject(), Core.getSegmenter(), callback, perFile); + this(Core.getProject(), Core.getSegmenter(), callback, perFile, + Preferences.getPreferenceDefault(Preferences.EXT_TMX_FUZZY_MATCH_THRESHOLD, + OConsts.FUZZY_MATCH_THRESHOLD)); } - public CalcMatchStatistics(IProject project, Segmenter segmenter, IStatsConsumer callback, boolean perFile) { + public CalcMatchStatistics(IProject project, Segmenter segmenter, IStatsConsumer callback, + boolean perFile, int threshold) { this.project = project; this.callback = callback; this.perFile = perFile; finder = ThreadLocal.withInitial( - () -> new FindMatches(project, segmenter, OConsts.MAX_NEAR_STRINGS, false, -1)); + () -> new FindMatches(project, segmenter, OConsts.MAX_NEAR_STRINGS, false, threshold)); } @Override diff --git a/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java b/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java index 25ab768787..e90729d4c6 100644 --- a/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java +++ b/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java @@ -25,7 +25,6 @@ package org.omegat.core.statistics; -import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -36,7 +35,6 @@ import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.omegat.core.Core; @@ -67,17 +65,13 @@ public class CalcMatchStatisticsTest { - @BeforeClass - public static void setup() throws IOException { - TestPreferencesInitializer.init(); - } - @Test public void testCalcMatchStatics() throws Exception { TestProject project = new TestProject(new ProjectPropertiesTest()); IStatsConsumer callback = new TestStatsConsumer(); Segmenter segmenter = new Segmenter(SRX.getDefault()); - CalcMatchStatisticsMock calcMatchStatistics = new CalcMatchStatisticsMock(project, segmenter, callback); + CalcMatchStatisticsMock calcMatchStatistics = new CalcMatchStatisticsMock(project, segmenter, + callback, 30); calcMatchStatistics.start(); try { calcMatchStatistics.join(); @@ -130,8 +124,7 @@ public void testCalcMatchStatics() throws Exception { Assert.assertEquals("5699", result[7][4]); // change threshold - Preferences.setPreference(Preferences.EXT_TMX_FUZZY_MATCH_THRESHOLD, 70); - calcMatchStatistics = new CalcMatchStatisticsMock(project, segmenter, callback); + calcMatchStatistics = new CalcMatchStatisticsMock(project, segmenter, callback, 70); calcMatchStatistics.start(); try { calcMatchStatistics.join(); @@ -370,8 +363,9 @@ static class CalcMatchStatisticsMock extends CalcMatchStatistics { private MatchStatCounts result; private final IStatsConsumer callback; - CalcMatchStatisticsMock(IProject project, Segmenter segmenter, IStatsConsumer callback) { - super(project, segmenter, callback, false); + CalcMatchStatisticsMock(IProject project, Segmenter segmenter, IStatsConsumer callback, + int threshold) { + super(project, segmenter, callback, false, threshold); this.project = project; this.callback = callback; }