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
.tmf
.core
.trace
.ITmfTrace
;
15 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
18 * ControlFlowEntry comparators. These do not allow for null arguments.
20 * @author Bernd Hufmann
21 * @noimplement This interface only contains static definitions.
23 public interface IControlFlowEntryComparator
{
26 * Process Name Comparator
28 Comparator
<ITimeGraphEntry
> PROCESS_NAME_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
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();
34 return o1
.getName().compareTo(o2
.getName());
41 Comparator
<ITimeGraphEntry
> TID_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
43 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
44 if (o1
== null || o2
== null) {
45 throw new IllegalArgumentException();
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());
58 * Parent ThreadID Comparator
60 Comparator
<ITimeGraphEntry
> PTID_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
62 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
63 if (o1
== null || o2
== null) {
64 throw new IllegalArgumentException();
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());
77 * Birth time Comparator
79 Comparator
<ITimeGraphEntry
> BIRTH_TIME_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
81 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
82 if (o1
== null || o2
== null) {
83 throw new IllegalArgumentException();
85 return Long
.compare(o1
.getStartTime(), o2
.getStartTime());
90 * Trace Comparator (uses trace start time and name)
92 Comparator
<ITimeGraphEntry
> TRACE_COMPARATOR
= new Comparator
<ITimeGraphEntry
>() {
94 public int compare(@Nullable ITimeGraphEntry o1
, @Nullable ITimeGraphEntry o2
) {
95 if (o1
== null || o2
== null) {
96 throw new IllegalArgumentException();
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());
104 result
= trace1
.getName().compareTo(trace2
.getName());