View Javadoc

1   /*
2    * $Id: CorrelationSequenceComparator.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.routing.inbound;
12  
13  import org.mule.umo.UMOEvent;
14  
15  import java.util.Comparator;
16  
17  /**
18   * <code>CorrelationSequenceComparator</code> is a {@link Comparator} for
19   * {@link UMOEvent}s using their respective correlation sequences.
20   */
21  public final class CorrelationSequenceComparator implements Comparator
22  {
23  
24      public CorrelationSequenceComparator()
25      {
26          super();
27      }
28  
29      public int compare(Object o1, Object o2)
30      {
31          int val1 = ((UMOEvent)o1).getMessage().getCorrelationSequence();
32          int val2 = ((UMOEvent)o2).getMessage().getCorrelationSequence();
33  
34          if (val1 == val2)
35          {
36              return 0;
37          }
38          else if (val1 > val2)
39          {
40              return 1;
41          }
42          else
43          {
44              return -1;
45          }
46      }
47  
48  }