tmf: Simple warning fixes in tmf.core and tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / util / SortAsyncForBackward.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
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
9 *
10 * Contributors:
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 /**
23 * Asynchronous message comparator.
24 *
25 * Compares two asyncMessages only taking into account the event occurrence when their
26 * appear.<br>
27 *
28 * Used to order the AsyncMessage list insuring that the previous node has both of his ends smaller than the current node
29 *
30 * @version 1.0
31 * @author sveyrier
32 *
33 */
34 public class SortAsyncForBackward implements Comparator<GraphNode>, Serializable {
35
36 // ------------------------------------------------------------------------
37 // Constants
38 // ------------------------------------------------------------------------
39 /**
40 * Serial version UID
41 */
42 private static final long serialVersionUID = 603959931263853359L;
43
44 // ------------------------------------------------------------------------
45 // Methods
46 // ------------------------------------------------------------------------
47
48 /*
49 * (non-Javadoc)
50 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
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
60 if (m1.getStartOccurrence() > m1.getEndOccurrence()) {
61 m1Max = m1.getStartOccurrence();
62 } else {
63 m1Max = m1.getEndOccurrence();
64 }
65 if (m2.getStartOccurrence() > m2.getEndOccurrence()) {
66 m2Max = m2.getStartOccurrence();
67 } else {
68 m2Max = m2.getEndOccurrence();
69 }
70
71 int m1Min, m2Min;
72 // Search for the smaller event occurrence for each messages
73 if (m1.getStartOccurrence() > m1.getEndOccurrence()) {
74 m1Min = m1.getEndOccurrence();
75 } else {
76 m1Min = m1.getStartOccurrence();
77 }
78 if (m2.getStartOccurrence() > m2.getEndOccurrence()) {
79 m2Min = m2.getEndOccurrence();
80 } else {
81 m2Min = m2.getStartOccurrence();
82 }
83
84 if (m1Max > m2Max) {
85 return 1;
86 } else if (m1Max == m2Max) {
87 if (m1Min == m2Min) {
88 return 0;
89 } else if (m1Min > m2Min) {
90 return -1;
91 } else {
92 return 1;
93 }
94 } else {
95 return -1;
96 }
97 } else {
98 return 0;
99 }
100 }
101
102 }
This page took 0.031961 seconds and 5 git commands to generate.