public static DataSet newEmptyDataSet() { return new DataSetImpl(); }
public DataSet addEmptyRowAt(int row) { _setEmptyRowAt(row, true); return this; }
protected void _setValuesAt(int row, boolean insert, Object... values) { for (int i = 0; i < values.length; i++) { Object value = values[i]; _setValueAt(row, i, value, insert); } }
public DataSet trim(int offset, int rows) { if (offset < 0) { throw new IllegalArgumentException("Offset can't be negative: " + offset); } if (offset == 0 && (rows <= 0 || rows >= this.getRowCount())) { this.rowCountNonTrimmed = -1; return this; } if (offset >= getRowCount()) { throw new IllegalArgumentException("Offset can't be greater than the number of rows: " + offset); } DataSetImpl other = cloneEmpty(); other.rowCountNonTrimmed = getRowCount(); for (int i=0; i<columns.size(); i++) { DataColumn column = columns.get(i); DataColumn colOther = other.getColumns().get(i); List values = column.getValues(); List valOther = colOther.getValues(); for (int j=offset; j<values.size() && j<( offset+rows ); j++) { Object value = values.get(j); valOther.add(value); } } return other; }
public Object convert(DataColumn column, Object value) { if (ColumnType.NUMBER.equals(column.getColumnType())) { return convertToDouble(value); } if (ColumnType.DATE.equals(column.getColumnType())) { return convertToDate(value); } return convertToString(value); }
public DataSetImpl cloneEmpty() { DataSetImpl other = new DataSetImpl(); for (int i=0; i<columns.size(); i++) { DataColumn column = columns.get(i); DataColumn otherCol = column.cloneEmpty(); other.addColumn(otherCol); } return other; }
protected void _setValueAt(int row, int column, Object value, boolean insert) { DataColumn columnObj = getColumnByIndex(column); List l = columnObj.getValues(); if (row > l.size()) { throw new IllegalArgumentException("The row index " + row + " is out of bounds: " + (l.size()-1)); } Object _val = convert(columnObj, value); if (row < 0 || row == l.size()) l.add(_val); else if (insert) l.add(row, _val); else l.set(row, _val); }
public DataSet setValuesAt(int row, Object... values) { _setValuesAt(row, false, values); return this; }
public DataSet addColumn(String id, ColumnType type) { return addColumn(id, type, null); }
public DataSet trim(int offset, int rows) { if (offset < 0) { throw new IllegalArgumentException("Offset can't be negative: " + offset); } if (offset == 0 && (rows <= 0 || rows >= this.getRowCount())) { this.rowCountNonTrimmed = -1; return this; } if (offset > getRowCount()) { throw new IllegalArgumentException("Offset can't be greater than the number of rows: " + offset); } DataSetImpl other = cloneEmpty(); other.rowCountNonTrimmed = getRowCount(); for (int i=0; i<columns.size(); i++) { DataColumn column = columns.get(i); DataColumn colOther = other.getColumns().get(i); List values = column.getValues(); List valOther = colOther.getValues(); for (int j=offset; j<values.size() && j<( offset+rows ); j++) { Object value = values.get(j); valOther.add(value); } } return other; }
public Object convert(DataColumn column, Object value) { if (ColumnType.NUMBER.equals(column.getColumnType())) { return convertToDouble(value); } if (ColumnType.DATE.equals(column.getColumnType())) { return convertToDate(value); } return convertToString(value); }
public DataSetImpl cloneEmpty() { DataSetImpl other = new DataSetImpl(); for (int i=0; i<columns.size(); i++) { DataColumn column = columns.get(i); DataColumn otherCol = column.cloneEmpty(); other.addColumn(otherCol); } return other; }
protected void _setValueAt(int row, int column, Object value, boolean insert) { DataColumn columnObj = getColumnByIndex(column); List l = columnObj.getValues(); if (row > l.size()) { throw new IllegalArgumentException("The row index " + row + " is out of bounds: " + (l.size()-1)); } Object _val = convert(columnObj, value); if (row < 0 || row == l.size()) l.add(_val); else if (insert) l.add(row, _val); else l.set(row, _val); }
public DataSet addValues(Object... values) { _setValuesAt(-1, true, values); return this; }
public DataSet addColumn(String id, ColumnType type) { return addColumn(id, type, null); }
public DataSet trim(List<Integer> rows) { if (rows == null) { return this; } DataSetImpl other = cloneEmpty(); other.rowCountNonTrimmed = getRowCount(); if (rows.isEmpty()) return other; for (int i=0; i<columns.size(); i++) { List values = columns.get(i).getValues(); List valOther = other.getColumns().get(i).getValues(); for (Integer row : rows) { if (row >= values.size()) { throw new IllegalArgumentException("Row number is out of bounds: " + row); } Object value = values.get(row); valOther.add(value); } } return other; }
public DataSetImpl cloneInstance() { DataSetImpl other = new DataSetImpl(); for (int i=0; i<columns.size(); i++) { DataColumn column = columns.get(i); DataColumn otherCol = column.cloneInstance(); other.addColumn(otherCol); } return other; }
public DataSet addValueAt(int column, Object value) { _setValueAt(-1, column, value, true); return this; }
public DataSet addValuesAt(int row, Object... values) { _setValuesAt(row, true, values); return this; }
public DataSet addEmptyRowAt(int row) { _setEmptyRowAt(row, true); return this; }