2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.corext.textmanipulation;
7 import java.util.Comparator;
10 * A special comparator to comapre <code>TextRange</code>s.
12 /* package */class TextEditNodeComparator implements Comparator {
13 public int compare(Object o1, Object o2) {
14 TextEditNode node1 = (TextEditNode) o1;
15 TextEditNode node2 = (TextEditNode) o2;
16 TextRange pos1 = node1.getTextRange();
17 TextRange pos2 = node2.getTextRange();
19 int offset1 = pos1.fOffset;
20 int offset2 = pos2.fOffset;
21 if (offset1 < offset2)
23 if (offset1 > offset2)
27 int length1 = pos1.fLength;
28 int length2 = pos2.fLength;
30 // insertion points come before anything else at the same position.
31 if (length1 == 0 && length2 != 0)
33 if (length1 != 0 && length2 == 0)
36 // Longer edits come before shorter edits
37 if (length1 < length2)
39 if (length1 > length2)
42 if (node1.fEdit.index < node2.fEdit.index)