1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Francois Chouinard - Moved from LTTng to TMF
12 ******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.distribution
.model
;
17 * Class with basic distribution data used for distribution models.
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.
24 * @author Bernd Hufmann
26 public class BaseDistributionData
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 * Constant indication that bucket is not filled.
34 public final static int OUT_OF_RANGE_BUCKET
= -1;
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
42 protected final int fNbBuckets
;
44 * Duration of each bucket
46 protected long fBucketDuration
;
48 * Bucket index of last event time
50 protected int fLastBucket
;
52 * Timestamp of the first bucket. (could be negative when analyzing events with descending time!!!)
54 protected long fFirstBucketTime
;
56 * Timestamp of the first event
58 protected long fFirstEventTime
;
60 * Timestamp of the last event
62 protected long fLastEventTime
;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 * Constructs a base distribution data object.
70 * @param nbBuckets A total number of buckets
72 public BaseDistributionData(int nbBuckets
) {
73 fNbBuckets
= nbBuckets
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
81 * Returns the total number of buckets.
83 * @return the number of buckets.
85 public int getNbBuckets() {
90 * Returns the duration of buckets.
92 * @return bucket duration
94 public long getBucketDuration() {
95 return fBucketDuration
;
99 * Set the bucket duration.
101 * @param bucketDuration The duration to set.
103 public void setBucketDuration(long bucketDuration
) {
104 fBucketDuration
= bucketDuration
;
108 * Returns the index of the last used bucket.
110 * @return last bucket index.
112 public int getLastBucket() {
117 * Sets the index of the last bucket used.
119 * @param lastBucket The last bucket index to set.
121 public void setLastBucket(int lastBucket
) {
122 fLastBucket
= lastBucket
;
126 * Returns the start time of the first bucket.
128 * @return first bucket time.
130 public long getFirstBucketTime() {
131 return fFirstBucketTime
;
135 * Sets the start time of the first bucket.
137 * @param firstBucketTime The bucket time to ser.
139 public void setFirstBucketTime(long firstBucketTime
) {
140 fFirstBucketTime
= firstBucketTime
;
144 * Returns the start time of the last bucket used.
146 * @return the start time of the last bucket.
148 public long getLastBucketTime() {
149 return getBucketStartTime(fLastBucket
);
153 * Returns the time of the event with the lowest timestamp.
155 * @return first event time.
157 public long getFirstEventTime() {
158 return fFirstEventTime
;
162 * Sets the time of the event with the lowest timestamp.
164 * @param firstEventTime The first event time to set.
166 public void setFirstEventTime(long firstEventTime
) {
167 fFirstEventTime
= firstEventTime
;
171 * Returns the time of the event with the biggest timestamp.
173 * @return the last event time.
175 public long getLastEventTime() {
176 return fLastEventTime
;
180 * Sets the time of the event with the biggest timestamp.
182 * @param lastEventTime The last event time to set.
184 public void setLastEventTime(long lastEventTime
) {
185 fLastEventTime
= lastEventTime
;
189 * Returns the bucket start time of a given bucket index.
191 * @param index The bucket index.
192 * @return the bucket start time of a given bucket index.
194 public long getBucketStartTime(int index
) {
195 return fFirstBucketTime
+ index
* fBucketDuration
;
199 * Returns the bucket end time of a given bucket index.
201 * @param index The bucket index.
202 * @return the bucket start time of a given bucket index.
204 public long getBucketEndTime(int index
) {
205 return getBucketStartTime(index
) + fBucketDuration
;
209 * Returns the bucket index of the bucket containing a given time.
211 * @param time The timestamp to check.
212 * @return the bucket index of the bucket containing the given time.
214 public int getIndex(long time
) {
215 return (int)((time
- fFirstBucketTime
) / fBucketDuration
);
219 * Check if an index is valid.
223 * @return If it's valid, true or false.
225 public boolean isIndexValid(int index
) {
226 return ((index
>= 0) && (index
<= fNbBuckets
- 1));
229 // ------------------------------------------------------------------------
231 // ------------------------------------------------------------------------
234 * Clears the data model to default values.
236 public void clear() {
237 fFirstBucketTime
= 0;
This page took 0.037048 seconds and 6 git commands to generate.