Commit | Line | Data |
---|---|---|
a4cddcbc BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | *******************************************************************************/ | |
9 | package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow; | |
10 | ||
11 | import java.util.Comparator; | |
12 | ||
13 | import org.eclipse.jdt.annotation.Nullable; | |
a4cddcbc BH |
14 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
15 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
16 | ||
17 | /** | |
18 | * ControlFlowEntry comparators. These do not allow for null arguments. | |
19 | * | |
20 | * @author Bernd Hufmann | |
21 | * @noimplement This interface only contains static definitions. | |
22 | */ | |
23 | public interface IControlFlowEntryComparator { | |
24 | ||
25 | /** | |
26 | * Process Name Comparator | |
27 | */ | |
28 | Comparator<ITimeGraphEntry> PROCESS_NAME_COMPARATOR = new Comparator<ITimeGraphEntry>() { | |
29 | @Override | |
30 | public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) { | |
31 | if (o1 == null || o2 == null || o1.getName() == null || o2.getName() == null) { | |
32 | throw new IllegalArgumentException(); | |
33 | } | |
34 | return o1.getName().compareTo(o2.getName()); | |
35 | } | |
36 | }; | |
37 | ||
38 | /** | |
39 | * TreadID Comparator | |
40 | */ | |
41 | Comparator<ITimeGraphEntry> TID_COMPARATOR = new Comparator<ITimeGraphEntry>() { | |
42 | @Override | |
43 | public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) { | |
44 | if (o1 == null || o2 == null) { | |
45 | throw new IllegalArgumentException(); | |
46 | } | |
47 | int result = 0; | |
48 | if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) { | |
49 | ControlFlowEntry entry1 = (ControlFlowEntry) o1; | |
50 | ControlFlowEntry entry2 = (ControlFlowEntry) o2; | |
51 | result = Integer.compare(entry1.getThreadId(), entry2.getThreadId()); | |
52 | } | |
53 | return result; | |
54 | } | |
55 | }; | |
56 | ||
57 | /** | |
58 | * Parent ThreadID Comparator | |
59 | */ | |
60 | Comparator<ITimeGraphEntry> PTID_COMPARATOR = new Comparator<ITimeGraphEntry>() { | |
61 | @Override | |
62 | public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) { | |
63 | if (o1 == null || o2 == null) { | |
64 | throw new IllegalArgumentException(); | |
65 | } | |
66 | int result = 0; | |
67 | if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) { | |
68 | ControlFlowEntry entry1 = (ControlFlowEntry) o1; | |
69 | ControlFlowEntry entry2 = (ControlFlowEntry) o2; | |
70 | result = Integer.compare(entry1.getParentThreadId(), entry2.getParentThreadId()); | |
71 | } | |
72 | return result; | |
73 | } | |
74 | }; | |
75 | ||
76 | /** | |
77 | * Birth time Comparator | |
78 | */ | |
79 | Comparator<ITimeGraphEntry> BIRTH_TIME_COMPARATOR = new Comparator<ITimeGraphEntry>() { | |
80 | @Override | |
81 | public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) { | |
82 | if (o1 == null || o2 == null) { | |
83 | throw new IllegalArgumentException(); | |
84 | } | |
85 | return Long.compare(o1.getStartTime(), o2.getStartTime()); | |
86 | } | |
87 | }; | |
88 | ||
89 | /** | |
90 | * Trace Comparator (uses trace start time and name) | |
91 | */ | |
92 | Comparator<ITimeGraphEntry> TRACE_COMPARATOR = new Comparator<ITimeGraphEntry>() { | |
93 | @Override | |
94 | public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) { | |
95 | if (o1 == null || o2 == null) { | |
96 | throw new IllegalArgumentException(); | |
97 | } | |
98 | int result = 0; | |
99 | if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) { | |
100 | ITmfTrace trace1 = ((ControlFlowEntry) o1).getTrace(); | |
101 | ITmfTrace trace2 = ((ControlFlowEntry) o2).getTrace(); | |
102 | result = trace1.getStartTime().compareTo(trace2.getStartTime()); | |
103 | if (result == 0) { | |
104 | result = trace1.getName().compareTo(trace2.getName()); | |
105 | } | |
106 | } | |
107 | return result; | |
108 | } | |
109 | }; | |
110 | ||
111 | } |