View Javadoc

1   /*
2    * $Id: CorrelationSequenceComparator.java 18181 2010-07-13 13:46:53Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.correlation;
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<MuleEvent>
22  {
23      public int compare(MuleEvent event1, MuleEvent event2)
24      {
25          int val1 = event1.getMessage().getCorrelationSequence();
26          int val2 = event2.getMessage().getCorrelationSequence();
27  
28          if (val1 == val2)
29          {
30              return 0;
31          }
32          else if (val1 > val2)
33          {
34              return 1;
35          }
36          else
37          {
38              return -1;
39          }
40      }
41  }