tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / util / SortAsyncForBackward.java
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
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
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.
23 *
24 * Compares two asyncMessages only taking into account the event occurrence when their
25 * appear.<br>
26 *
27 * Used to order the AsyncMessage list insuring that the previous node has both of his ends smaller than the current node
28 *
29 * @version 1.0
30 * @author sveyrier
31 *
32 */
33 public class SortAsyncForBackward implements Comparator<GraphNode>, Serializable {
34
35 // ------------------------------------------------------------------------
36 // Constants
37 // ------------------------------------------------------------------------
38 /**
39 * Serial version UID
40 */
41 private static final long serialVersionUID = 603959931263853359L;
42
43 // ------------------------------------------------------------------------
44 // Methods
45 // ------------------------------------------------------------------------
46
47 /*
48 * (non-Javadoc)
49 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
50 */
51 @Override
52 public int compare(GraphNode arg0, GraphNode arg1) {
53 if (arg0 instanceof AsyncMessage && arg1 instanceof AsyncMessage) {
54 AsyncMessage m1 = (AsyncMessage) arg0;
55 AsyncMessage m2 = (AsyncMessage) arg1;
56 int m1Max, m2Max;
57 // AsyncMessage has two ends which may have different event occurrences
58 // Search for the greater event occurrence for each messages
59 if (m1.getStartOccurrence() > m1.getEndOccurrence()) {
60 m1Max = m1.getStartOccurrence();
61 } else {
62 m1Max = m1.getEndOccurrence();
63 }
64 if (m2.getStartOccurrence() > m2.getEndOccurrence()) {
65 m2Max = m2.getStartOccurrence();
66 } else {
67 m2Max = m2.getEndOccurrence();
68 }
69
70 int m1Min, m2Min;
71 // Search for the smaller event occurrence for each messages
72 if (m1.getStartOccurrence() > m1.getEndOccurrence()) {
73 m1Min = m1.getEndOccurrence();
74 } else {
75 m1Min = m1.getStartOccurrence();
76 }
77 if (m2.getStartOccurrence() > m2.getEndOccurrence()) {
78 m2Min = m2.getEndOccurrence();
79 } else {
80 m2Min = m2.getStartOccurrence();
81 }
82
83 if (m1Max > m2Max) {
84 return 1;
85 } else if (m1Max == m2Max) {
86 if (m1Min == m2Min) {
87 return 0;
88 } else if (m1Min > m2Min) {
89 return -1;
90 } else {
91 return 1;
92 }
93 } else {
94 return -1;
95 }
96 }
97 return 0;
98 }
99
100 }
This page took 0.057461 seconds and 5 git commands to generate.