KickJava   Java API By Example, From Geeks To Geeks.

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


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

16 public class WebAssetTitleComparator implements Comparator JavaDoc {
17
18     private String JavaDoc orderType = "";
19
20     public WebAssetTitleComparator(String JavaDoc orderType) {
21         super();
22         this.orderType = orderType;
23     }
24
25     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
26
27         try {
28             WebAsset w1 = (WebAsset) o1;
29             WebAsset w2 = (WebAsset) o2;
30
31             User user1 = PublicUserFactory.getUserByUserId(w1.getModUser());
32             User user2 = PublicUserFactory.getUserByUserId(w2.getModUser());
33             
34             int ret = user1.getFullName().compareTo(user2.getFullName());
35
36             if (orderType.equals("asc")) {
37                 return ret;
38             }
39
40             return ret * -1;
41
42         } catch (ClassCastException JavaDoc e) {
43
44         }
45         return 0;
46     }
47 }
Popular Tags