23fb11a067e78c9613e496b8bafa084b5a8b1229
[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, 2016 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 org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
18 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
19 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
20 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
21 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
22 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
23
24 import com.google.common.collect.ImmutableList;
25
26 /**
27 * Event aspects for Custom {Text|XML} traces.
28 *
29 * Since this definition will be different for every single custom trace, we
30 * cannot define specific {@link ITmfEventAspect} in advance.
31 *
32 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
33 * with the CustomTraceDefinition of the the particular trace to display.
34 *
35 * @author Alexandre Montplaisir
36 */
37 public class CustomEventAspects {
38
39 /**
40 * Build a set of event aspects for a given trace definition
41 *
42 * @param definition
43 * The {@link CustomTraceDefinition} of the trace for which you
44 * want the aspects
45 * @return The set of event aspects for the given trace
46 */
47 public static @NonNull Iterable<ITmfEventAspect<?>> generateAspects(CustomTraceDefinition definition) {
48 ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
49 for (OutputColumn output : definition.outputs) {
50 if (output.tag.equals(Tag.TIMESTAMP) &&
51 (definition.timeStampOutputFormat == null || definition.timeStampOutputFormat.isEmpty())) {
52 builder.add(TmfBaseAspects.getTimestampAspect());
53 } else if (output.tag.equals(Tag.EVENT_TYPE)) {
54 builder.add(TmfBaseAspects.getEventTypeAspect());
55 } else {
56 builder.add(new TmfContentFieldAspect(output.name, output.name));
57 }
58 }
59 return builder.build();
60 }
61 }
This page took 0.033916 seconds and 4 git commands to generate.