KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jdepend > framework > PackageComparator


1 package jdepend.framework;
2
3 import java.util.Comparator JavaDoc;
4
5 /**
6  * The <code>PackageComparator</code> class is a <code>Comparator</code>
7  * used to compare two <code>JavaPackage</code> instances for order using a
8  * sorting strategy.
9  *
10  * @author <b>Mike Clark</b>
11  * @author Clarkware Consulting, Inc.
12  */

13
14 public class PackageComparator implements Comparator JavaDoc {
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 JavaDoc p1, Object JavaDoc 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 }
Popular Tags