Remove unneeded checkNotNull() calls
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / ITmfEventAspect.java
CommitLineData
9447c7ee 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 Ericsson
9447c7ee
AM
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Alexandre Montplaisir - Initial API and implementation
ec34bf48 11 * Patrick Tasse - Added base aspect list
9447c7ee
AM
12 *******************************************************************************/
13
14package org.eclipse.tracecompass.tmf.core.event.aspect;
15
ec34bf48
PT
16import java.util.List;
17
2a28075c 18import org.eclipse.jdt.annotation.Nullable;
9447c7ee 19import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
40dfafb3 20import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
9447c7ee 21import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
2a28075c 22import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
9447c7ee 23
ec34bf48
PT
24import com.google.common.collect.ImmutableList;
25
9447c7ee
AM
26/**
27 * An aspect is a piece of information that can be extracted, directly or
28 * indirectly, from a trace event.
29 *
30 * Simple examples could be timestamp, or event fields. But it could also be
31 * something like a state system request, at the timestamp of the given event.
32 *
33 * The aspect can then be used to populate event table columns, to filter
34 * on to only keep certain events, to plot XY charts, etc.
35 *
36 * @author Alexandre Montplaisir
37 */
38public interface ITmfEventAspect {
39
40 /**
41 * Static definition of an empty string. You can use this instead of 'null'!
42 */
43 String EMPTY_STRING = ""; //$NON-NLS-1$
44
ec34bf48
PT
45 /**
46 * List of all common base aspects
47 */
48 public static final List<ITmfEventAspect> BASE_ASPECTS =
0e4f957e 49 ImmutableList.of(
ec34bf48
PT
50 BaseAspects.TIMESTAMP,
51 BaseAspects.EVENT_TYPE,
52 BaseAspects.CONTENTS,
53 BaseAspects.TRACE_NAME
0e4f957e 54 );
9447c7ee
AM
55 /**
56 * Some basic aspects that all trace types should be able to use, using
57 * methods found in {@link ITmfEvent}.
58 */
59 interface BaseAspects {
60
61 /**
62 * Aspect for the event timestamp
63 */
64 ITmfEventAspect TIMESTAMP = new ITmfEventAspect() {
65 @Override
66 public String getName() {
67 return Messages.getMessage(Messages.AspectName_Timestamp);
68 }
69
70 @Override
71 public String getHelpText() {
72 return EMPTY_STRING;
73 }
74
75 @Override
2a28075c
GB
76 public @Nullable ITmfTimestamp resolve(ITmfEvent event) {
77 return event.getTimestamp();
9447c7ee 78 }
9447c7ee
AM
79 };
80
81 /**
82 * Aspect for the event type
83 */
84 ITmfEventAspect EVENT_TYPE = new ITmfEventAspect() {
85 @Override
86 public String getName() {
87 return Messages.getMessage(Messages.AspectName_EventType);
88 }
89
90 @Override
91 public String getHelpText() {
92 return Messages.getMessage(Messages.AspectHelpText_EventType);
93 }
94
95 @Override
2a28075c 96 public @Nullable String resolve(ITmfEvent event) {
9447c7ee
AM
97 ITmfEventType type = event.getType();
98 if (type == null) {
2a28075c 99 return null;
9447c7ee 100 }
2a28075c 101 return type.getName();
9447c7ee 102 }
9447c7ee
AM
103 };
104
105 /**
106 * Aspect for the aggregated event contents (fields)
107 */
40dfafb3 108 TmfEventFieldAspect CONTENTS = new TmfEventFieldAspect(Messages.getMessage(Messages.AspectName_Contents), null, new TmfEventFieldAspect.IRootField() {
9447c7ee 109 @Override
40dfafb3
PT
110 public @Nullable ITmfEventField getRootField(ITmfEvent event) {
111 return event.getContent();
9447c7ee 112 }
40dfafb3 113 }) {
9447c7ee
AM
114 @Override
115 public String getHelpText() {
116 return Messages.getMessage(Messages.AspectHelpText_Contents);
117 }
118
9447c7ee 119 };
de34c0b1
AM
120
121 /**
122 * Aspect for the trace's name (for experiments with many traces)
123 */
124 ITmfEventAspect TRACE_NAME = new ITmfEventAspect() {
125 @Override
126 public String getName() {
127 return Messages.getMessage(Messages.AspectName_TraceName);
128 }
129
130 @Override
131 public String getHelpText() {
132 return Messages.getMessage(Messages.AspectHelpText_TraceName);
133 }
134
135 @Override
2a28075c
GB
136 public @Nullable String resolve(ITmfEvent event) {
137 return event.getTrace().getName();
de34c0b1 138 }
de34c0b1 139 };
9447c7ee
AM
140 }
141
142 /**
143 * Get the name of this aspect. This name will be user-visible and, as such,
144 * should be localized.
145 *
146 * @return The name of this aspect.
147 */
148 String getName();
149
150 /**
151 * Return a descriptive help text of what this aspect does. This could then
152 * be shown in tooltip or in option dialogs for instance. It should also be
153 * localized.
154 *
155 * You can return {@link #EMPTY_STRING} if you judge that the aspect name
156 * makes it obvious.
157 *
158 * @return The help text of this aspect
159 */
160 String getHelpText();
161
162 /**
163 * The "functor" representing this aspect. Basically, what to do for an
164 * event that is passed in parameter.
165 *
166 * Note to implementers:
167 *
168 * The parameter type here is {@link ITmfEvent}. This is because you could
169 * receive any type of event here. Do not assume you will only receive
170 * events of your own trace type. It is perfectly fine to return
171 * {@link #EMPTY_STRING} for event types you don't support.
172 *
173 * You also can (and should) provide a more specific return type than
174 * Object.
175 *
176 * @param event
177 * The event to process
178 * @return The resulting tidbit of information for this event.
179 */
2a28075c 180 @Nullable Object resolve(ITmfEvent event);
9447c7ee 181}
This page took 0.057611 seconds and 5 git commands to generate.