Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
11252342 | 2 | * Copyright (c) 2005, 2013 IBM Corporation, Ericsson |
73005152 BH |
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 | |
abbdd66a AM |
7 | * |
8 | * Contributors: | |
c8422608 AM |
9 | * IBM - Initial API and implementation |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
73005152 BH |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.util; |
14 | ||
15 | import java.io.Serializable; | |
16 | import java.util.Comparator; | |
17 | ||
18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage; | |
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
20 | ||
21 | /** | |
22 | * Asynchronous message comparator Compare two AsyncMessages only taking into account the event occurrence when their | |
23 | * appear.<br> | |
abbdd66a | 24 | * |
73005152 | 25 | * Used to order the AsyncMessage list insuring that next node has one of his ends greater than the current node |
abbdd66a | 26 | * |
df0b8ff4 | 27 | * @version 1.0 |
73005152 | 28 | * @author sveyrier |
abbdd66a | 29 | * |
73005152 BH |
30 | */ |
31 | public class SortAsyncMessageComparator implements Comparator<GraphNode>, Serializable { | |
32 | ||
df0b8ff4 BH |
33 | // ------------------------------------------------------------------------ |
34 | // Constants | |
35 | // ------------------------------------------------------------------------ | |
73005152 BH |
36 | /** |
37 | * Serial version UID | |
38 | */ | |
39 | private static final long serialVersionUID = 1L; | |
40 | ||
df0b8ff4 BH |
41 | // ------------------------------------------------------------------------ |
42 | // Methods | |
43 | // ------------------------------------------------------------------------ | |
11252342 | 44 | |
73005152 BH |
45 | @Override |
46 | public int compare(GraphNode arg0, GraphNode arg1) { | |
47 | if (arg0 instanceof AsyncMessage && arg1 instanceof AsyncMessage) { | |
48 | AsyncMessage m1 = (AsyncMessage) arg0; | |
49 | AsyncMessage m2 = (AsyncMessage) arg1; | |
50 | int m1Min, m2Min; | |
51 | // AsyncMessage has two ends which may have different event occurrences | |
52 | // Search for the smaller event occurrence for each messages | |
df0b8ff4 | 53 | if (m1.getStartOccurrence() > m1.getEndOccurrence()) { |
73005152 | 54 | m1Min = m1.getEndOccurrence(); |
df0b8ff4 | 55 | } else { |
73005152 | 56 | m1Min = m1.getStartOccurrence(); |
df0b8ff4 BH |
57 | } |
58 | if (m2.getStartOccurrence() > m2.getEndOccurrence()) { | |
73005152 | 59 | m2Min = m2.getEndOccurrence(); |
df0b8ff4 | 60 | } else { |
73005152 | 61 | m2Min = m2.getStartOccurrence(); |
df0b8ff4 | 62 | } |
73005152 BH |
63 | |
64 | int m1Max, m2Max; | |
65 | // Search for the greater event occurrence for each messages | |
df0b8ff4 | 66 | if (m1.getStartOccurrence() > m1.getEndOccurrence()) { |
73005152 | 67 | m1Max = m1.getStartOccurrence(); |
df0b8ff4 | 68 | } else { |
73005152 | 69 | m1Max = m1.getEndOccurrence(); |
df0b8ff4 BH |
70 | } |
71 | if (m2.getStartOccurrence() > m2.getEndOccurrence()) { | |
73005152 | 72 | m2Max = m2.getStartOccurrence(); |
df0b8ff4 | 73 | } else { |
73005152 | 74 | m2Max = m2.getEndOccurrence(); |
df0b8ff4 | 75 | } |
73005152 | 76 | |
df0b8ff4 | 77 | if (m1Min > m2Min) { |
73005152 | 78 | return 1; |
df0b8ff4 BH |
79 | } else if ((m1Min == m2Min)) { |
80 | if (m1Max == m2Max) { | |
73005152 | 81 | return 0; |
df0b8ff4 | 82 | } else if (m1Max > m2Max) { |
73005152 | 83 | return -1; |
df0b8ff4 | 84 | } else { |
73005152 | 85 | return 1; |
df0b8ff4 BH |
86 | } |
87 | } else { | |
73005152 | 88 | return -1; |
df0b8ff4 | 89 | } |
df0b8ff4 | 90 | } |
abbdd66a | 91 | return 0; |
73005152 BH |
92 | } |
93 | ||
94 | } |