Commit | Line | Data |
---|---|---|
73005152 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2005, 2006 IBM Corporation and others. | |
df0b8ff4 | 3 | * Copyright (c) 2011, 2012 Ericsson. |
013a5f1c | 4 | * |
73005152 BH |
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 | |
013a5f1c AM |
9 | * |
10 | * Contributors: | |
73005152 BH |
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.GraphNode; | |
20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage; | |
21 | ||
22 | /** | |
23 | * Synchronous message comparator Compare two syncMessages only taking into account the event occurrence when their | |
24 | * appear.<br> | |
013a5f1c | 25 | * |
73005152 | 26 | * The message with the greater event occurrence is considered to be the greater.<br> |
013a5f1c AM |
27 | * |
28 | * @version 1.0 | |
73005152 | 29 | * @author sveyrier |
013a5f1c | 30 | * |
73005152 BH |
31 | */ |
32 | public class SortSyncMessageComparator implements Comparator<GraphNode>, Serializable { | |
33 | ||
df0b8ff4 BH |
34 | // ------------------------------------------------------------------------ |
35 | // Constants | |
36 | // ------------------------------------------------------------------------ | |
73005152 BH |
37 | /** |
38 | * Serial version UID | |
39 | */ | |
40 | private static final long serialVersionUID = 4781250984753283718L; | |
41 | ||
df0b8ff4 BH |
42 | // ------------------------------------------------------------------------ |
43 | // Methods | |
44 | // ------------------------------------------------------------------------ | |
45 | /* | |
46 | * (non-Javadoc) | |
47 | * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) | |
73005152 BH |
48 | */ |
49 | @Override | |
50 | public int compare(GraphNode arg0, GraphNode arg1) { | |
51 | if (arg0 instanceof SyncMessage && arg1 instanceof SyncMessage) { | |
52 | SyncMessage m1 = (SyncMessage) arg0; | |
53 | SyncMessage m2 = (SyncMessage) arg1; | |
df0b8ff4 | 54 | if (m1.getEventOccurrence() > m2.getEventOccurrence()) { |
73005152 | 55 | return 1; |
df0b8ff4 | 56 | } else if (m1.getEventOccurrence() == m2.getEventOccurrence()) { |
73005152 | 57 | return 0; |
df0b8ff4 | 58 | } else { |
73005152 | 59 | return -1; |
df0b8ff4 BH |
60 | } |
61 | } else { | |
73005152 | 62 | return 0; |
df0b8ff4 | 63 | } |
73005152 | 64 | } |
73005152 | 65 | } |