01: package jdepend.framework;
02:
03: import java.util.Comparator;
04:
05: /**
06: * The <code>PackageComparator</code> class is a <code>Comparator</code>
07: * used to compare two <code>JavaPackage</code> instances for order using a
08: * sorting strategy.
09: *
10: * @author <b>Mike Clark</b>
11: * @author Clarkware Consulting, Inc.
12: */
13:
14: public class PackageComparator implements Comparator {
15:
16: private PackageComparator byWhat;
17:
18: private static PackageComparator byName;
19: static {
20: byName = new PackageComparator();
21: }
22:
23: public static PackageComparator byName() {
24: return byName;
25: }
26:
27: private PackageComparator() {
28: }
29:
30: public PackageComparator(PackageComparator byWhat) {
31: this .byWhat = byWhat;
32: }
33:
34: public PackageComparator byWhat() {
35: return byWhat;
36: }
37:
38: public int compare(Object p1, Object p2) {
39:
40: JavaPackage a = (JavaPackage) p1;
41: JavaPackage b = (JavaPackage) p2;
42:
43: if (byWhat() == byName()) {
44: return a.getName().compareTo(b.getName());
45: }
46:
47: return 0;
48: }
49: }
|