Remove unneeded checkNotNull() calls
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / parsers / custom / CustomEventAspects.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
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 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 * Alexandre Montplaisir - Update for TmfEventTableColumn
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
15
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.tracecompass.common.core.NonNullUtils;
20 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
21 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
22 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEvent;
23 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
24 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
25
26 import com.google.common.collect.ImmutableList;
27
28 /**
29 * Event aspects for Custom {Text|XML} traces.
30 *
31 * Since this definition will be different for every single custom trace, we
32 * cannot define specific {@link ITmfEventAspect} in advance.
33 *
34 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
35 * with the CustomTraceDefinition of the the particular trace to display.
36 *
37 * @author Alexandre Montplaisir
38 */
39 public class CustomEventAspects {
40
41 /**
42 * Aspects for custom events, which use an integer ID to represent each
43 * field.
44 */
45 private static final class CustomEventFieldAspect implements ITmfEventAspect {
46
47 private final @NonNull String fName;
48 private final int fIndex;
49
50 /**
51 * Constructor
52 *
53 * @param name
54 * The name of this aspect
55 * @param idx
56 * The index of this field in the event's content to display
57 */
58 public CustomEventFieldAspect(@NonNull String name, int idx) {
59 fName = name;
60 fIndex = idx;
61 }
62
63 @Override
64 public String getName() {
65 return fName;
66 }
67
68 @Override
69 public String getHelpText() {
70 return EMPTY_STRING;
71 }
72
73 @Override
74 public String resolve(ITmfEvent event) {
75 if (event instanceof CustomEvent) {
76 return NonNullUtils.nullToEmptyString(((CustomEvent) event).getEventString(fIndex));
77 }
78 return EMPTY_STRING;
79 }
80 }
81
82 /**
83 * Build a set of event aspects for a given trace definition
84 *
85 * @param definition
86 * The {@link CustomTraceDefinition} of the trace for which you
87 * want the aspects
88 * @return The set of event aspects for the given trace
89 */
90 public static @NonNull Iterable<ITmfEventAspect> generateAspects(CustomTraceDefinition definition) {
91 ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
92 List<OutputColumn> outputs = definition.outputs;
93 for (int i = 0; i < outputs.size(); i++) {
94 String name = outputs.get(i).name;
95 builder.add(new CustomEventFieldAspect(name, i));
96 }
97 return builder.build();
98 }
99 }
This page took 0.032732 seconds and 5 git commands to generate.