Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
20 | /** | |
21 | * Aspect for a time range duration | |
22 | * | |
23 | * @author Alexandre Montplaisir | |
24 | */ | |
25 | public class LamiTimeRangeDurationAspect extends LamiTableEntryAspect { | |
26 | ||
27 | private final int fColIndex; | |
28 | ||
29 | /** | |
30 | * Constructor | |
31 | * | |
32 | * @param timeRangeName | |
33 | * Name of the time range | |
34 | * @param colIndex | |
35 | * Column index | |
36 | */ | |
37 | public LamiTimeRangeDurationAspect(String timeRangeName, int colIndex) { | |
38 | super(timeRangeName + " (" + Messages.LamiAspect_TimeRangeDuration + ')', "ns"); //$NON-NLS-1$ //$NON-NLS-2$ | |
39 | fColIndex = colIndex; | |
40 | } | |
41 | ||
42 | @Override | |
43 | public boolean isContinuous() { | |
44 | return true; | |
45 | } | |
46 | ||
47 | @Override | |
48 | public boolean isTimeStamp() { | |
49 | return false; | |
50 | } | |
51 | ||
52 | @Override | |
53 | public boolean isTimeDuration() { | |
54 | return true; | |
55 | } | |
56 | ||
57 | @Override | |
58 | public @Nullable String resolveString(LamiTableEntry entry) { | |
59 | LamiData data = entry.getValue(fColIndex); | |
60 | if (data instanceof LamiTimeRange) { | |
61 | LamiTimeRange range = (LamiTimeRange) data; | |
62 | return String.valueOf(range.getDuration()); | |
63 | } | |
64 | return data.toString(); | |
65 | } | |
66 | ||
67 | @Override | |
68 | public @Nullable Double resolveDouble(@NonNull LamiTableEntry entry) { | |
69 | LamiData data = entry.getValue(fColIndex); | |
70 | if (data instanceof LamiTimeRange) { | |
71 | LamiTimeRange range = (LamiTimeRange) data; | |
72 | return Double.valueOf(range.getDuration()); | |
73 | } | |
74 | return null; | |
75 | } | |
76 | ||
77 | @Override | |
78 | public Comparator<LamiTableEntry> getComparator() { | |
79 | return (o1, o2) -> { | |
80 | Double dO1 = resolveDouble(o1); | |
81 | Double dO2 = resolveDouble(o2); | |
82 | if (dO1 == null || dO2 == null) { | |
83 | return 0; | |
84 | } | |
85 | ||
86 | return dO1.compareTo(dO2); | |
87 | }; | |
88 | } | |
89 | ||
90 | } |