Skip to content

Commit 2e6fad6

Browse files
committed
#15 prototype VTable
1 parent 8bfc231 commit 2e6fad6

3 files changed

Lines changed: 149 additions & 1 deletion

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
7+
import java.util.List;
8+
import org.epics.util.array.ListNumber;
9+
10+
/**
11+
* An immutable table that extends {@link VTable}
12+
*
13+
* @author carcassi, shroff
14+
*/
15+
class IVTable extends VTable {
16+
17+
private final List<Class<?>> types;
18+
private final List<String> names;
19+
private final List<Object> values;
20+
private final int rowCount;
21+
22+
IVTable(List<Class<?>> types, List<String> names, List<Object> values) {
23+
this.types = types;
24+
this.names = names;
25+
this.values = values;
26+
int maxCount = 0;
27+
for (Object array : values) {
28+
maxCount = Math.max(maxCount, getDataSize(array));
29+
}
30+
this.rowCount = maxCount;
31+
}
32+
33+
private static int getDataSize(Object data) {
34+
if (data instanceof List) {
35+
return ((List) data).size();
36+
} else if (data instanceof ListNumber) {
37+
return ((ListNumber) data).size();
38+
}
39+
40+
throw new IllegalArgumentException("Object " + data + " is not supported");
41+
}
42+
43+
@Override
44+
public int getColumnCount() {
45+
return names.size();
46+
}
47+
48+
@Override
49+
public int getRowCount() {
50+
return rowCount;
51+
}
52+
53+
@Override
54+
public Class<?> getColumnType(int column) {
55+
return types.get(column);
56+
}
57+
58+
@Override
59+
public String getColumnName(int column) {
60+
return names.get(column);
61+
}
62+
63+
@Override
64+
public Object getColumnData(int column) {
65+
return values.get(column);
66+
}
67+
68+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
7+
import java.util.List;
8+
import org.epics.util.array.ListNumber;
9+
10+
/**
11+
* A table. Tables are collections of columns, each of which is composed of a
12+
* String representing the name of the column and a list of a particular type
13+
* (all elements of the same column must be of the same type).
14+
*
15+
* @author carcassi, shroff
16+
*/
17+
public abstract class VTable extends VType {
18+
19+
/**
20+
* The number of columns in the table.
21+
*
22+
* @return the number of columns
23+
*/
24+
abstract int getColumnCount();
25+
26+
/**
27+
* The number of rows in the table.
28+
* <p>
29+
* Currently, it is not clear whether all columns actually have the same number
30+
* of rows, that is if all arrays have the same length. In the case of variable
31+
* row, this will return the maximum row count, that is the length of the
32+
* longest array/column.
33+
*
34+
* @return the number of rows
35+
*/
36+
abstract int getRowCount();
37+
38+
/**
39+
* The type of the elements in the column. The column array will be an array of
40+
* the given type. For primitive types, this function will return the TYPE class
41+
* (such as {@link Double#TYPE}, while {@link #getColumnData(int) } will return
42+
* a {@link ListNumber}.
43+
*
44+
* @param column the column index
45+
* @return the type of this column
46+
*/
47+
abstract Class<?> getColumnType(int column);
48+
49+
/**
50+
* The name of the given column.
51+
*
52+
* @param column the column index
53+
* @return the name of the column
54+
*/
55+
abstract String getColumnName(int column);
56+
57+
/**
58+
* The data for the given column.
59+
* <p>
60+
* The data is going to be a {@link List} in case of objects or a
61+
* {@link ListNumber} in case of a numeric primitive.
62+
*
63+
* @param column the column index
64+
* @return the data of the column
65+
*/
66+
abstract Object getColumnData(int column);
67+
68+
/**
69+
* Create a new VTable
70+
*
71+
* @param types the types of each column
72+
* @param names the name of each column
73+
* @param values the values of each column
74+
* @return an immutable instance of the VTable
75+
*/
76+
public static VTable of(List<Class<?>> types, List<String> names, List<Object> values) {
77+
return new IVTable(types, names, values);
78+
}
79+
}

epics-vtype/vtype/src/main/java/org/epics/vtype/VType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public abstract class VType {
4040
VShortArray.class,
4141
VUByteArray.class,
4242
VByteArray.class,
43-
VImage.class);
43+
VImage.class,
44+
VTable.class);
4445

4546
/**
4647
* Returns the type of the object by returning the class object of one

0 commit comments

Comments
 (0)