Commit | Line | Data |
---|---|---|
a52fde77 | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2012, 2013 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 | ||
bcec0116 | 13 | package org.eclipse.linuxtools.statesystem.core.interval; |
a52fde77 | 14 | |
bcec0116 | 15 | import org.eclipse.linuxtools.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 |
bcec0116 | 23 | * @since 3.0 |
a52fde77 AM |
24 | */ |
25 | public final class TmfStateInterval implements ITmfStateInterval { | |
26 | ||
27 | private final long start; | |
28 | private final long end; | |
29 | private final int attribute; | |
30 | private final ITmfStateValue sv; | |
31 | ||
32 | /** | |
33 | * Construct an interval from its given parameters | |
5df842b3 | 34 | * |
a52fde77 | 35 | * @param start |
5df842b3 | 36 | * Start time |
a52fde77 | 37 | * @param end |
5df842b3 | 38 | * End time |
a52fde77 | 39 | * @param attribute |
5df842b3 | 40 | * Attribute linked to this interval |
a52fde77 | 41 | * @param sv |
5df842b3 | 42 | * State value this interval will contain |
a52fde77 AM |
43 | */ |
44 | public TmfStateInterval(long start, long end, int attribute, | |
45 | ITmfStateValue sv) { | |
46 | this.start = start; | |
47 | this.end = end; | |
48 | this.attribute = attribute; | |
49 | this.sv = sv; | |
50 | } | |
51 | ||
52 | @Override | |
53 | public long getStartTime() { | |
54 | return start; | |
55 | } | |
56 | ||
57 | @Override | |
58 | public long getEndTime() { | |
59 | return end; | |
60 | } | |
61 | ||
eaad89a0 AM |
62 | @Override |
63 | public long getViewerEndTime() { | |
64 | return end + 1; | |
65 | } | |
66 | ||
a52fde77 AM |
67 | @Override |
68 | public int getAttribute() { | |
69 | return attribute; | |
70 | } | |
71 | ||
72 | @Override | |
73 | public ITmfStateValue getStateValue() { | |
74 | return sv; | |
75 | } | |
76 | ||
77 | @Override | |
78 | public boolean intersects(long timestamp) { | |
79 | if (start <= timestamp) { | |
80 | if (end >= timestamp) { | |
81 | return true; | |
82 | } | |
83 | } | |
84 | return false; | |
85 | } | |
86 | ||
87 | @Override | |
88 | public String toString() { | |
89 | /* Only used for debugging */ | |
90 | StringBuffer buf = new StringBuffer(start + " to "); //$NON-NLS-1$ | |
ce928461 | 91 | buf.append(end + ", "); //$NON-NLS-1$ |
a52fde77 AM |
92 | buf.append(String.format("key = %4d, ", attribute)); //$NON-NLS-1$ |
93 | buf.append("value = " + sv.toString()); //$NON-NLS-1$ | |
94 | return buf.toString(); | |
95 | } | |
96 | ||
97 | } |