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