TMF: Add some non null annotations to TmfTimeRange
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / TmfTraceContext.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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 * Alexandre Montplaisir - Initial API and implementation
11 * Patrick Tasse - Support selection range
12 * Xavier Raynaud - Support filters tracking
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.core.trace;
16
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
21 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
22 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
23 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
24
25 /**
26 * Context of a trace, which is the representation of the "view" the user
27 * currently has on this trace (window time range, selected time or time range).
28 *
29 * TODO could be extended to support the notion of current location too.
30 *
31 * @author Alexandre Montplaisir
32 */
33 @NonNullByDefault
34 final class TmfTraceContext {
35
36 static final TmfTraceContext NULL_CONTEXT =
37 new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE, null);
38
39 private final TmfTimeRange fSelection;
40 private final TmfTimeRange fWindowRange;
41 private final @Nullable IFile fEditorFile;
42 private final @Nullable ITmfFilter fFilter;
43
44 public TmfTraceContext(ITmfTimestamp beginTs, ITmfTimestamp endTs, TmfTimeRange tr, @Nullable IFile editorFile) {
45 fSelection = new TmfTimeRange(beginTs, endTs);
46 fWindowRange = tr;
47 fEditorFile = editorFile;
48 fFilter = null;
49 }
50
51 public TmfTraceContext(TmfTraceContext prevCtx, ITmfTimestamp beginTs, ITmfTimestamp endTs) {
52 fSelection = new TmfTimeRange(beginTs, endTs);
53 fWindowRange = prevCtx.fWindowRange;
54 fEditorFile = prevCtx.fEditorFile;
55 fFilter = prevCtx.fFilter;
56 }
57
58 public TmfTraceContext(TmfTraceContext prevCtx, TmfTimeRange tr) {
59 fSelection = prevCtx.fSelection;
60 fWindowRange = tr;
61 fEditorFile = prevCtx.fEditorFile;
62 fFilter = prevCtx.fFilter;
63 }
64
65 /**
66 * @param prevCtx
67 * The previous context
68 * @param filter
69 * The applied filter
70 */
71 public TmfTraceContext(TmfTraceContext prevCtx, @Nullable ITmfFilter filter) {
72 fSelection = prevCtx.fSelection;
73 fWindowRange = prevCtx.fWindowRange;
74 fEditorFile = prevCtx.fEditorFile;
75 fFilter = filter;
76 }
77
78 public ITmfTimestamp getSelectionBegin() {
79 return fSelection.getStartTime();
80 }
81
82 public ITmfTimestamp getSelectionEnd() {
83 return fSelection.getEndTime();
84 }
85
86 public TmfTimeRange getWindowRange() {
87 return fWindowRange;
88 }
89
90 public @Nullable IFile getEditorFile() {
91 return fEditorFile;
92 }
93
94 /**
95 * @return the current filter applied to the trace
96 */
97 public @Nullable ITmfFilter getFilter() {
98 return fFilter;
99 }
100
101 public boolean isValid() {
102 if (fSelection.getStartTime().compareTo(TmfTimestamp.ZERO) <= 0 ||
103 fSelection.getEndTime().compareTo(TmfTimestamp.ZERO) <= 0 ||
104 fWindowRange.getEndTime().compareTo(fWindowRange.getStartTime()) <= 0) {
105 return false;
106 }
107 return true;
108 }
109
110 @Override
111 public String toString() {
112 return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
113 ", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$
114 }
115 }
This page took 0.032701 seconds and 5 git commands to generate.