use of com.google.refine.model.Column in project OpenRefine by OpenRefine.
the class MassRowColumnChange method save.
@Override
public void save(Writer writer, Properties options) throws IOException {
writer.write("newColumnCount=");
writer.write(Integer.toString(_newColumns.size()));
writer.write('\n');
for (Column column : _newColumns) {
column.save(writer);
writer.write('\n');
}
writer.write("oldColumnCount=");
writer.write(Integer.toString(_oldColumns.size()));
writer.write('\n');
for (Column column : _oldColumns) {
column.save(writer);
writer.write('\n');
}
writer.write("newRowCount=");
writer.write(Integer.toString(_newRows.size()));
writer.write('\n');
for (Row row : _newRows) {
row.save(writer, options);
writer.write('\n');
}
writer.write("oldRowCount=");
writer.write(Integer.toString(_oldRows.size()));
writer.write('\n');
for (Row row : _oldRows) {
row.save(writer, options);
writer.write('\n');
}
ColumnChange.writeOldColumnGroups(writer, options, _oldColumnGroups);
// end of change marker
writer.write("/ec/\n");
}
use of com.google.refine.model.Column in project OpenRefine by OpenRefine.
the class ImporterUtilities method setupColumns.
public static void setupColumns(Project project, List<String> columnNames) {
Map<String, Integer> nameToIndex = new HashMap<String, Integer>();
for (int c = 0; c < columnNames.size(); c++) {
String cell = columnNames.get(c).trim();
if (cell.isEmpty()) {
cell = "Column";
} else if (cell.startsWith("\"") && cell.endsWith("\"")) {
// FIXME: is trimming quotation marks appropriate?
cell = cell.substring(1, cell.length() - 1).trim();
}
if (nameToIndex.containsKey(cell)) {
int index = nameToIndex.get(cell);
nameToIndex.put(cell, index + 1);
cell = cell.contains(" ") ? (cell + " " + index) : (cell + index);
} else {
nameToIndex.put(cell, 2);
}
columnNames.set(c, cell);
if (project.columnModel.getColumnByName(cell) == null) {
Column column = new Column(project.columnModel.allocateNewCellIndex(), cell);
try {
project.columnModel.addColumn(project.columnModel.columns.size(), column, false);
} catch (ModelException e) {
// Ignore: shouldn't get in here since we just checked for duplicate names.
}
}
}
}
use of com.google.refine.model.Column in project OpenRefine by OpenRefine.
the class CellChange method apply.
@Override
public void apply(Project project) {
project.rows.get(row).setCell(cellIndex, newCell);
Column column = project.columnModel.getColumnByCellIndex(cellIndex);
column.clearPrecomputes();
ProjectManager.singleton.getInterProjectModel().flushJoinsInvolvingProjectColumn(project.id, column.getName());
}
use of com.google.refine.model.Column in project OpenRefine by OpenRefine.
the class ColumnAdditionChange method apply.
@Override
public void apply(Project project) {
synchronized (project) {
if (_newCellIndex < 0) {
_newCellIndex = project.columnModel.allocateNewCellIndex();
}
int columnGroupCount = project.columnModel.columnGroups.size();
_oldColumnGroups = new ArrayList<ColumnGroup>(columnGroupCount);
for (int i = columnGroupCount - 1; i >= 0; i--) {
ColumnGroup columnGroup = project.columnModel.columnGroups.get(i);
_oldColumnGroups.add(columnGroup);
if (columnGroup.startColumnIndex <= _columnIndex) {
if (columnGroup.startColumnIndex + columnGroup.columnSpan > _columnIndex) {
// the new column is inserted right in the middle of the group
project.columnModel.columnGroups.set(i, new ColumnGroup(columnGroup.startColumnIndex, columnGroup.columnSpan + 1, columnGroup.keyColumnIndex < _columnIndex ? columnGroup.keyColumnIndex : (columnGroup.keyColumnIndex + 1)));
}
} else {
// the new column precedes this whole group
project.columnModel.columnGroups.set(i, new ColumnGroup(columnGroup.startColumnIndex + 1, columnGroup.columnSpan, columnGroup.keyColumnIndex + 1));
}
}
Column column = new Column(_newCellIndex, _columnName);
project.columnModel.columns.add(_columnIndex, column);
try {
for (CellAtRow cell : _newCells) {
project.rows.get(cell.row).setCell(_newCellIndex, cell.cell);
}
} catch (Exception e) {
e.printStackTrace();
}
project.update();
}
}
use of com.google.refine.model.Column in project OpenRefine by OpenRefine.
the class ColumnReorderChange method save.
@Override
public void save(Writer writer, Properties options) throws IOException {
writer.write("columnNameCount=");
writer.write(Integer.toString(_columnNames.size()));
writer.write('\n');
for (String n : _columnNames) {
writer.write(n);
writer.write('\n');
}
writer.write("oldColumnCount=");
writer.write(Integer.toString(_oldColumns.size()));
writer.write('\n');
for (Column c : _oldColumns) {
c.save(writer);
writer.write('\n');
}
writer.write("newColumnCount=");
writer.write(Integer.toString(_newColumns.size()));
writer.write('\n');
for (Column c : _newColumns) {
c.save(writer);
writer.write('\n');
}
writeOldColumnGroups(writer, options, _oldColumnGroups);
// end of change marker
writer.write("/ec/\n");
}
Aggregations