01: package net.sourceforge.pmd.dcd.graph;
02:
03: import java.util.Comparator;
04:
05: /**
06: * Compares ClassNodes by the name of the class. Can also compare String class
07: * names to ClassNodes.
08: */
09: public class ClassNodeComparator implements Comparator {
10:
11: public static final ClassNodeComparator INSTANCE = new ClassNodeComparator();
12:
13: private ClassNodeComparator() {
14: }
15:
16: public int compare(Object obj1, Object obj2) {
17: if (obj1 instanceof String && obj2 instanceof String) {
18: return ((String) obj1).compareTo((String) obj2);
19: } else if (obj1 instanceof String) {
20: return ((String) obj1).compareTo(((ClassNode) obj2)
21: .getName());
22: } else if (obj2 instanceof String) {
23: return ((ClassNode) obj1).getName()
24: .compareTo((String) obj2);
25: } else {
26: return ((ClassNode) obj1).compareTo((ClassNode) obj2);
27: }
28: }
29: }
|