View Javadoc

1   /*
2    * $Id: CorrelationSequenceComparator.java 10489 2008-01-23 17:53:38Z dfeist $
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.api.MuleEvent;
14  
15  import java.util.Comparator;
16  
17  /**
18   * <code>CorrelationSequenceComparator</code> is a {@link Comparator} for
19   * {@link MuleEvent}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 = ((MuleEvent)o1).getMessage().getCorrelationSequence();
32          int val2 = ((MuleEvent)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  }