1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
;
11 import java
.util
.Comparator
;
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
;
19 * ControlFlowEntry comparators. These do not allow for null arguments.
21 * @author Bernd Hufmann
22 * @noimplement This interface only contains static definitions.
24 public interface IControlFlowEntryComparator
{
27 * Process Name Comparator
29 Comparator
<ITimeGraphEntry
> PROCESS_NAME_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
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();
35 return o1
.getName().compareTo(o2
.getName());
42 Comparator
<ITimeGraphEntry
> TID_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
44 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
45 if (o1
== null || o2
== null) {
46 throw new IllegalArgumentException();
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());
59 * Parent ThreadID Comparator
61 Comparator
<ITimeGraphEntry
> PTID_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
63 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
64 if (o1
== null || o2
== null) {
65 throw new IllegalArgumentException();
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());
78 * Birth time Comparator
80 Comparator
<ITimeGraphEntry
> BIRTH_TIME_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
82 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
83 if (o1
== null || o2
== null) {
84 throw new IllegalArgumentException();
86 return Long
.compare(o1
.getStartTime(), o2
.getStartTime());
91 * Trace Comparator (uses trace start time and name)
93 Comparator
<ITimeGraphEntry
> TRACE_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
95 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
96 if (o1
== null || o2
== null) {
97 throw new IllegalArgumentException();
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());
105 result
= trace1
.getName().compareTo(trace2
.getName());