lttng: Temporary lttng-luna annotation update
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramScaledData.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 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Added setter and getter and bar width support
12 * Francois Chouinard - Moved from LTTng to TMF
13 * Patrick Tasse - Support selection range
14 *******************************************************************************/
15
16 package org.eclipse.linuxtools.tmf.ui.views.histogram;
17
18 import java.util.Arrays;
19
20 /**
21 * Convenience class/struct for scaled histogram data.
22 *
23 * @version 1.0
24 * @author Francois Chouinard
25 */
26 public class HistogramScaledData {
27
28 // ------------------------------------------------------------------------
29 // Constants
30 // ------------------------------------------------------------------------
31
32 /**
33 * Indicator value that bucket is out of range (not filled).
34 */
35 public static final int OUT_OF_RANGE_BUCKET = -1;
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40 /**
41 * Width of histogram canvas (number of pixels).
42 */
43 public int fWidth;
44 /**
45 * Height of histogram canvas (number of pixels).
46 */
47 public int fHeight;
48 /**
49 * Width of one histogram bar (number of pixels).
50 */
51 public int fBarWidth;
52 /**
53 * Array of scaled values
54 */
55 public int[] fData;
56 /**
57 * The bucket duration of a scaled data bucket.
58 */
59 public long fBucketDuration;
60 /**
61 * The maximum number of events of all buckets.
62 */
63 public long fMaxValue;
64 /**
65 * The index of the current bucket.
66 */
67 @Deprecated
68 public int fCurrentBucket;
69 /**
70 * The index of the selection begin bucket.
71 * @since 3.0
72 */
73 public int fSelectionBeginBucket;
74 /**
75 * The index of the selection end bucket.
76 * @since 3.0
77 */
78 public int fSelectionEndBucket;
79 /**
80 * The index of the last bucket.
81 */
82 public int fLastBucket;
83 /**
84 * The scaling factor used to fill the scaled data.
85 */
86 public double fScalingFactor;
87 /**
88 * Time of first bucket.
89 */
90 public long fFirstBucketTime;
91 /**
92 * The time of the first event.
93 */
94 public long fFirstEventTime;
95
96 // ------------------------------------------------------------------------
97 // Constructor
98 // ------------------------------------------------------------------------
99
100 /**
101 * Constructor.
102 * @param width the canvas width
103 * @param height the canvas height
104 * @param barWidth the required bar width
105 */
106 public HistogramScaledData(int width, int height, int barWidth) {
107 fWidth = width;
108 fHeight = height;
109 fBarWidth = barWidth;
110 fData = new int[width/fBarWidth];
111 Arrays.fill(fData, 0);
112 fBucketDuration = 1;
113 fMaxValue = 0;
114 fSelectionBeginBucket = 0;
115 fSelectionEndBucket = 0;
116 fLastBucket = 0;
117 fScalingFactor = 1;
118 fFirstBucketTime = 0;
119 }
120
121 /**
122 * Copy constructor
123 * @param other another scaled data.
124 */
125 public HistogramScaledData(HistogramScaledData other) {
126 fWidth = other.fWidth;
127 fHeight = other.fHeight;
128 fBarWidth = other.fBarWidth;
129 fData = Arrays.copyOf(other.fData, fWidth);
130 fBucketDuration = other.fBucketDuration;
131 fMaxValue = other.fMaxValue;
132 fSelectionBeginBucket = other.fSelectionBeginBucket;
133 fSelectionEndBucket = other.fSelectionEndBucket;
134 fLastBucket = other.fLastBucket;
135 fScalingFactor = other.fScalingFactor;
136 fFirstBucketTime = other.fFirstBucketTime;
137 }
138
139 // ------------------------------------------------------------------------
140 // Setter and Getter
141 // ------------------------------------------------------------------------
142
143 /**
144 * Returns the time of the first bucket of the scaled data.
145 * @return the time of the first bucket.
146 */
147 public long getFirstBucketTime() {
148 return fFirstBucketTime;
149 }
150
151 /**
152 * Set the first event time.
153 * @param firstEventTime The time to set
154 */
155 public void setFirstBucketTime(long firstEventTime) {
156 fFirstBucketTime = firstEventTime;
157 }
158
159 /**
160 * Returns the time of the last bucket.
161 * @return last bucket time
162 */
163 public long getLastBucketTime() {
164 return getBucketStartTime(fLastBucket);
165 }
166
167 /**
168 * Returns the time of the bucket start time for given index.
169 * @param index A bucket index.
170 * @return the time of the bucket start time
171 */
172 public long getBucketStartTime(int index) {
173 return fFirstBucketTime + index * fBucketDuration;
174 }
175
176 /**
177 * Returns the time of the bucket end time for given index.
178 * @param index A bucket index.
179 * @return the time of the bucket end time
180 */
181 public long getBucketEndTime(int index) {
182 return getBucketStartTime(index) + fBucketDuration;
183 }
184 }
This page took 0.035015 seconds and 5 git commands to generate.