1 11 package org.eclipse.ui.internal.texteditor.quickdiff.compare.equivalence; 12 13 import java.util.ConcurrentModificationException ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.jface.text.source.ILineRange; 18 19 import org.eclipse.ui.internal.texteditor.quickdiff.compare.rangedifferencer.IRangeComparator; 20 21 31 public final class DocEquivalenceComparator implements IRangeComparator { 32 33 private final DocumentEquivalenceClass fEquivalenceClass; 34 private final int fLineOffset; 35 private final int fLines; 36 37 private boolean fSkip= false; 38 39 public DocEquivalenceComparator(DocumentEquivalenceClass equivalenceClass, ILineRange range) { 40 fEquivalenceClass= equivalenceClass; 41 if (range == null) { 42 fLineOffset= 0; 43 fLines= fEquivalenceClass.getCount(); 44 } else { 45 fLineOffset= range.getStartLine(); 46 fLines= range.getNumberOfLines(); 47 Assert.isTrue(fLineOffset >= 0); 48 Assert.isTrue(fLineOffset + fLines <= fEquivalenceClass.getCount()); 49 } 50 } 51 52 57 public int getRangeCount() { 58 return fLines; 59 } 60 61 70 public boolean rangesEqual(int thisIndex, IRangeComparator other, int otherIndex) { 71 if (other instanceof DocEquivalenceComparator) { 72 DocEquivalenceComparator dec= (DocEquivalenceComparator) other; 73 try { 74 Hash ourHash= getHash(thisIndex); 75 Hash otherHash= dec.getHash(otherIndex); 76 return ourHash.equals(otherHash); 77 } catch (ConcurrentModificationException e) { 78 fSkip= true; 79 } catch (IndexOutOfBoundsException e) { 80 fSkip= true; 81 } 82 } 83 return false; 84 } 85 86 Hash getHash(int index) { 87 return fEquivalenceClass.getHash(fLineOffset + index); 88 } 89 90 98 public boolean skipRangeComparison(int length, int max, IRangeComparator other) { 99 return fSkip; 100 } 101 } 102 103 | Popular Tags |