tmf: Mark TmfTraceUtils @NonNullByDefault
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / experiment / TmfExperimentUtils.java
1 /*******************************************************************************
2 * Copyright (c) 2014 É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 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.trace.experiment;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import java.util.Collection;
18 import java.util.HashSet;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
23 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
24 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
25
26 /**
27 * This utility class contains some utility methods to retrieve specific traces
28 * or analysis in an experiment.
29 *
30 * @author Geneviève Bastien
31 */
32 @NonNullByDefault
33 public final class TmfExperimentUtils {
34
35 private TmfExperimentUtils() {
36
37 }
38
39 // ------------------------------------------------------------------------
40 // Utility methods for analysis modules
41 // ------------------------------------------------------------------------
42
43 private static Iterable<ITmfTrace> getTracesFromHost(TmfExperiment experiment, String hostId) {
44 Collection<ITmfTrace> hostTraces = new HashSet<>();
45 for (ITmfTrace trace : experiment.getTraces()) {
46 if (trace.getHostId().equals(hostId)) {
47 hostTraces.add(trace);
48 }
49 }
50 return hostTraces;
51 }
52
53 /**
54 * Get a specific analysis module from a specific host of an experiment. It
55 * will return the first module with the given ID from the first trace of
56 * the host that has such a module.
57 *
58 * @param experiment
59 * The experiment the host belongs to
60 * @param hostId
61 * The ID of the host for which we want the specified analysis
62 * @param analysisId
63 * The ID of the requested analysis
64 * @return The requested analysis module or {@code null} if no module found
65 */
66 public static @Nullable IAnalysisModule getAnalysisModuleForHost(TmfExperiment experiment, String hostId, String analysisId) {
67 for (ITmfTrace trace : getTracesFromHost(experiment, hostId)) {
68 IAnalysisModule module = trace.getAnalysisModule(analysisId);
69 if (module != null) {
70 return module;
71 }
72 }
73 return null;
74 }
75
76 /**
77 * Get an analysis module of a specific class from a specific host of an
78 * experiment. It will return the first module of the given class from the
79 * first trace of the host that has such a module.
80 *
81 * @param experiment
82 * The experiment the host belongs to
83 * @param hostId
84 * The ID of the host for which we want the specified analysis
85 * @param moduleClass
86 * The class of the analysis module to return
87 * @return The first analysis module of the given class or {@code null} if
88 * no module found
89 */
90 public static @Nullable <T extends IAnalysisModule> T getAnalysisModuleOfClassForHost(TmfExperiment experiment, String hostId, Class<T> moduleClass) {
91 for (ITmfTrace trace : getTracesFromHost(experiment, hostId)) {
92 trace = checkNotNull(trace);
93 for (T module : TmfTraceUtils.getAnalysisModulesOfClass(trace, moduleClass)) {
94 return module;
95 }
96 }
97 return null;
98 }
99
100 }
This page took 0.032428 seconds and 5 git commands to generate.