import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
*
* @author Alexandre Montplaisir
*/
+@NonNullByDefault
public final class TmfTraceManager {
// ------------------------------------------------------------------------
private final Map<ITmfTrace, TmfTraceContext> fTraces;
/** The currently-selected trace. Should always be part of the trace map */
- private ITmfTrace fCurrentTrace = null;
+ private @Nullable ITmfTrace fCurrentTrace = null;
private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$
}
/** Singleton instance */
- private static TmfTraceManager tm = null;
+ private static @Nullable TmfTraceManager tm = null;
/**
* Get an instance of the trace manager.
* @return The trace manager
*/
public static synchronized TmfTraceManager getInstance() {
- if (tm == null) {
- tm = new TmfTraceManager();
+ TmfTraceManager mgr = tm;
+ if (mgr == null) {
+ mgr = new TmfTraceManager();
+ tm = mgr;
}
- return tm;
+ return mgr;
}
// ------------------------------------------------------------------------
/**
* Get the currently selected trace (normally, the focused editor).
*
- * @return The active trace
+ * @return The active trace, or <code>null</code> if there is no active
+ * trace
*/
- public synchronized ITmfTrace getActiveTrace() {
+ public synchronized @Nullable ITmfTrace getActiveTrace() {
return fCurrentTrace;
}
/**
* Get the trace set of the currently active trace.
*
- * @return The active trace set
+ * @return The active trace set. Empty (but non-null) if there is no
+ * currently active trace.
* @see #getTraceSet(ITmfTrace)
*/
- public synchronized @NonNull Collection<ITmfTrace> getActiveTraceSet() {
+ public synchronized Collection<ITmfTrace> getActiveTraceSet() {
final ITmfTrace trace = fCurrentTrace;
return getTraceSet(trace);
}
* the trace
* @return the editor file or null if the trace is not opened
*/
- public synchronized IFile getTraceEditorFile(ITmfTrace trace) {
+ public synchronized @Nullable IFile getTraceEditorFile(ITmfTrace trace) {
TmfTraceContext ctx = fTraces.get(trace);
if (ctx != null) {
return ctx.getEditorFile();
* all the traces contained in this experiment.
*
* @param trace
- * The trace or experiment
+ * The trace or experiment. If it is null, an empty collection
+ * will be returned.
* @return The corresponding trace set.
*/
- public static @NonNull Collection<@NonNull ITmfTrace> getTraceSet(ITmfTrace trace) {
+ public static Collection<ITmfTrace> getTraceSet(@Nullable ITmfTrace trace) {
if (trace == null) {
return ImmutableSet.of();
}
* this experiment, along with the experiment.
*
* @param trace
- * The trace or experiment
+ * The trace or experiment. If it is null, an empty collection
+ * will be returned.
* @return The corresponding trace set, including the experiment.
*/
- public static @NonNull Collection<ITmfTrace> getTraceSetWithExperiment(ITmfTrace trace) {
+ public static Collection<ITmfTrace> getTraceSetWithExperiment(@Nullable ITmfTrace trace) {
if (trace == null) {
return ImmutableSet.of();
}
/**
* Signal propagator
- * @param signal any signal
+ *
+ * @param signal
+ * any signal
* @since 2.0
*/
@TmfSignalHandler
- public synchronized void signalReceived(final @NonNull TmfTraceModelSignal signal) {
+ public synchronized void signalReceived(final TmfTraceModelSignal signal) {
fTraces.forEach((t, u) -> u.receive(signal));
}