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 / LamiTimeRangeEndAspect.java
CommitLineData
4208b510
AM
1/*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir
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
10package org.eclipse.tracecompass.internal.provisional.analysis.lami.core.aspect;
11
12import java.util.Comparator;
13
14import org.eclipse.jdt.annotation.NonNull;
15import org.eclipse.jdt.annotation.Nullable;
16import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiTableEntry;
17import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiData;
18import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiTimeRange;
19import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
20
21/**
22 * Aspect for a time range duration
23 *
24 * @author Alexandre Montplaisir
25 */
26public class LamiTimeRangeEndAspect extends LamiTableEntryAspect {
27
28 private final int fColIndex;
29
30 /**
31 * Constructor
32 *
33 * @param timeRangeName
34 * Name of the time range
35 * @param colIndex
36 * Column index
37 */
38 public LamiTimeRangeEndAspect(String timeRangeName, int colIndex) {
39 super(timeRangeName + " (" + Messages.LamiAspect_TimeRangeEnd + ')', null); //$NON-NLS-1$
40 fColIndex = colIndex;
41 }
42
43 @Override
44 public boolean isContinuous() {
45 return true;
46 }
47
48 @Override
49 public @Nullable String resolveString(LamiTableEntry entry) {
50 LamiData data = entry.getValue(fColIndex);
51 if (data instanceof LamiTimeRange) {
52 LamiTimeRange range = (LamiTimeRange) data;
53 return TmfTimestampFormat.getDefaulTimeFormat().format(range.getEnd());
54 }
55 return data.toString();
56 }
57
58 @Override
59 public boolean isTimeStamp() {
60 return true;
61 }
62
63 @Override
5b973e7c 64 public @Nullable Number resolveNumber(@NonNull LamiTableEntry entry) {
4208b510
AM
65 LamiData data = entry.getValue(fColIndex);
66 if (data instanceof LamiTimeRange) {
67 LamiTimeRange range = (LamiTimeRange) data;
5b973e7c 68 return Long.valueOf(range.getEnd());
4208b510
AM
69 }
70 return null;
71 }
72
73 @Override
74 public Comparator<LamiTableEntry> getComparator() {
75 return (o1, o2) -> {
5b973e7c
JR
76 Number d1 = resolveNumber(o1);
77 Number d2 = resolveNumber(o2);
78
79 if (d1 == null && d2 == null) {
4208b510
AM
80 return 0;
81 }
5b973e7c
JR
82 if (d1 == null) {
83 return 1;
84 }
85
86 if (d2 == null) {
87 return -1;
88 }
4208b510 89
5b973e7c 90 return Long.compare(d1.longValue(), d2.longValue());
4208b510
AM
91 };
92 }
93
94}
This page took 0.029318 seconds and 5 git commands to generate.