1 /**********************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
;
16 import java
.io
.Serializable
;
17 import java
.util
.Comparator
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessage
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
23 * Asynchronous message comparator Compare two AsyncMessages only taking into account the event occurrence when their
26 * Used to order the AsyncMessage list insuring that next node has one of his ends greater than the current node
32 public class SortAsyncMessageComparator
implements Comparator
<GraphNode
>, Serializable
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
40 private static final long serialVersionUID
= 1L;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
47 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
50 public int compare(GraphNode arg0
, GraphNode arg1
) {
51 if (arg0
instanceof AsyncMessage
&& arg1
instanceof AsyncMessage
) {
52 AsyncMessage m1
= (AsyncMessage
) arg0
;
53 AsyncMessage m2
= (AsyncMessage
) arg1
;
55 // AsyncMessage has two ends which may have different event occurrences
56 // Search for the smaller event occurrence for each messages
57 if (m1
.getStartOccurrence() > m1
.getEndOccurrence()) {
58 m1Min
= m1
.getEndOccurrence();
60 m1Min
= m1
.getStartOccurrence();
62 if (m2
.getStartOccurrence() > m2
.getEndOccurrence()) {
63 m2Min
= m2
.getEndOccurrence();
65 m2Min
= m2
.getStartOccurrence();
69 // Search for the greater event occurrence for each messages
70 if (m1
.getStartOccurrence() > m1
.getEndOccurrence()) {
71 m1Max
= m1
.getStartOccurrence();
73 m1Max
= m1
.getEndOccurrence();
75 if (m2
.getStartOccurrence() > m2
.getEndOccurrence()) {
76 m2Max
= m2
.getStartOccurrence();
78 m2Max
= m2
.getEndOccurrence();
83 } else if ((m1Min
== m2Min
)) {
86 } else if (m1Max
> m2Max
) {