* match longest possible sequence and not just the first one. should make sequence matching more reliable and work as expected
This commit is contained in:
parent
cdfafe0337
commit
6f5acab61f
|
@ -97,6 +97,7 @@ public class CommonSequenceMatcher {
|
||||||
|
|
||||||
|
|
||||||
protected <E extends Comparable<E>> E[] firstCommonSequence(E[] seq1, E[] seq2, int maxStartIndex) {
|
protected <E extends Comparable<E>> E[] firstCommonSequence(E[] seq1, E[] seq2, int maxStartIndex) {
|
||||||
|
E[] matchSeq = null;
|
||||||
for (int i = 0; i < seq1.length && i <= maxStartIndex; i++) {
|
for (int i = 0; i < seq1.length && i <= maxStartIndex; i++) {
|
||||||
for (int j = 0; j < seq2.length && j <= maxStartIndex; j++) {
|
for (int j = 0; j < seq2.length && j <= maxStartIndex; j++) {
|
||||||
// common sequence length
|
// common sequence length
|
||||||
|
@ -108,16 +109,11 @@ public class CommonSequenceMatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if a common sequence was found
|
// check if a common sequence was found
|
||||||
if (len > 0) {
|
if (len > (matchSeq == null ? 0 : matchSeq.length)) {
|
||||||
if (i == 0 && len == seq1.length)
|
matchSeq = copyOfRange(seq1, i, i + len);
|
||||||
return seq1;
|
|
||||||
|
|
||||||
return copyOfRange(seq1, i, i + len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return matchSeq;
|
||||||
// no intersection at all
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue