Commit | Line | Data |
---|---|---|
a52fde77 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
a52fde77 AM |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
5df842b3 | 5 | * |
a52fde77 AM |
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 | |
5df842b3 | 10 | * |
a52fde77 AM |
11 | *******************************************************************************/ |
12 | ||
e894a508 | 13 | package org.eclipse.tracecompass.statesystem.core.interval; |
a52fde77 | 14 | |
e894a508 | 15 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; |
a52fde77 AM |
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. | |
5df842b3 | 21 | * |
2cb26548 | 22 | * @author Alexandre Montplaisir |
a52fde77 AM |
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 | |
5df842b3 | 33 | * |
a52fde77 | 34 | * @param start |
5df842b3 | 35 | * Start time |
a52fde77 | 36 | * @param end |
5df842b3 | 37 | * End time |
a52fde77 | 38 | * @param attribute |
5df842b3 | 39 | * Attribute linked to this interval |
a52fde77 | 40 | * @param sv |
5df842b3 | 41 | * State value this interval will contain |
a52fde77 AM |
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 int getAttribute() { | |
63 | return attribute; | |
64 | } | |
65 | ||
66 | @Override | |
67 | public ITmfStateValue getStateValue() { | |
68 | return sv; | |
69 | } | |
70 | ||
71 | @Override | |
72 | public boolean intersects(long timestamp) { | |
73 | if (start <= timestamp) { | |
74 | if (end >= timestamp) { | |
75 | return true; | |
76 | } | |
77 | } | |
78 | return false; | |
79 | } | |
80 | ||
81 | @Override | |
82 | public String toString() { | |
83 | /* Only used for debugging */ | |
84 | StringBuffer buf = new StringBuffer(start + " to "); //$NON-NLS-1$ | |
ce928461 | 85 | buf.append(end + ", "); //$NON-NLS-1$ |
a52fde77 AM |
86 | buf.append(String.format("key = %4d, ", attribute)); //$NON-NLS-1$ |
87 | buf.append("value = " + sv.toString()); //$NON-NLS-1$ | |
88 | return buf.toString(); | |
89 | } | |
90 | ||
91 | } |