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