Commit | Line | Data |
---|---|---|
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: SortAsyncMessageComparator.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 | **********************************************************************/ | |
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 Compare two AsyncMessages only taking into account the event occurrence when their | |
23 | * appear.<br> | |
24 | * | |
25 | * Used to order the AsyncMessage list insuring that next node has one of his ends greater than the current node | |
26 | * | |
27 | * @author sveyrier | |
28 | * | |
29 | */ | |
30 | public class SortAsyncMessageComparator implements Comparator<GraphNode>, Serializable { | |
31 | ||
32 | /** | |
33 | * Serial version UID | |
34 | */ | |
35 | private static final long serialVersionUID = 1L; | |
36 | ||
37 | /** | |
38 | * Compares two synchronous syncMessages Returns 0 (equal) if one of the message is not synchronous | |
39 | * | |
40 | * @return 1 if arg0 is greater, 0 if equal, -1 otherwise | |
41 | */ | |
42 | @Override | |
43 | public int compare(GraphNode arg0, GraphNode arg1) { | |
44 | if (arg0 instanceof AsyncMessage && arg1 instanceof AsyncMessage) { | |
45 | AsyncMessage m1 = (AsyncMessage) arg0; | |
46 | AsyncMessage m2 = (AsyncMessage) arg1; | |
47 | int m1Min, m2Min; | |
48 | // AsyncMessage has two ends which may have different event occurrences | |
49 | // Search for the smaller event occurrence for each messages | |
50 | if (m1.getStartOccurrence() > m1.getEndOccurrence()) | |
51 | m1Min = m1.getEndOccurrence(); | |
52 | else | |
53 | m1Min = m1.getStartOccurrence(); | |
54 | if (m2.getStartOccurrence() > m2.getEndOccurrence()) | |
55 | m2Min = m2.getEndOccurrence(); | |
56 | else | |
57 | m2Min = m2.getStartOccurrence(); | |
58 | ||
59 | int m1Max, m2Max; | |
60 | // Search for the greater event occurrence for each messages | |
61 | if (m1.getStartOccurrence() > m1.getEndOccurrence()) | |
62 | m1Max = m1.getStartOccurrence(); | |
63 | else | |
64 | m1Max = m1.getEndOccurrence(); | |
65 | if (m2.getStartOccurrence() > m2.getEndOccurrence()) | |
66 | m2Max = m2.getStartOccurrence(); | |
67 | else | |
68 | m2Max = m2.getEndOccurrence(); | |
69 | ||
70 | if (m1Min > m2Min) | |
71 | return 1; | |
72 | else if ((m1Min == m2Min)) | |
73 | if (m1Max == m2Max) | |
74 | return 0; | |
75 | else if (m1Max > m2Max) | |
76 | return -1; | |
77 | else | |
78 | return 1; | |
79 | else | |
80 | return -1; | |
81 | } else | |
82 | return 0; | |
83 | } | |
84 | ||
85 | } |