fTrace = trace;
}
+ /**
+ * Constructs a new trace context with data taken from a builder.
+ *
+ * @param builder
+ * the builder
+ * @since 2.2
+ */
+ public LinuxTraceContext(LinuxBuilder builder) {
+ super(builder);
+ fCpu = builder.cpu;
+ fTid = builder.tid;
+ fTrace = builder.trace;
+ }
+
@Override
public void receive(@NonNull TmfTraceModelSignal signal) {
if (signal.getHostId().equals(fTrace.getHostId())) {
return fTid;
}
+ @Override
+ public @NonNull Builder builder() {
+ return new LinuxBuilder(this);
+ }
+
+ /**
+ * A builder for creating trace context instances.
+ *
+ * @since 2.2
+ */
+ public class LinuxBuilder extends Builder {
+ private int cpu;
+ private int tid;
+ private ITmfTrace trace;
+
+ /**
+ * Constructor
+ *
+ * @param ctx
+ * the trace context used to initialize the builder
+ */
+ public LinuxBuilder(LinuxTraceContext ctx) {
+ super(ctx);
+ this.cpu = ctx.fCpu;
+ this.tid = ctx.fTid;
+ this.trace = ctx.fTrace;
+ }
+
+ /**
+ * Build the trace context.
+ *
+ * @return a trace context
+ */
+ @Override
+ public TmfTraceContext build() {
+ return new LinuxTraceContext(this);
+ }
+ }
}
/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
private final TmfTimeRange fWindowRange;
private final @Nullable IFile fEditorFile;
private final @Nullable ITmfFilter fFilter;
- private final Map<@NonNull String, @NonNull Object> fData = new HashMap<>();
+ private final Map<@NonNull String, @NonNull Object> fData;
/**
* Build a new trace context.
fWindowRange = windowRange;
fEditorFile = editorFile;
fFilter = filter;
- fData.clear();
+ fData = new HashMap<>();
+ }
+
+ /**
+ * Constructs a new trace context with data taken from a builder.
+ *
+ * @param builder
+ * the builder
+ * @since 2.3
+ */
+ public TmfTraceContext(Builder builder) {
+ fSelection = builder.selection;
+ fWindowRange = builder.windowRange;
+ fEditorFile = builder.editorFile;
+ fFilter = builder.filter;
+ fData = new HashMap<>(builder.data);
}
/**
return ImmutableMap.copyOf(fData);
}
+ /**
+ * Returns a new builder that is initialized with the data from this trace
+ * context.
+ *
+ * @return the builder
+ * @since 2.3
+ */
+ public Builder builder() {
+ return new Builder(this);
+ }
+
+ /**
+ * A builder for creating trace context instances.
+ *
+ * @since 2.3
+ */
+ public class Builder {
+ private TmfTimeRange selection;
+ private TmfTimeRange windowRange;
+ private @Nullable IFile editorFile;
+ private @Nullable ITmfFilter filter;
+ private Map<String, Object> data;
+
+ /**
+ * Constructor
+ *
+ * @param ctx
+ * the trace context used to initialize the builder
+ */
+ public Builder(TmfTraceContext ctx) {
+ this.selection = ctx.fSelection;
+ this.windowRange = ctx.fWindowRange;
+ this.editorFile = ctx.fEditorFile;
+ this.filter = ctx.fFilter;
+ this.data = new HashMap<>(ctx.fData);
+ }
+
+ /**
+ * Build the trace context.
+ *
+ * @return a trace context
+ */
+ public TmfTraceContext build() {
+ return new TmfTraceContext(this);
+ }
+
+ /**
+ * Sets the selected time range.
+ *
+ * @param selection
+ * the selected time range
+ * @return this {@code Builder} object
+ */
+ public Builder setSelection(TmfTimeRange selection) {
+ this.selection = selection;
+ return this;
+ }
+
+ /**
+ * Sets the window range.
+ *
+ * @param windowRange
+ * the window range
+ * @return this {@code Builder} object
+ */
+ public Builder setWindowRange(TmfTimeRange windowRange) {
+ this.windowRange = windowRange;
+ return this;
+ }
+
+ /**
+ * Sets the current filter.
+ *
+ * @param filter
+ * the current filter
+ * @return this {@code Builder} object
+ */
+ public Builder setFilter(@Nullable ITmfFilter filter) {
+ this.filter = filter;
+ return this;
+ }
+ }
+
@Override
public String toString() {
return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
/*******************************************************************************
- * Copyright (c) 2013, 2015 Ericsson
+ * Copyright (c) 2013, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*/
@TmfSignalHandler
public synchronized void filterApplied(TmfEventFilterAppliedSignal signal) {
- final ITmfTrace newTrace = signal.getTrace();
- TmfTraceContext context = fTraces.get(newTrace);
+ final ITmfTrace trace = signal.getTrace();
+ TmfTraceContext context = fTraces.get(trace);
if (context == null) {
throw new RuntimeException();
}
- final TmfTraceContext newContext = newTrace.createTraceContext(context.getSelectionRange(),
- context.getWindowRange(),
- context.getEditorFile(),
- signal.getEventFilter());
- newContext.setData(context.getData());
- fTraces.put(newTrace, newContext);
+ final TmfTraceContext newContext = context.builder()
+ .setFilter(signal.getEventFilter())
+ .build();
+ fTraces.put(trace, newContext);
}
/**
* else the same as the previous trace context.
*/
TmfTimeRange newSelectionRange = new TmfTimeRange(beginTs, endTs);
- TmfTraceContext newCtx = trace.createTraceContext(newSelectionRange,
- prevCtx.getWindowRange(),
- prevCtx.getEditorFile(),
- prevCtx.getFilter());
- newCtx.setData(prevCtx.getData());
+ TmfTraceContext newCtx = prevCtx.builder()
+ .setSelection(newSelectionRange)
+ .build();
entry.setValue(newCtx);
}
}
TmfTimeRange newWindowTr = (targetTr == null ? prevCtx.getWindowRange() : targetTr);
/* Keep the values from the old context, except for the window range */
- TmfTraceContext newCtx = trace.createTraceContext(prevCtx.getSelectionRange(),
- newWindowTr, prevCtx.getEditorFile(), prevCtx.getFilter());
- newCtx.setData(prevCtx.getData());
+ TmfTraceContext newCtx = prevCtx.builder()
+ .setWindowRange(newWindowTr)
+ .build();
entry.setValue(newCtx);
}
}