1 /**********************************************************************
2 * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
;
15 import java
.io
.Serializable
;
16 import java
.util
.Comparator
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessage
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
22 * Asynchronous message comparator Compare two AsyncMessages only taking into account the event occurrence when their
25 * Used to order the AsyncMessage list insuring that next node has one of his ends greater than the current node
31 public class SortAsyncMessageComparator
implements Comparator
<GraphNode
>, Serializable
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
39 private static final long serialVersionUID
= 1L;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
49 public int compare(GraphNode arg0
, GraphNode arg1
) {
50 if (arg0
instanceof AsyncMessage
&& arg1
instanceof AsyncMessage
) {
51 AsyncMessage m1
= (AsyncMessage
) arg0
;
52 AsyncMessage m2
= (AsyncMessage
) arg1
;
54 // AsyncMessage has two ends which may have different event occurrences
55 // Search for the smaller event occurrence for each messages
56 if (m1
.getStartOccurrence() > m1
.getEndOccurrence()) {
57 m1Min
= m1
.getEndOccurrence();
59 m1Min
= m1
.getStartOccurrence();
61 if (m2
.getStartOccurrence() > m2
.getEndOccurrence()) {
62 m2Min
= m2
.getEndOccurrence();
64 m2Min
= m2
.getStartOccurrence();
68 // Search for the greater event occurrence for each messages
69 if (m1
.getStartOccurrence() > m1
.getEndOccurrence()) {
70 m1Max
= m1
.getStartOccurrence();
72 m1Max
= m1
.getEndOccurrence();
74 if (m2
.getStartOccurrence() > m2
.getEndOccurrence()) {
75 m2Max
= m2
.getStartOccurrence();
77 m2Max
= m2
.getEndOccurrence();
82 } else if ((m1Min
== m2Min
)) {
85 } else if (m1Max
> m2Max
) {