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 | /** | |
abbdd66a AM |
22 | * Asynchronous message comparator. |
23 | * | |
73005152 BH |
24 | * Compares two asyncMessages only taking into account the event occurrence when their |
25 | * appear.<br> | |
abbdd66a | 26 | * |
73005152 | 27 | * Used to order the AsyncMessage list insuring that the previous node has both of his ends smaller than the current node |
abbdd66a | 28 | * |
df0b8ff4 | 29 | * @version 1.0 |
73005152 | 30 | * @author sveyrier |
abbdd66a | 31 | * |
73005152 BH |
32 | */ |
33 | public class SortAsyncForBackward implements Comparator<GraphNode>, Serializable { | |
abbdd66a | 34 | |
df0b8ff4 BH |
35 | // ------------------------------------------------------------------------ |
36 | // Constants | |
37 | // ------------------------------------------------------------------------ | |
73005152 BH |
38 | /** |
39 | * Serial version UID | |
40 | */ | |
41 | private static final long serialVersionUID = 603959931263853359L; | |
42 | ||
df0b8ff4 BH |
43 | // ------------------------------------------------------------------------ |
44 | // Methods | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
73005152 BH |
47 | @Override |
48 | public int compare(GraphNode arg0, GraphNode arg1) { | |
49 | if (arg0 instanceof AsyncMessage && arg1 instanceof AsyncMessage) { | |
50 | AsyncMessage m1 = (AsyncMessage) arg0; | |
51 | AsyncMessage m2 = (AsyncMessage) arg1; | |
52 | int m1Max, m2Max; | |
53 | // AsyncMessage has two ends which may have different event occurrences | |
54 | // Search for the greater event occurrence for each messages | |
df0b8ff4 | 55 | if (m1.getStartOccurrence() > m1.getEndOccurrence()) { |
73005152 | 56 | m1Max = m1.getStartOccurrence(); |
df0b8ff4 | 57 | } else { |
73005152 | 58 | m1Max = m1.getEndOccurrence(); |
df0b8ff4 BH |
59 | } |
60 | if (m2.getStartOccurrence() > m2.getEndOccurrence()) { | |
73005152 | 61 | m2Max = m2.getStartOccurrence(); |
df0b8ff4 | 62 | } else { |
73005152 | 63 | m2Max = m2.getEndOccurrence(); |
df0b8ff4 | 64 | } |
73005152 BH |
65 | |
66 | int m1Min, m2Min; | |
67 | // Search for the smaller event occurrence for each messages | |
df0b8ff4 | 68 | if (m1.getStartOccurrence() > m1.getEndOccurrence()) { |
73005152 | 69 | m1Min = m1.getEndOccurrence(); |
df0b8ff4 | 70 | } else { |
73005152 | 71 | m1Min = m1.getStartOccurrence(); |
df0b8ff4 BH |
72 | } |
73 | if (m2.getStartOccurrence() > m2.getEndOccurrence()) { | |
73005152 | 74 | m2Min = m2.getEndOccurrence(); |
df0b8ff4 | 75 | } else { |
73005152 | 76 | m2Min = m2.getStartOccurrence(); |
df0b8ff4 | 77 | } |
73005152 | 78 | |
df0b8ff4 | 79 | if (m1Max > m2Max) { |
73005152 | 80 | return 1; |
df0b8ff4 BH |
81 | } else if (m1Max == m2Max) { |
82 | if (m1Min == m2Min) { | |
73005152 | 83 | return 0; |
df0b8ff4 | 84 | } else if (m1Min > m2Min) { |
73005152 | 85 | return -1; |
df0b8ff4 | 86 | } else { |
73005152 | 87 | return 1; |
df0b8ff4 BH |
88 | } |
89 | } else { | |
73005152 | 90 | return -1; |
df0b8ff4 | 91 | } |
df0b8ff4 | 92 | } |
abbdd66a | 93 | return 0; |
73005152 BH |
94 | } |
95 | ||
96 | } |