use of org.diirt.util.array.BufferInt in project yamcs-studio by yamcs.
the class VTableFactory method tableRangeFilter.
public static VTable tableRangeFilter(VTable table, String columnName, Object min, Object max) {
RangeFilter valueFilter = new RangeFilter(table, columnName, min, max);
BufferInt indexes = new BufferInt();
for (int i = 0; i < table.getRowCount(); i++) {
if (valueFilter.filterRow(i)) {
indexes.addInt(i);
}
}
return extractRows(table, indexes);
}
use of org.diirt.util.array.BufferInt in project yamcs-studio by yamcs.
the class VTableFactory method tableStringMatchFilter.
public static VTable tableStringMatchFilter(VTable table, String columnName, String substring) {
StringMatchFilter filter = new StringMatchFilter(table, columnName, substring);
BufferInt indexes = new BufferInt();
for (int i = 0; i < table.getRowCount(); i++) {
if (filter.filterRow(i)) {
indexes.addInt(i);
}
}
return extractRows(table, indexes);
}
use of org.diirt.util.array.BufferInt in project yamcs-studio by yamcs.
the class VTableFactory method join.
public static VTable join(VTable... tables) {
if (tables.length == 0) {
return null;
}
if (tables.length == 1) {
return tables[0];
}
// Find columns to join
Map<String, int[]> commonColumnsIndexes = null;
for (int nTable = 0; nTable < tables.length; nTable++) {
VTable vTable = tables[nTable];
if (commonColumnsIndexes == null) {
commonColumnsIndexes = new HashMap<>();
for (int i = 0; i < vTable.getColumnCount(); i++) {
int[] indexes = new int[tables.length];
indexes[0] = i;
commonColumnsIndexes.put(vTable.getColumnName(i), indexes);
}
} else {
commonColumnsIndexes.keySet().retainAll(columnNames(vTable));
for (int i = 0; i < vTable.getColumnCount(); i++) {
if (commonColumnsIndexes.keySet().contains(vTable.getColumnName(i))) {
commonColumnsIndexes.get(vTable.getColumnName(i))[nTable] = i;
}
}
}
}
if (commonColumnsIndexes.isEmpty()) {
throw new UnsupportedOperationException("Case not implemented yet");
}
List<EqualValueFilter> filters = new ArrayList<>();
for (Map.Entry<String, int[]> entry : commonColumnsIndexes.entrySet()) {
int[] indexes = entry.getValue();
filters.add(new EqualValueFilter(Arrays.asList(tables), indexes));
}
// Find rows
boolean done = false;
List<BufferInt> rowIndexes = new ArrayList<>();
for (int i = 0; i < tables.length; i++) {
rowIndexes.add(new BufferInt());
if (tables[i].getRowCount() == 0) {
done = true;
}
}
int[] currentIndexes = new int[tables.length];
while (!done) {
boolean match = true;
for (EqualValueFilter filter : filters) {
match = match && filter.filterRow(currentIndexes);
}
if (match) {
for (int i = 0; i < currentIndexes.length; i++) {
rowIndexes.get(i).addInt(currentIndexes[i]);
}
}
boolean needsIncrement = true;
int offset = currentIndexes.length - 1;
while (needsIncrement) {
currentIndexes[offset]++;
if (currentIndexes[offset] == tables[offset].getRowCount()) {
currentIndexes[offset] = 0;
offset--;
if (offset == -1) {
done = true;
needsIncrement = false;
}
} else {
needsIncrement = false;
}
}
}
List<String> columnNames = new ArrayList<>();
List<Class<?>> columnTypes = new ArrayList<>();
List<Object> columnData = new ArrayList<>();
for (int nColumn = 0; nColumn < tables[0].getColumnCount(); nColumn++) {
columnNames.add(tables[0].getColumnName(nColumn));
Class<?> type = tables[0].getColumnType(nColumn);
if (type.isPrimitive()) {
columnTypes.add(type);
columnData.add(ListNumbers.listView((ListNumber) tables[0].getColumnData(nColumn), rowIndexes.get(0)));
} else {
columnTypes.add(type);
columnData.add(createView((List<?>) tables[0].getColumnData(nColumn), rowIndexes.get(0)));
}
}
for (int i = 1; i < tables.length; i++) {
VTable vTable = tables[i];
for (int nColumn = 0; nColumn < vTable.getColumnCount(); nColumn++) {
if (!commonColumnsIndexes.containsKey(vTable.getColumnName(nColumn))) {
columnNames.add(vTable.getColumnName(nColumn));
Class<?> type = vTable.getColumnType(nColumn);
if (type.isPrimitive()) {
columnTypes.add(type);
columnData.add(ListNumbers.listView((ListNumber) vTable.getColumnData(nColumn), rowIndexes.get(i)));
} else {
columnTypes.add(type);
columnData.add(createView((List<?>) vTable.getColumnData(nColumn), rowIndexes.get(i)));
}
}
}
}
return ValueFactory.newVTable(columnTypes, columnNames, columnData);
}
use of org.diirt.util.array.BufferInt in project yamcs-studio by yamcs.
the class VTableFactory method tableValueFilter.
public static VTable tableValueFilter(VTable table, String columnName, Object value) {
ValueFilter valueFilter = new ValueFilter(table, columnName, value);
BufferInt indexes = new BufferInt();
for (int i = 0; i < table.getRowCount(); i++) {
if (valueFilter.filterRow(i)) {
indexes.addInt(i);
}
}
return extractRows(table, indexes);
}
Aggregations