KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > pojos > BookmarkComparator


1 package org.roller.pojos;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Comparator JavaDoc;
5
6 public class BookmarkComparator implements Comparator JavaDoc, Serializable JavaDoc
7 {
8     static final long serialVersionUID = 4009699640952161148L;
9     
10     public int compare(Object JavaDoc val1, Object JavaDoc val2)
11     throws ClassCastException JavaDoc
12     {
13         BookmarkData bd1 = (BookmarkData)val1;
14         BookmarkData bd2 = (BookmarkData)val2;
15         int priority1 = bd1.getPriority().intValue();
16         int priority2 = bd2.getPriority().intValue();
17
18         if (priority1 > priority2)
19         {
20             return 1;
21         }
22         else if (priority1 < priority2)
23         {
24             return -1;
25         }
26
27         // if priorities are the same, return
28
// results of String.compareTo()
29
return bd1.getName().compareTo(bd2.getName());
30
31     }
32
33 }
34
Popular Tags