KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.roller.pojos;
2
3
4 import java.io.Serializable JavaDoc;
5 import java.util.Comparator JavaDoc;
6
7 /** Compares referers based on day hits and then alphabetical order */
8 public class RefererComparator implements Comparator JavaDoc, Serializable JavaDoc
9 {
10     static final long serialVersionUID = -1658901752434218888L;
11     
12     public int compare(Object JavaDoc val1, Object JavaDoc val2)
13     throws ClassCastException JavaDoc
14     {
15         RefererData r1 = (RefererData)val1;
16         RefererData r2 = (RefererData)val2;
17         int hits1 = r1.getDayHits().intValue();
18         int hits2 = r2.getDayHits().intValue();
19
20         if (hits1 > hits2)
21         {
22             return -1;
23         }
24         else if (hits1 < hits2)
25         {
26             return 1;
27         }
28
29         // if hits are the same, return
30
// results of String.compareTo()
31
return r1.getRefererUrl().compareTo(r2.getRefererUrl());
32     }
33 }
34
Popular Tags