tmf: Do not define base aspects in the interface
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / TmfBaseAspects.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
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.tmf.core.event.aspect;
11
12 import java.util.List;
13
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
16 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
17 import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
18 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
19
20 import com.google.common.collect.ImmutableList;
21
22 /**
23 * Some basic aspects that all trace types should be able to use, using methods
24 * found in {@link ITmfEvent}.
25 *
26 * @author Alexandre Montplaisir
27 * @author Geneviève Bastien
28 * @since 2.0
29 */
30 public final class TmfBaseAspects {
31
32 private static final ITmfEventAspect<ITmfTimestamp> TIMESTAMP_ASPECT = new ITmfEventAspect<ITmfTimestamp>() {
33 @Override
34 public String getName() {
35 return Messages.getMessage(Messages.AspectName_Timestamp);
36 }
37
38 @Override
39 public String getHelpText() {
40 return ITmfEventAspect.EMPTY_STRING;
41 }
42
43 @Override
44 public @Nullable ITmfTimestamp resolve(ITmfEvent event) {
45 return event.getTimestamp();
46 }
47 };
48
49 private static final ITmfEventAspect<String> EVENT_TYPE_ASPECT = new ITmfEventAspect<String>() {
50 @Override
51 public String getName() {
52 return Messages.getMessage(Messages.AspectName_EventType);
53 }
54
55 @Override
56 public String getHelpText() {
57 return Messages.getMessage(Messages.AspectHelpText_EventType);
58 }
59
60 @Override
61 public @Nullable String resolve(ITmfEvent event) {
62 ITmfEventType type = event.getType();
63 if (type == null) {
64 return null;
65 }
66 return type.getName();
67 }
68 };
69
70 private static final TmfEventFieldAspect CONTENTS_ASPECT = new TmfEventFieldAspect(Messages.getMessage(Messages.AspectName_Contents), null, new TmfEventFieldAspect.IRootField() {
71 @Override
72 public @Nullable ITmfEventField getRootField(ITmfEvent event) {
73 return event.getContent();
74 }
75 }) {
76 @Override
77 public String getHelpText() {
78 return Messages.getMessage(Messages.AspectHelpText_Contents);
79 }
80 };
81
82 private static final ITmfEventAspect<String> TRACE_NAME_ASPECT = new ITmfEventAspect<String>() {
83 @Override
84 public String getName() {
85 return Messages.getMessage(Messages.AspectName_TraceName);
86 }
87
88 @Override
89 public String getHelpText() {
90 return Messages.getMessage(Messages.AspectHelpText_TraceName);
91 }
92
93 @Override
94 public @Nullable String resolve(ITmfEvent event) {
95 return event.getTrace().getName();
96 }
97 };
98
99 private static final List<ITmfEventAspect<?>> BASE_ASPECTS = ImmutableList.of(
100 getTimestampAspect(),
101 getEventTypeAspect(),
102 getContentsAspect(),
103 getTraceNameAspect());
104
105 private TmfBaseAspects() {
106
107 }
108
109 /**
110 * Get the aspect for the event timestamp
111 *
112 * @return The timestamp aspect
113 */
114 public static ITmfEventAspect<ITmfTimestamp> getTimestampAspect() {
115 return TIMESTAMP_ASPECT;
116 }
117
118 /**
119 * Get the aspect for the event type
120 *
121 * @return The aspect for the event type
122 */
123 public static ITmfEventAspect<String> getEventTypeAspect() {
124 return EVENT_TYPE_ASPECT;
125 }
126
127 /**
128 * Get the aspect for the aggregated event contents (fields)
129 *
130 * @return The aspect for the aggregate event contents
131 */
132 public static TmfEventFieldAspect getContentsAspect() {
133 return CONTENTS_ASPECT;
134 }
135
136 /**
137 * Get the aspect for the trace's name (for experiments with many traces)
138 *
139 * @return The trace name aspect
140 */
141 public static ITmfEventAspect<String> getTraceNameAspect() {
142 return TRACE_NAME_ASPECT;
143 }
144
145 /**
146 * Get the list of all common base aspects
147 *
148 * @return the list of base aspects
149 */
150 public static List<ITmfEventAspect<?>> getBaseAspects() {
151 return BASE_ASPECTS;
152 }
153
154 }
This page took 0.061817 seconds and 5 git commands to generate.