KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > comparators > WebAssetModDateComparator


1 package com.dotmarketing.comparators;
2
3 import java.util.Comparator JavaDoc;
4
5 import com.dotmarketing.beans.WebAsset;
6
7 /**
8  * @author Maria
9  *
10  * To change this generated comment edit the template variable "typecomment":
11  * Window>Preferences>Java>Templates.
12  * To enable and disable the creation of type comments go to
13  * Window>Preferences>Java>Code Generation.
14  */

15 public class WebAssetModDateComparator implements Comparator JavaDoc {
16
17     private String JavaDoc orderType = "";
18     
19     public WebAssetModDateComparator () {
20         
21     }
22     
23     public WebAssetModDateComparator (String JavaDoc direction) {
24         orderType = direction;
25     }
26     
27     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
28
29         try {
30
31                 int result;
32                 
33                 WebAsset w1 = (WebAsset) o1;
34                 WebAsset w2 = (WebAsset) o2;
35                 
36                 result = (w1.getModDate().equals(w2.getModDate())) ? 0 : (w1.getModDate().before(w2.getModDate())) ? -1 : 1;
37
38                 if (orderType.equals("asc"))
39                     return -result;
40                 else
41                     return result;
42                 
43             } catch (ClassCastException JavaDoc e) {
44             }
45         return 0;
46     }
47 }
48
Popular Tags