From 6f5acab61f7e7284ffa58d1404b60b4f159033ad Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 20 Feb 2013 10:18:35 +0000 Subject: [PATCH] * match longest possible sequence and not just the first one. should make sequence matching more reliable and work as expected --- .../filebot/similarity/CommonSequenceMatcher.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java b/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java index f2be5978..9fce86a3 100644 --- a/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java +++ b/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java @@ -97,6 +97,7 @@ public class CommonSequenceMatcher { protected > E[] firstCommonSequence(E[] seq1, E[] seq2, int maxStartIndex) { + E[] matchSeq = null; for (int i = 0; i < seq1.length && i <= maxStartIndex; i++) { for (int j = 0; j < seq2.length && j <= maxStartIndex; j++) { // common sequence length @@ -108,16 +109,11 @@ public class CommonSequenceMatcher { } // check if a common sequence was found - if (len > 0) { - if (i == 0 && len == seq1.length) - return seq1; - - return copyOfRange(seq1, i, i + len); + if (len > (matchSeq == null ? 0 : matchSeq.length)) { + matchSeq = copyOfRange(seq1, i, i + len); } } } - - // no intersection at all - return null; + return matchSeq; } }