07b745b31ded5b480b8672b97c4fb9dd5fdc4e45
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.core / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / core / aspect / LamiMixedAspect.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.LamiData.DataType;
18
19 /**
20 * Aspect for LAMI mixed types.
21 *
22 * The data in this column can contain any class of data.
23 *
24 * @author Philippe Proulx
25 */
26 public class LamiMixedAspect 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 LamiMixedAspect(String colName, int colIndex) {
39 super(colName, null);
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 Class<? extends LamiData> cls = data.getClass();
57
58 DataType dataType = DataType.fromClass(cls);
59
60 if (dataType == null) {
61 return data.toString();
62 }
63
64 String str = data.toString();
65
66 if (dataType.getUnits() != null) {
67 str += " " + dataType.getUnits(); //$NON-NLS-1$
68 }
69
70 return str;
71 }
72
73 @Override
74 public @Nullable Double resolveDouble(LamiTableEntry entry) {
75 return null;
76 }
77
78 @Override
79 public Comparator<LamiTableEntry> getComparator() {
80 return (o1, o2) -> {
81 String s1 = resolveString(o1);
82 String s2 = resolveString(o2);
83
84 if (s1 == null || s2 == null) {
85 return 0;
86 }
87
88 return s1.compareTo(s2);
89 };
90 }
91
92 }
This page took 0.035103 seconds and 4 git commands to generate.