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