Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 45012c287d36e98c6b5c98e9b4584e3a5105f575 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2006, 2018 IBM Corporation.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 *******************************************************************************/

package org.eclipse.linuxtools.systemtap.graphing.core.adapters;

import java.util.Arrays;

import org.eclipse.linuxtools.internal.systemtap.graphing.core.Localization;
import org.eclipse.linuxtools.systemtap.graphing.core.datasets.IBlockDataSet;
import org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSet;

public class BlockAdapter implements IAdapter {
    public BlockAdapter(IBlockDataSet data, int xSeries, int[] ySeries) {
        this.data = data;
        this.xSeries = xSeries;
        this.ySeries = Arrays.copyOf(ySeries, ySeries.length);
    }

    @Override
    public Number getYSeriesMax(int y, int start, int end) {
        return getSeriesMax(ySeries[y], start, end);
    }

    @Override
    public Number getSeriesMax(int series, int start, int end) {
        if(start < 0 || end > data.getRowCount() || start > end)
            return null;

        Number max = Double.NEGATIVE_INFINITY;
        Number cur;

        Object[] dataColumn = data.getColumn(series, start, end);
        for(int i=0; i<dataColumn.length; i++) {
            try {
                cur = Double.parseDouble(dataColumn[i].toString());
                if(max.doubleValue() < cur.doubleValue())
                    max = cur;
            } catch (NumberFormatException e) {}
        }
        return max;
    }

    @Override
    public String[] getLabels() {
        String[] labels = data.getTitles();

        String[] labels2 = new String[ySeries.length + 1];
        labels2[0] = (IDataSet.COL_ROW_NUM == xSeries) ? Localization.getString("BlockAdapter.RowNum") : labels[xSeries]; //$NON-NLS-1$

        for(int i=0; i<ySeries.length; i++)
            labels2[i+1] = labels[ySeries[i]];

        return labels2;
    }

    @Override
    public int getSeriesCount() {
        return ySeries.length;
    }

    @Override
    public int getRecordCount() {
        return data.getRowCount();
    }

    @Override
    public Object[][] getData() {
        return getData(0, getRecordCount());
    }

    //[Row][Column]
    @Override
    public Object[][] getData(int start, int end) {
        Object[][] o = new Object[Math.min(end-start,getRecordCount())][ySeries.length+1];

        Object[] row;
        for(int j,i=0; i<o.length; i++) {
            row = data.getRow(i+start);
            o[i][0] = (IDataSet.COL_ROW_NUM == xSeries) ? Integer.valueOf(i) : row[xSeries];

            for(j=0; j<ySeries.length; j++)
                o[i][j+1] = row[ySeries[j]];
        }

        return o;
    }

    private IBlockDataSet data;
    private int xSeries;
    private int[] ySeries;
}

Back to the top