01: package net.sourceforge.pmd.dcd.graph;
02:
03: import java.util.Comparator;
04:
05: /**
06: * Compares MemberNodes. FieldNodes are smaller than ConstructorNodes
07: * which are smaller than MethodNodes.
08: */
09: public class MemberNodeComparator implements Comparator<MemberNode> {
10:
11: public static final MemberNodeComparator INSTANCE = new MemberNodeComparator();
12:
13: private MemberNodeComparator() {
14: }
15:
16: public int compare(MemberNode node1, MemberNode node2) {
17: if (node1 instanceof FieldNode) {
18: if (node2 instanceof FieldNode) {
19: return node1.compareTo(node2);
20: } else {
21: return -1;
22: }
23: } else if (node1 instanceof ConstructorNode) {
24: if (node2 instanceof FieldNode) {
25: return 1;
26: } else if (node2 instanceof ConstructorNode) {
27: return node1.compareTo(node2);
28: } else {
29: return -1;
30: }
31: } else {
32: if (node2 instanceof MethodNode) {
33: return node1.compareTo(node2);
34: } else {
35: return 1;
36: }
37: }
38: }
39: }
|