Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / distribution / model / BaseDistributionData.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 * Bernd Hufmann - Initial API and implementation
11 * Francois Chouinard - Moved from LTTng to TMF
12 ******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.views.distribution.model;
15
16 /**
17 * Class with basic distribution data used for distribution models.
18 *
19 * It stores number of events (with timestamp) in buckets with a start time and a
20 * certain duration. The duration is the same across all buckets.
21 * Note that Timestamps are stored as long values.
22 *
23 * @version 1.0
24 * @author Bernd Hufmann
25 */
26 public class BaseDistributionData {
27
28 // ------------------------------------------------------------------------
29 // Constants
30 // ------------------------------------------------------------------------
31 /**
32 * Constant indication that bucket is not filled.
33 */
34 public final static int OUT_OF_RANGE_BUCKET = -1;
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39 /**
40 * Number of buckets
41 */
42 protected final int fNbBuckets;
43 /**
44 * Duration of each bucket
45 */
46 protected long fBucketDuration;
47 /**
48 * Bucket index of last event time
49 */
50 protected int fLastBucket;
51 /**
52 * Timestamp of the first bucket. (could be negative when analyzing events with descending time!!!)
53 */
54 protected long fFirstBucketTime;
55 /**
56 * Timestamp of the first event
57 */
58 protected long fFirstEventTime;
59 /**
60 * Timestamp of the last event
61 */
62 protected long fLastEventTime;
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 /**
69 * Constructs a base distribution data object.
70 * @param nbBuckets A total number of buckets
71 */
72 public BaseDistributionData(int nbBuckets) {
73 fNbBuckets = nbBuckets;
74 clear();
75 }
76
77 // ------------------------------------------------------------------------
78 // Accessors
79 // ------------------------------------------------------------------------
80 /**
81 * Returns the total number of buckets.
82 *
83 * @return the number of buckets.
84 */
85 public int getNbBuckets() {
86 return fNbBuckets;
87 }
88
89 /**
90 * Returns the duration of buckets.
91 *
92 * @return bucket duration
93 */
94 public long getBucketDuration() {
95 return fBucketDuration;
96 }
97
98 /**
99 * Set the bucket duration.
100 *
101 * @param bucketDuration The duration to set.
102 */
103 public void setBucketDuration(long bucketDuration) {
104 fBucketDuration = bucketDuration;
105 }
106
107 /**
108 * Returns the index of the last used bucket.
109 *
110 * @return last bucket index.
111 */
112 public int getLastBucket() {
113 return fLastBucket;
114 }
115
116 /**
117 * Sets the index of the last bucket used.
118 *
119 * @param lastBucket The last bucket index to set.
120 */
121 public void setLastBucket(int lastBucket) {
122 fLastBucket = lastBucket;
123 }
124
125 /**
126 * Returns the start time of the first bucket.
127 *
128 * @return first bucket time.
129 */
130 public long getFirstBucketTime() {
131 return fFirstBucketTime;
132 }
133
134 /**
135 * Sets the start time of the first bucket.
136 *
137 * @param firstBucketTime The bucket time to ser.
138 */
139 public void setFirstBucketTime(long firstBucketTime) {
140 fFirstBucketTime = firstBucketTime;
141 }
142
143 /**
144 * Returns the start time of the last bucket used.
145 *
146 * @return the start time of the last bucket.
147 */
148 public long getLastBucketTime() {
149 return getBucketStartTime(fLastBucket);
150 }
151
152 /**
153 * Returns the time of the event with the lowest timestamp.
154 *
155 * @return first event time.
156 */
157 public long getFirstEventTime() {
158 return fFirstEventTime;
159 }
160
161 /**
162 * Sets the time of the event with the lowest timestamp.
163 *
164 * @param firstEventTime The first event time to set.
165 */
166 public void setFirstEventTime(long firstEventTime) {
167 fFirstEventTime = firstEventTime;
168 }
169
170 /**
171 * Returns the time of the event with the biggest timestamp.
172 *
173 * @return the last event time.
174 */
175 public long getLastEventTime() {
176 return fLastEventTime;
177 }
178
179 /**
180 * Sets the time of the event with the biggest timestamp.
181 *
182 * @param lastEventTime The last event time to set.
183 */
184 public void setLastEventTime(long lastEventTime) {
185 fLastEventTime = lastEventTime;
186 }
187
188 /**
189 * Returns the bucket start time of a given bucket index.
190 *
191 * @param index The bucket index.
192 * @return the bucket start time of a given bucket index.
193 */
194 public long getBucketStartTime(int index) {
195 return fFirstBucketTime + index * fBucketDuration;
196 }
197
198 /**
199 * Returns the bucket end time of a given bucket index.
200 *
201 * @param index The bucket index.
202 * @return the bucket start time of a given bucket index.
203 */
204 public long getBucketEndTime(int index) {
205 return getBucketStartTime(index) + fBucketDuration;
206 }
207
208 /**
209 * Returns the bucket index of the bucket containing a given time.
210 *
211 * @param time The timestamp to check.
212 * @return the bucket index of the bucket containing the given time.
213 */
214 public int getIndex(long time) {
215 return (int)((time - fFirstBucketTime) / fBucketDuration);
216 }
217
218 /**
219 * Check if an index is valid.
220 *
221 * @param index
222 * The index to check
223 * @return If it's valid, true or false.
224 */
225 public boolean isIndexValid(int index) {
226 return ((index >= 0) && (index <= fNbBuckets - 1));
227 }
228
229 // ------------------------------------------------------------------------
230 // Operations
231 // ------------------------------------------------------------------------
232
233 /**
234 * Clears the data model to default values.
235 */
236 public void clear() {
237 fFirstBucketTime = 0;
238 fFirstEventTime = 0;
239 fLastEventTime = 0;
240 fLastBucket = 0;
241 fBucketDuration = 1;
242 }
243 }
This page took 0.035916 seconds and 5 git commands to generate.