1 11 package org.eclipse.compare.rangedifferencer; 12 13 29 public class RangeDifference { 30 31 32 public final static int NOCHANGE= 0; 33 34 public final static int CHANGE= 2; 35 36 37 public final static int CONFLICT= 1; 38 39 public final static int RIGHT= 2; 40 41 public final static int LEFT= 3; 42 46 public final static int ANCESTOR= 4; 47 48 49 public final static int ERROR= 5; 50 51 52 int fKind; 53 54 int fLeftStart; 55 int fLeftLength; 56 int fRightStart; 57 int fRightLength; 58 int lAncestorStart; 59 int lAncestorLength; 60 61 66 RangeDifference(int changeKind) { 67 fKind= changeKind; 68 } 69 70 80 RangeDifference(int kind, int rightStart, int rightLength, int leftStart, int leftLength) { 81 fKind= kind; 82 fRightStart= rightStart; 83 fRightLength= rightLength; 84 fLeftStart= leftStart; 85 fLeftLength= leftLength; 86 } 87 88 100 RangeDifference(int kind, int rightStart, int rightLength, int leftStart, int leftLength, 101 int ancestorStart, int ancestorLength) { 102 this(kind, rightStart, rightLength, leftStart, leftLength); 103 lAncestorStart= ancestorStart; 104 lAncestorLength= ancestorLength; 105 } 106 107 114 public int kind() { 115 return fKind; 116 } 117 118 123 public int ancestorStart() { 124 return lAncestorStart; 125 } 126 127 132 public int ancestorLength() { 133 return lAncestorLength; 134 } 135 136 141 public int ancestorEnd() { 142 return lAncestorStart + lAncestorLength; 143 } 144 145 150 public int rightStart() { 151 return fRightStart; 152 } 153 154 159 public int rightLength() { 160 return fRightLength; 161 } 162 163 168 public int rightEnd() { 169 return fRightStart + fRightLength; 170 } 171 172 177 public int leftStart() { 178 return fLeftStart; 179 } 180 181 186 public int leftLength() { 187 return fLeftLength; 188 } 189 190 195 public int leftEnd() { 196 return fLeftStart + fLeftLength; 197 } 198 199 204 public int maxLength() { 205 return Math.max(fRightLength, Math.max(fLeftLength, lAncestorLength)); 206 } 207 208 public boolean equals(Object obj) { 209 if (obj instanceof RangeDifference) { 210 RangeDifference other = (RangeDifference) obj; 211 return fKind == other.fKind 212 && fLeftStart == other.fLeftStart 213 && fLeftLength == other.fLeftLength 214 && fRightStart == other.fRightStart 215 && fRightLength == other.fRightLength 216 && lAncestorStart == other.lAncestorStart 217 && lAncestorLength == other.lAncestorLength; 218 } 219 return super.equals(obj); 220 } 221 222 public String toString() { 223 String string = "Left: " + toRangeString(fLeftStart, fLeftLength) + " Right: " + toRangeString(fRightStart, fRightLength); if (lAncestorLength > 0 || lAncestorStart> 0) 225 string += " Ancestor: " + toRangeString(lAncestorStart, lAncestorLength); return string; 227 } 228 229 private String toRangeString(int start, int length) { 230 return "(" + start + ", " + length + ")"; } 232 } 233 234 | Popular Tags |