analysis.lami: correctly handle Number (double, long etc.) type graphing
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.core / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / core / aspect / LamiIRQNumberAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Philippe Proulx
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
10 package org.eclipse.tracecompass.internal.provisional.analysis.lami.core.aspect;
11
12 import java.util.Comparator;
13
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiTableEntry;
16 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiData;
17 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiIRQ;
18
19 /**
20 * Aspect for the IRQ numbers.
21 *
22 * This resolves the IRQ number for a given table, so 0|timer would return 0.
23 *
24 * @author Philippe Proulx
25 */
26 public class LamiIRQNumberAspect extends LamiTableEntryAspect {
27
28 private final int fColIndex;
29
30 /**
31 * Constructor
32 *
33 * @param colName
34 * Column name
35 * @param colIndex
36 * Column index
37 */
38 public LamiIRQNumberAspect(String colName, int colIndex) {
39 super(colName + " (#)", null); //$NON-NLS-1$
40 fColIndex = colIndex;
41 }
42
43 @Override
44 public boolean isContinuous() {
45 return false;
46 }
47
48 @Override
49 public boolean isTimeStamp() {
50 return false;
51 }
52
53 @Override
54 public @Nullable String resolveString(LamiTableEntry entry) {
55 LamiData data = entry.getValue(fColIndex);
56 if (data instanceof LamiIRQ) {
57 return String.valueOf(((LamiIRQ) data).getNumber());
58 }
59 /* Could be null, unknown, etc. */
60 return data.toString();
61 }
62
63 @Override
64 public @Nullable Number resolveNumber(LamiTableEntry entry) {
65 LamiData data = entry.getValue(fColIndex);
66 if (data instanceof LamiIRQ) {
67 return (((LamiIRQ) data).getNumber());
68 }
69
70 return null;
71 }
72
73 @Override
74 public Comparator<LamiTableEntry> getComparator() {
75 return (o1, o2) -> {
76 Number d1 = resolveNumber(o1);
77 Number d2 = resolveNumber(o2);
78
79 if (d1 == null && d2 == null) {
80 return 0;
81 }
82 if (d1 == null) {
83 return 1;
84 }
85
86 if (d2 == null) {
87 return -1;
88 }
89
90 return Integer.compare(d1.intValue(), d2.intValue());
91 };
92 }
93
94 }
This page took 0.033903 seconds and 5 git commands to generate.