abb160e4969bcef59550e895297847add10095b5
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.core / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / core / aspect / LamiTimeRangeBeginAspect.java
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
10 package org.eclipse.tracecompass.internal.provisional.analysis.lami.core.aspect;
11
12 import java.util.Comparator;
13
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiTableEntry;
17 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiData;
18 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiTimeRange;
19 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
20
21 /**
22 * Aspect for beginning timestamp of a timerange
23 *
24 * @author Alexandre Montplaisir
25 */
26 public class LamiTimeRangeBeginAspect 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 LamiTimeRangeBeginAspect(String timeRangeName, int colIndex) {
39 super(timeRangeName + " (" + Messages.LamiAspect_TimeRangeBegin + ')', null); //$NON-NLS-1$
40 fColIndex = colIndex;
41 }
42
43 @Override
44 public boolean isContinuous() {
45 return true;
46 }
47
48 @Override
49 public boolean isTimeStamp() {
50 return true;
51 }
52
53 @Override
54 public @Nullable String resolveString(LamiTableEntry entry) {
55 LamiData data = entry.getValue(fColIndex);
56 if (data instanceof LamiTimeRange) {
57 LamiTimeRange range = (LamiTimeRange) data;
58 return TmfTimestampFormat.getDefaulTimeFormat().format(range.getStart());
59 }
60 /* Could be null, unknown, etc. */
61 return data.toString();
62 }
63
64
65
66 @Override
67 public @Nullable Double resolveDouble(@NonNull LamiTableEntry entry) {
68 LamiData data = entry.getValue(fColIndex);
69 if (data instanceof LamiTimeRange) {
70 LamiTimeRange range = (LamiTimeRange) data;
71 return Double.valueOf(range.getStart());
72 }
73 return null;
74 }
75
76 @Override
77 public Comparator<LamiTableEntry> getComparator() {
78 return (o1, o2) -> {
79 Double dO1 = resolveDouble(o1);
80 Double dO2 = resolveDouble(o2);
81 if (dO1 == null || dO2 == null) {
82 return 0;
83 }
84
85 return dO1.compareTo(dO2);
86 };
87 }
88
89 }
This page took 0.031973 seconds and 4 git commands to generate.