~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/nonui/adapters/BlockAdapter.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006 IBM Corporation.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters;
 
13
 
 
14
import org.eclipse.linuxtools.internal.systemtap.ui.graphingapi.nonui.Localization;
 
15
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IBlockDataSet;
 
16
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet;
 
17
 
 
18
public class BlockAdapter implements IAdapter {
 
19
        public BlockAdapter(IBlockDataSet data, int xSeries, int[] ySeries) {
 
20
                this.data = data;
 
21
                this.xSeries = xSeries;
 
22
                this.ySeries = ySeries;
 
23
        }
 
24
        
 
25
        public Number getXMax() {
 
26
                return getXMax(0, getRecordCount());
 
27
        }
 
28
        
 
29
        public Number getXMax(int start, int end) {
 
30
                return getSeriesMax(xSeries, start, end);
 
31
        }
 
32
        
 
33
        public Number getYMax() {
 
34
                return getYMax(0, getRecordCount());
 
35
        }
 
36
        
 
37
        public Number getYMax(int start, int end) {
 
38
                Number max = new Double(Double.MIN_VALUE);
 
39
                Number a;
 
40
                for(int i=0; i<ySeries.length; i++) {
 
41
                        a = getSeriesMax(ySeries[i], start, end);
 
42
                        max = (max.doubleValue()) > a.doubleValue() ? max : a;
 
43
                }
 
44
                return max;
 
45
        }
 
46
 
 
47
        public Number getYSeriesMax(int y) {
 
48
                return getYSeriesMax(y, 0, getRecordCount());
 
49
        }
 
50
        
 
51
        public Number getYSeriesMax(int y, int start, int end) {
 
52
                return getSeriesMax(ySeries[y], start, end);
 
53
        }
 
54
        
 
55
        public Number getSeriesMax(int series) {
 
56
                return getSeriesMax(series, 0, getRecordCount());
 
57
        }
 
58
        
 
59
        public Number getSeriesMax(int series, int start, int end) {
 
60
                if(start < 0 || end > data.getRowCount() || start > end)
 
61
                        return null;
 
62
                
 
63
                Number max = new Double(Double.NEGATIVE_INFINITY);
 
64
                Number cur;
 
65
 
 
66
                Object[] dataColumn = data.getColumn(series, start, end);
 
67
                for(int i=0; i<dataColumn.length; i++) {
 
68
                        try {
 
69
                                cur = new Double(Double.parseDouble(dataColumn[i].toString()));
 
70
                                if(max.doubleValue() < cur.doubleValue())
 
71
                                        max = cur;
 
72
                        } catch (NumberFormatException e) {}
 
73
                }
 
74
                return max;
 
75
        }
 
76
 
 
77
        public Number getXMin() {
 
78
                return getXMin(0, getRecordCount());
 
79
        }
 
80
        
 
81
        public Number getXMin(int start, int end) {
 
82
                return getSeriesMin(xSeries, start, end);
 
83
        }
 
84
        
 
85
        public Number getYMin() {
 
86
                return getYMin(0, getRecordCount());
 
87
        }
 
88
        
 
89
        public Number getYMin(int start, int end) {
 
90
                Number min = new Double(Double.MIN_VALUE);
 
91
                Number a;
 
92
                for(int i=0; i<ySeries.length; i++) {
 
93
                        a = getSeriesMin(ySeries[i], start, end);
 
94
                        min = (min.doubleValue()) < a.doubleValue() ? min : a;
 
95
                }
 
96
                return min;
 
97
        }
 
98
 
 
99
        public Number getYSeriesMin(int y) {
 
100
                return getYSeriesMin(y, 0, getRecordCount());
 
101
        }
 
102
        
 
103
        public Number getYSeriesMin(int y, int start, int end) {
 
104
                return getSeriesMin(ySeries[y], start, end);
 
105
        }
 
106
        
 
107
        public Number getSeriesMin(int series) {
 
108
                return getSeriesMin(series, 0, getRecordCount());
 
109
        }
 
110
        
 
111
        public Number getSeriesMin(int series, int start, int end) {
 
112
                if(start < 0 || end > data.getRowCount() || start > end)
 
113
                        return null;
 
114
                
 
115
                Number min = new Double(Double.POSITIVE_INFINITY);
 
116
                Number cur;
 
117
 
 
118
                Object[] dataColumn = data.getColumn(series, start, end);
 
119
                for(int i=0; i<dataColumn.length; i++) {
 
120
                        try {
 
121
                                cur = new Double(Double.parseDouble(dataColumn[i].toString()));
 
122
                                if(min.doubleValue() > cur.doubleValue())
 
123
                                        min = cur;
 
124
                        } catch (NumberFormatException e) {}
 
125
                }
 
126
                return min;
 
127
        }
 
128
 
 
129
        public String[] getLabels() {
 
130
                String[] labels = data.getTitles();
 
131
                
 
132
                String[] labels2 = new String[ySeries.length + 1];
 
133
                labels2[0] = (IDataSet.COL_ROW_NUM == xSeries) ? Localization.getString("BlockAdapter.RowNum") : labels[xSeries];
 
134
 
 
135
                for(int i=0; i<ySeries.length; i++)
 
136
                        labels2[i+1] = labels[ySeries[i]];
 
137
                
 
138
                return labels2;
 
139
        }
 
140
        
 
141
        public int getSeriesCount() {
 
142
                return ySeries.length;
 
143
        }
 
144
 
 
145
        public int getRecordCount() {
 
146
                return data.getRowCount();
 
147
        }
 
148
        
 
149
        public Object[][] getData() {
 
150
                return getData(0, getRecordCount());
 
151
        }
 
152
        
 
153
        //[Row][Column]
 
154
        public Object[][] getData(int start, int end) {
 
155
                Object[][] o = new Object[Math.min(end-start,getRecordCount())][ySeries.length+1];
 
156
                
 
157
                Object[] row;
 
158
                for(int j,i=0; i<o.length; i++) {
 
159
                        row = data.getRow(i+start);
 
160
                        o[i][0] = (IDataSet.COL_ROW_NUM == xSeries) ? new Integer(i) : row[xSeries];
 
161
 
 
162
                        for(j=0; j<ySeries.length; j++)
 
163
                                o[i][j+1] = row[ySeries[j]];
 
164
                }
 
165
                
 
166
                return o;
 
167
        }
 
168
                
 
169
        private IBlockDataSet data;
 
170
        private int xSeries;
 
171
        private int[] ySeries;
 
172
}