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