Commit | Line | Data |
---|---|---|
4208b510 AM |
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.LamiProcess; | |
18 | ||
19 | /** | |
20 | * Aspect for process names | |
21 | * | |
22 | * @author Philippe Proulx | |
23 | */ | |
24 | public class LamiProcessNameAspect extends LamiTableEntryAspect { | |
25 | ||
26 | private final int fColIndex; | |
27 | ||
28 | /** | |
29 | * Constructor | |
30 | * | |
31 | * @param colName | |
32 | * Column name | |
33 | * @param colIndex | |
34 | * Column index | |
35 | */ | |
36 | public LamiProcessNameAspect(String colName, int colIndex) { | |
37 | super(colName + " (" + Messages.LamiAspect_Name +')', null); //$NON-NLS-1$ | |
38 | fColIndex = colIndex; | |
39 | } | |
40 | ||
41 | @Override | |
42 | public boolean isContinuous() { | |
43 | return false; | |
44 | } | |
45 | ||
46 | @Override | |
47 | public boolean isTimeStamp() { | |
48 | return false; | |
49 | } | |
50 | ||
51 | @Override | |
52 | public @Nullable String resolveString(LamiTableEntry entry) { | |
53 | LamiData data = entry.getValue(fColIndex); | |
54 | if (data instanceof LamiProcess) { | |
55 | return ((LamiProcess) data).getName(); | |
56 | } | |
57 | /* Could be null, unknown, etc. */ | |
58 | return data.toString(); | |
59 | } | |
60 | ||
61 | @Override | |
5b973e7c | 62 | public @Nullable Number resolveNumber(LamiTableEntry entry) { |
4208b510 AM |
63 | return null; |
64 | } | |
65 | ||
66 | @Override | |
67 | public Comparator<LamiTableEntry> getComparator() { | |
68 | return (o1, o2) -> { | |
69 | String s1 = resolveString(o1); | |
70 | String s2 = resolveString(o2); | |
71 | ||
5b973e7c | 72 | if (s1 == null && s2 == null) { |
4208b510 AM |
73 | return 0; |
74 | } | |
5b973e7c JR |
75 | if (s1 == null) { |
76 | return 1; | |
77 | } | |
78 | ||
79 | if (s2 == null) { | |
80 | return -1; | |
81 | } | |
4208b510 AM |
82 | |
83 | return s1.compareTo(s2); | |
84 | }; | |
85 | } | |
86 | } |