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