From e2a3149d190219af93f2119f1eecb0539ad5ff78 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 9 Feb 2016 01:17:48 +0000 Subject: [PATCH] Refactor SimilarityComparator simple usage --- source/net/filebot/format/MediaBindingBean.java | 2 +- source/net/filebot/similarity/SimilarityComparator.java | 8 ++++---- test/net/filebot/similarity/SimilarityComparatorTest.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 72561dd1..e0992838 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -938,7 +938,7 @@ public class MediaBindingBean { // still no good match found -> just take the most probable video from the same folder if (videos.size() > 0) { - sort(videos, new SimilarityComparator(FileUtilities.getName(getMediaFile()), FileUtilities::getName)); + sort(videos, SimilarityComparator.compareTo(getMediaFile(), FileUtilities::getName)); return videos.get(0); } } diff --git a/source/net/filebot/similarity/SimilarityComparator.java b/source/net/filebot/similarity/SimilarityComparator.java index 0d4aced0..acd80aff 100644 --- a/source/net/filebot/similarity/SimilarityComparator.java +++ b/source/net/filebot/similarity/SimilarityComparator.java @@ -9,6 +9,10 @@ import java.util.function.Function; public class SimilarityComparator implements Comparator { + public static SimilarityComparator compareTo(T value, Function mapper) { + return new SimilarityComparator(new NameSimilarityMetric(), singleton(mapper.apply(value)), mapper.andThen(Collections::singleton)); + } + protected SimilarityMetric metric; protected Collection

paragon; @@ -20,10 +24,6 @@ public class SimilarityComparator implements Comparator { this.mapper = mapper; } - public SimilarityComparator(P paragon, Function mapper) { - this(new NameSimilarityMetric(), singleton(paragon), mapper.andThen(Collections::singleton)); - } - @Override public int compare(T o1, T o2) { return Double.compare(getSimilarity(o2), getSimilarity(o1)); diff --git a/test/net/filebot/similarity/SimilarityComparatorTest.java b/test/net/filebot/similarity/SimilarityComparatorTest.java index 16bdd5a1..8241a62c 100644 --- a/test/net/filebot/similarity/SimilarityComparatorTest.java +++ b/test/net/filebot/similarity/SimilarityComparatorTest.java @@ -27,7 +27,7 @@ public class SimilarityComparatorTest { @Test public void defaultUsage() { - SimilarityComparator c = new SimilarityComparator("Hello", String::toString); + SimilarityComparator c = SimilarityComparator.compareTo("Hello", String::toString); List phrases = generateWords(); phrases.sort(c);