KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > server > list > StandardMessageComparator


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.server.list;
8
9 import java.util.Comparator JavaDoc;
10
11 import org.jboss.jms.server.MessageReference;
12
13 /**
14  * A comparator that implements standard message ordering
15  *
16  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
17  * @version $Revision: 1.1 $
18  */

19 public class StandardMessageComparator
20    implements Comparator JavaDoc
21 {
22    // Constants -----------------------------------------------------
23

24    // Attributes ----------------------------------------------------
25

26    // Static --------------------------------------------------------
27

28    // Constructors --------------------------------------------------
29

30    // Public --------------------------------------------------------
31

32    // Comparator implementation -------------------------------------
33

34    public int compare(Object JavaDoc o1, Object JavaDoc o2)
35    {
36       try
37       {
38          MessageReference r1 = (MessageReference) o1;
39          MessageReference r2 = (MessageReference) o2;
40          int p1 = r1.getPriority();
41          int p2 = r2.getPriority();
42          if (p1 != p2) return p2-p1;
43          String JavaDoc l1 = r1.getMessageID();
44          String JavaDoc l2 = r2.getMessageID();
45          return l1.compareTo(l2);
46       }
47       catch (Exception JavaDoc e)
48       {
49          throw new RuntimeException JavaDoc("Error during comparison", e);
50       }
51    }
52
53    // Protected ------------------------------------------------------
54

55    // Package Private ------------------------------------------------
56

57    // Private --------------------------------------------------------
58

59    // Inner Classes --------------------------------------------------
60

61 }
62
Popular Tags