A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / textmanipulation / TextEditNodeComparator.java
1 /*
2  * (c) Copyright IBM Corp. 2000, 2001.
3  * All Rights Reserved.
4  */
5 package net.sourceforge.phpdt.internal.corext.textmanipulation;
6
7 import java.util.Comparator;
8
9 /**
10  * A special comparator to comapre <code>TextRange</code>s.
11  */
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();
18
19                 int offset1 = pos1.fOffset;
20                 int offset2 = pos2.fOffset;
21                 if (offset1 < offset2)
22                         return -1;
23                 if (offset1 > offset2)
24                         return 1;
25
26                 // same offset
27                 int length1 = pos1.fLength;
28                 int length2 = pos2.fLength;
29
30                 // insertion points come before anything else at the same position.
31                 if (length1 == 0 && length2 != 0)
32                         return -1;
33                 if (length1 != 0 && length2 == 0)
34                         return 1;
35
36                 // Longer edits come before shorter edits
37                 if (length1 < length2)
38                         return 1;
39                 if (length1 > length2)
40                         return -1;
41
42                 if (node1.fEdit.index < node2.fEdit.index)
43                         return -1;
44                 return 1;
45         }
46 }