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