KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > support > reflect > CtLineElementComparator


1 package spoon.support.reflect;
2
3 import java.util.Comparator JavaDoc;
4
5 import spoon.reflect.declaration.CtElement;
6
7 /**
8  * Comparator of compile-time elements. Elements are sorted by position in
9  * source files.
10  */

11 public class CtLineElementComparator implements Comparator JavaDoc<CtElement> {
12
13     /**
14      * Compares two program elements.
15      */

16     public int compare(CtElement o1, CtElement o2) {
17         if (o1.getPosition() == null)
18             return 1;
19         if (o2.getPosition() == null)
20             return -1;
21         if (o1.getPosition().getLine() == o2.getPosition().getLine()) {
22             return ((Integer JavaDoc)o1.getPosition().getColumn()).compareTo(o2.getPosition().getColumn());
23         }
24         return ((Integer JavaDoc)o1.getPosition().getLine()).compareTo(o2
25                 .getPosition().getLine());
26     }
27
28 }
29
Popular Tags