private static boolean rangesEqual(IRangeComparator a, int ai, IRangeComparator b, int bi) { return a.rangesEqual(ai, b, bi); } }
@Override public String toString() { String string = "Left: " + toRangeString(fLeftStart, fLeftLength) + " Right: " + toRangeString(fRightStart, fRightLength); //$NON-NLS-1$ //$NON-NLS-2$ if (lAncestorLength > 0 || lAncestorStart > 0) string += " Ancestor: " + toRangeString(lAncestorStart, lAncestorLength); //$NON-NLS-1$ return string; }
public static RangeDifference[] findDifferences( LCSSettings settings, IRangeComparator left, IRangeComparator right) { RangeComparatorLCS lcs = new RangeComparatorLCS(left, right); lcs.longestCommonSubsequence( settings); return lcs.getDifferences(); }
return findRanges(settings, left, right); RangeDifference[] in = findDifferences(settings, ancestor, left, right); List out = new ArrayList(); RangeDifference es = in[i]; rd = new RangeDifference(RangeDifference.NOCHANGE, mstart, es .rightStart() - mstart, ystart, es.leftStart() - ystart, astart, es .ancestorStart() - astart); if (rd.maxLength() > 0) out.add(rd); mstart = es.rightEnd(); ystart = es.leftEnd(); astart = es.ancestorEnd(); rd = new RangeDifference(RangeDifference.NOCHANGE, mstart, right .getRangeCount() - mstart, ystart, left.getRangeCount() - ystart, astart, ancestor.getRangeCount() - astart); if (rd.maxLength() > 0) out.add(rd);
RangeDifference[] in = findDifferences( settings, left, right); List out = new ArrayList(); RangeDifference es = in[i]; rd = new RangeDifference(RangeDifference.NOCHANGE, mstart, es .rightStart() - mstart, ystart, es.leftStart() - ystart); if (rd.maxLength() != 0) out.add(rd); mstart = es.rightEnd(); ystart = es.leftEnd(); rd = new RangeDifference(RangeDifference.NOCHANGE, mstart, right .getRangeCount() - mstart, ystart, left.getRangeCount() - ystart); if (rd.maxLength() > 0) out.add(rd);
if (myIter.getCount() == 0) { // only left changed rightStart = changeRangeStart - last.ancestorEnd() + last.rightEnd(); rightEnd = changeRangeEnd - last.ancestorEnd() + last.rightEnd(); kind = RangeDifference.LEFT; } else { .get(myIter.fRange.size() - 1); rightStart = changeRangeStart - f.fLeftStart + f.fRightStart; rightEnd = changeRangeEnd - l.leftEnd() + l.rightEnd(); if (yourIter.getCount() == 0) { // only right changed leftStart = changeRangeStart - last.ancestorEnd() + last.leftEnd(); leftEnd = changeRangeEnd - last.ancestorEnd() + last.leftEnd(); kind = RangeDifference.RIGHT; } else { .get(yourIter.fRange.size() - 1); leftStart = changeRangeStart - f.fLeftStart + f.fRightStart; leftEnd = changeRangeEnd - l.leftEnd() + l.rightEnd(); if (rangeSpansEqual(right, rightStart, rightEnd - rightStart, left, leftStart, leftEnd - leftStart)) kind = RangeDifference.ANCESTOR; return new RangeDifference(kind, rightStart, rightEnd - rightStart, leftStart, leftEnd - leftStart, changeRangeStart, changeRangeEnd - changeRangeStart);
int rightSize = right.getRangeCount(); int leftSize = left.getRangeCount(); && rangesEqual(right, row, left, row) == true;) row++; if (right.skipRangeComparison(d, maxDiagonal, left)) return EMPTY_RESULT; // should be something we already found edit = new LinkedRangeDifference(script[k + 1], LinkedRangeDifference.DELETE); } else { edit = new LinkedRangeDifference(script[k - 1], LinkedRangeDifference.INSERT); && rangesEqual(right, row, left, col) == true) { ++row; ++col; return createDifferencesRanges(script[k]);
public double getMatchRatio(StringComparator other) { LCSSettings settings = new LCSSettings(); settings.setUseGreedyMethod(true); settings.setPowLimit(1.5); settings.setTooLong(150 * 150); RangeDifference[] differences = RangeDifferencer.findDifferences( settings, other, this); int distanceOther = 0; for (RangeDifference d : differences) { distanceOther += d.leftLength(); } int distanceThis = 0; for (RangeDifference d : differences) { distanceThis += d.rightLength(); } return ((0.0 + distanceOther) / other.getRangeCount() + (0.0 + distanceThis) / getRangeCount()) / 2; } }
LinkedRangeDifference ep = reverseDifferences(start); ArrayList result = new ArrayList(); RangeDifference es = null; es = new RangeDifference(RangeDifference.CHANGE); if (ep.isInsert()) { es.fRightStart = ep.fRightStart + 1; es.fLeftStart = ep.fLeftStart; RangeDifference b = ep; do { ep = ep.getNext(); es.fLeftLength++; } while (ep != null && ep.isInsert() && ep.fRightStart == b.fRightStart); } else { ep = ep.getNext(); es.fRightLength++; } while (ep != null && ep.isDelete() && ep.fRightStart == a.fRightStart + 1); boolean change = (ep != null && ep.isInsert() && ep.fRightStart == a.fRightStart); ep = ep.getNext(); es.fLeftLength++; } while (ep != null && ep.isInsert() && ep.fRightStart == b.fRightStart); } else {
public RangeDifference[] getDifferences() { int length = getLength(); if (length == 0) { differences.add(new RangeDifference(RangeDifference.CHANGE, 0, comparator2.getRangeCount(), 0, comparator1 .getRangeCount())); } else { int index1, index2; differences.add(new RangeDifference( RangeDifference.CHANGE, 0, end2, 0, end1)); } else if (end1 != s1 + 1 || end2 != s2 + 1) { differences.add(new RangeDifference( RangeDifference.CHANGE, rightStart, rightLength, leftStart, leftLength)); && (s1 + 1 < comparator1.getRangeCount() || s2 + 1 < comparator2 .getRangeCount())) { int leftStart = s1 < comparator1.getRangeCount() ? s1 + 1 : s1; int rightStart = s2 < comparator2.getRangeCount() ? s2 + 1 : s2; differences.add(new RangeDifference(RangeDifference.CHANGE, rightStart, comparator2.getRangeCount() - (s2 + 1), leftStart, comparator1.getRangeCount() - (s1 + 1)));
@Override protected int getLength1() { return comparator1.getRangeCount(); }
/** * Finds the differences between two <code>IRangeComparator</code>s. The * differences are returned as an array of <code>RangeDifference</code>s. * If no differences are detected an empty array is returned. * * @param pm * if not <code>null</code> used to report progress * @param left * the left range comparator * @param right * the right range comparator * @return an array of range differences, or an empty array if no * differences were found * @since 2.0 */ public static RangeDifference[] findDifferences( LCSSettings settings, IRangeComparator left, IRangeComparator right) { if (!settings.isUseGreedyMethod()) { return OldDifferencer.findDifferences( left, right); } return RangeComparatorLCS.findDifferences( settings, left, right); }
/** * Finds the differences between two <code>IRangeComparator</code>s. The * differences are returned as an array of <code>RangeDifference</code>s. * If no differences are detected an empty array is returned. * * @param left * the left range comparator * @param right * the right range comparator * @return an array of range differences, or an empty array if no * differences were found */ public static RangeDifference[] findDifferences(IRangeComparator left, IRangeComparator right) { return findDifferences( new LCSSettings(), left, right); }
private static boolean rangeSpansEqual(IRangeComparator right, int rightStart, int rightLen, IRangeComparator left, int leftStart, int leftLen) { if (rightLen == leftLen) { int i = 0; for (i = 0; i < rightLen; i++) { if (!rangesEqual(right, rightStart + i, left, leftStart + i)) break; } if (i == rightLen) return true; } return false; }
boolean isDelete() { return kind() == DELETE; }
@Override protected int getLength2() { return comparator2.getRangeCount(); }
@Override protected boolean isRangeEqual(int i1, int i2) { return comparator1.rangesEqual(i1, comparator2, i2); }
boolean isInsert() { return kind() == INSERT; }
private static boolean rangesEqual(IRangeComparator a, int ai, IRangeComparator b, int bi) { return a.rangesEqual(ai, b, bi); }