blob: abed7b370dc6a5f6a67ef855cdd54bc3240634cf (
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*******************************************************************************
* Copyright (c) 2006, 2018 IBM Corporation and others.
*
* 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.datasets.table;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataEntry;
public class TableEntry implements IDataEntry {
public TableEntry() {
bodyContent = new ArrayList<>();
}
@Override
public int getRowCount() {
return bodyContent.size();
}
@Override
public int getColCount() {
if(getRowCount() > 0) {
return bodyContent.get(0).length;
}
return 0;
}
@Override
public Object get(String key, int col) {
if(col >= 0 && col < getColCount()) {
Object[] row = getRow(key);
if(null != row)
return row[col];
}
return null;
}
@Override
public Object[][] getData() {
Object[][] d = new Object[getRowCount()][getColCount()];
for(int i=0; i<getRowCount(); i++) {
d[i] = getRow(i);
}
return d;
}
@Override
public Object[] getRow(int row) {
if(row < 0 || row >= getRowCount())
return null;
return bodyContent.get(row);
}
@Override
public Object[] getRow(String key) {
Object[] row;
for(int i=0; i<bodyContent.size(); i++) {
row = bodyContent.get(i);
if(row[0].toString().equals(key))
return row;
}
return null;
}
@Override
public Object[] getColumn(int col) {
return getColumn(col, 0, getRowCount());
}
public Object[] getColumn(int col, int start, int end) {
if(0 <= col && getColCount() > col && start >=0 && end > start && end <= getRowCount()) {
Object[] res = new Object[Math.min(end-start, getRowCount())];
for(int i=0; i<res.length; i++)
res[i] = bodyContent.get(i+start)[col];
return res;
}
return null;
}
@Override
public void putRow(int row, Object[] data) {
if(row >= bodyContent.size())
add(data);
else if(row >= 0) {
bodyContent.add(row, data);
bodyContent.remove(row+1);
}
}
public void add(Object[] data) {
if(null != data && (data.length == getColCount() || getRowCount() == 0))
bodyContent.add(data);
}
@Override
public IDataEntry copy() {
TableEntry entry = new TableEntry();
for(int i=0; i<bodyContent.size(); i++)
entry.add(bodyContent.get(i));
return entry;
}
@Override
public boolean remove(int row) {
return (null != bodyContent.remove(row));
}
private List<Object[]> bodyContent; //ArrayList of arrays
}
|