common: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / statesystem / core / interval / TmfStateInterval.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 * Copyright (c) 2010, 2011 École Polytechnique de Montréal
4 * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
5 *
6 * All rights reserved. This program and the accompanying materials are
7 * made available under the terms of the Eclipse Public License v1.0 which
8 * accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.statesystem.core.interval;
14
15 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
16
17 /**
18 * The StateInterval represents the "state" a particular attribute was in, at a
19 * given time. It is the main object being returned from queries to the state
20 * system.
21 *
22 * @author Alexandre Montplaisir
23 */
24 public final class TmfStateInterval implements ITmfStateInterval {
25
26 private final long start;
27 private final long end;
28 private final int attribute;
29 private final ITmfStateValue sv;
30
31 /**
32 * Construct an interval from its given parameters
33 *
34 * @param start
35 * Start time
36 * @param end
37 * End time
38 * @param attribute
39 * Attribute linked to this interval
40 * @param sv
41 * State value this interval will contain
42 */
43 public TmfStateInterval(long start, long end, int attribute,
44 ITmfStateValue sv) {
45 this.start = start;
46 this.end = end;
47 this.attribute = attribute;
48 this.sv = sv;
49 }
50
51 @Override
52 public long getStartTime() {
53 return start;
54 }
55
56 @Override
57 public long getEndTime() {
58 return end;
59 }
60
61 @Override
62 public long getViewerEndTime() {
63 return end + 1;
64 }
65
66 @Override
67 public int getAttribute() {
68 return attribute;
69 }
70
71 @Override
72 public ITmfStateValue getStateValue() {
73 return sv;
74 }
75
76 @Override
77 public boolean intersects(long timestamp) {
78 if (start <= timestamp) {
79 if (end >= timestamp) {
80 return true;
81 }
82 }
83 return false;
84 }
85
86 @Override
87 public String toString() {
88 /* Only used for debugging */
89 StringBuffer buf = new StringBuffer(start + " to "); //$NON-NLS-1$
90 buf.append(end + ", "); //$NON-NLS-1$
91 buf.append(String.format("key = %4d, ", attribute)); //$NON-NLS-1$
92 buf.append("value = " + sv.toString()); //$NON-NLS-1$
93 return buf.toString();
94 }
95
96 }
This page took 0.033369 seconds and 5 git commands to generate.