Improve test cases, speed and accuracy.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / util / SortAsyncForBackward.java
CommitLineData
73005152
BH
1/**********************************************************************
2 * Copyright (c) 2005, 2006, 2011 IBM Corporation and others.
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 * $Id: SortAsyncForBackward.java,v 1.2 2006/09/20 20:56:27 ewchan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.util;
14
15import java.io.Serializable;
16import java.util.Comparator;
17
18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage;
19import 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 * @author sveyrier
30 *
31 */
32public class SortAsyncForBackward implements Comparator<GraphNode>, Serializable {
33
34 /**
35 * Serial version UID
36 */
37 private static final long serialVersionUID = 603959931263853359L;
38
39 /**
40 * Compares two asynchronous messages Returns 0 (equal) if one of the message is not asynchronous
41 *
42 * @return 1 if arg0 is greater, 0 if equal, -1 otherwise
43 */
44 @Override
45 public int compare(GraphNode arg0, GraphNode arg1) {
46 if (arg0 instanceof AsyncMessage && arg1 instanceof AsyncMessage) {
47 AsyncMessage m1 = (AsyncMessage) arg0;
48 AsyncMessage m2 = (AsyncMessage) arg1;
49 int m1Max, m2Max;
50 // AsyncMessage has two ends which may have different event occurrences
51 // Search for the greater event occurrence for each messages
52 if (m1.getStartOccurrence() > m1.getEndOccurrence())
53 m1Max = m1.getStartOccurrence();
54 else
55 m1Max = m1.getEndOccurrence();
56 if (m2.getStartOccurrence() > m2.getEndOccurrence())
57 m2Max = m2.getStartOccurrence();
58 else
59 m2Max = m2.getEndOccurrence();
60
61 int m1Min, m2Min;
62 // Search for the smaller event occurrence for each messages
63 if (m1.getStartOccurrence() > m1.getEndOccurrence())
64 m1Min = m1.getEndOccurrence();
65 else
66 m1Min = m1.getStartOccurrence();
67 if (m2.getStartOccurrence() > m2.getEndOccurrence())
68 m2Min = m2.getEndOccurrence();
69 else
70 m2Min = m2.getStartOccurrence();
71
72 if (m1Max > m2Max)
73 return 1;
74 else if (m1Max == m2Max)
75 if (m1Min == m2Min)
76 return 0;
77 else if (m1Min > m2Min)
78 return -1;
79 else
80 return 1;
81 else
82 return -1;
83 } else
84 return 0;
85 }
86
87}
This page took 0.031586 seconds and 5 git commands to generate.