KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > util > TimeZoneComparator


1 package org.roller.util;
2 import java.util.TimeZone JavaDoc;
3 import java.util.Comparator JavaDoc;
4 import java.io.Serializable JavaDoc;
5
6 public class TimeZoneComparator implements Comparator JavaDoc, Serializable JavaDoc
7 {
8     public int compare(Object JavaDoc obj1, Object JavaDoc obj2)
9     {
10         if (obj1 instanceof TimeZone JavaDoc && obj2 instanceof TimeZone JavaDoc)
11         {
12             TimeZone JavaDoc zone1 = (TimeZone JavaDoc)obj1;
13             TimeZone JavaDoc zone2 = (TimeZone JavaDoc)obj2;
14             int compName = zone1.getDisplayName().compareTo(zone2.getDisplayName());
15             if (compName == 0)
16             {
17                 return zone1.getID().compareTo(zone2.getID());
18             }
19             return compName;
20         }
21         return 0;
22     }
23
24     /* Do Comparators need to implement equals()? -Lance
25     public boolean equals(Object obj)
26     {
27         if (obj instanceof TimeZoneComparator)
28         {
29             if (obj.equals(this)) return true;
30         }
31         return false;
32     }
33     */

34 }
Popular Tags