68424f33ad8df2cf355fb67e5a819f8a09dbb211
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / internal / analysis / os / linux / ui / views / controlflow / IControlFlowEntryComparator.java
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;
14 import org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow.ControlFlowEntry;
15 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
16 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
17
18 /**
19 * ControlFlowEntry comparators. These do not allow for null arguments.
20 *
21 * @author Bernd Hufmann
22 * @noimplement This interface only contains static definitions.
23 */
24 public interface IControlFlowEntryComparator {
25
26 /**
27 * Process Name Comparator
28 */
29 Comparator<ITimeGraphEntry> PROCESS_NAME_COMPARATOR = new Comparator<ITimeGraphEntry>() {
30 @Override
31 public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
32 if (o1 == null || o2 == null || o1.getName() == null || o2.getName() == null) {
33 throw new IllegalArgumentException();
34 }
35 return o1.getName().compareTo(o2.getName());
36 }
37 };
38
39 /**
40 * TreadID Comparator
41 */
42 Comparator<ITimeGraphEntry> TID_COMPARATOR = new Comparator<ITimeGraphEntry>() {
43 @Override
44 public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
45 if (o1 == null || o2 == null) {
46 throw new IllegalArgumentException();
47 }
48 int result = 0;
49 if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {
50 ControlFlowEntry entry1 = (ControlFlowEntry) o1;
51 ControlFlowEntry entry2 = (ControlFlowEntry) o2;
52 result = Integer.compare(entry1.getThreadId(), entry2.getThreadId());
53 }
54 return result;
55 }
56 };
57
58 /**
59 * Parent ThreadID Comparator
60 */
61 Comparator<ITimeGraphEntry> PTID_COMPARATOR = new Comparator<ITimeGraphEntry>() {
62 @Override
63 public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
64 if (o1 == null || o2 == null) {
65 throw new IllegalArgumentException();
66 }
67 int result = 0;
68 if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {
69 ControlFlowEntry entry1 = (ControlFlowEntry) o1;
70 ControlFlowEntry entry2 = (ControlFlowEntry) o2;
71 result = Integer.compare(entry1.getParentThreadId(), entry2.getParentThreadId());
72 }
73 return result;
74 }
75 };
76
77 /**
78 * Birth time Comparator
79 */
80 Comparator<ITimeGraphEntry> BIRTH_TIME_COMPARATOR = new Comparator<ITimeGraphEntry>() {
81 @Override
82 public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
83 if (o1 == null || o2 == null) {
84 throw new IllegalArgumentException();
85 }
86 return Long.compare(o1.getStartTime(), o2.getStartTime());
87 }
88 };
89
90 /**
91 * Trace Comparator (uses trace start time and name)
92 */
93 Comparator<ITimeGraphEntry> TRACE_COMPARATOR = new Comparator<ITimeGraphEntry>() {
94 @Override
95 public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
96 if (o1 == null || o2 == null) {
97 throw new IllegalArgumentException();
98 }
99 int result = 0;
100 if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {
101 ITmfTrace trace1 = ((ControlFlowEntry) o1).getTrace();
102 ITmfTrace trace2 = ((ControlFlowEntry) o2).getTrace();
103 result = trace1.getStartTime().compareTo(trace2.getStartTime());
104 if (result == 0) {
105 result = trace1.getName().compareTo(trace2.getName());
106 }
107 }
108 return result;
109 }
110 };
111
112 }
This page took 0.032991 seconds and 4 git commands to generate.