1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.trace
;
15 import java
.util
.HashSet
;
18 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
25 * Utility methods for ITmfTrace's.
27 * @author Alexandre Montplaisir
30 public final class TmfTraceUtils
{
32 private TmfTraceUtils() {
36 * Get an analysis module belonging to this trace, with the specified ID and
40 * The trace for which you want the modules
42 * Returned modules must extend this class
44 * The ID of the analysis module
45 * @return The analysis module with specified class and ID, or null if no
48 public static @Nullable <T
extends IAnalysisModule
> T
getAnalysisModuleOfClass(ITmfTrace trace
,
49 Class
<T
> moduleClass
, String id
) {
50 Iterable
<T
> modules
= getAnalysisModulesOfClass(trace
, moduleClass
);
51 for (T module
: modules
) {
52 if (id
.equals(module
.getId())) {
60 * Return the analysis modules that are of a given class. Module will be
61 * casted to the requested class.
64 * The trace for which you want the modules
66 * Returned modules must extend this class
67 * @return List of modules of class moduleClass
69 public static <T
> Iterable
<T
> getAnalysisModulesOfClass(ITmfTrace trace
, Class
<T
> moduleClass
) {
70 Iterable
<IAnalysisModule
> analysisModules
= trace
.getAnalysisModules();
71 Set
<T
> modules
= new HashSet
<>();
72 for (IAnalysisModule module
: analysisModules
) {
73 if (moduleClass
.isAssignableFrom(module
.getClass())) {
74 modules
.add(moduleClass
.cast(module
));
81 * Return the first result of the first aspect that resolves as non null for
82 * the event received in parameter. If the returned value is not null, it
83 * can be safely cast to the aspect's class proper return type.
86 * The trace for which you want the event aspects
88 * The class of the aspect(s) to resolve
90 * The event for which to get the aspect
91 * @return The first result of the
92 * {@link ITmfEventAspect#resolve(ITmfEvent)} that returns non null
93 * for the event or {@code null} otherwise
95 public static @Nullable <T
extends ITmfEventAspect
> Object
resolveEventAspectOfClassForEvent(
96 ITmfTrace trace
, Class
<T
> aspectClass
, ITmfEvent event
) {
97 Iterable
<ITmfEventAspect
> aspects
= trace
.getEventAspects();
98 for (ITmfEventAspect aspect
: aspects
) {
99 if (aspectClass
.isAssignableFrom(aspect
.getClass())) {
100 Object obj
= aspect
.resolve(event
);
This page took 0.038339 seconds and 5 git commands to generate.