Package com.google.refine.model

Examples of com.google.refine.model.Row


       
        List<Row> newRows = new ArrayList<Row>();
       
        int oldRowCount = project.rows.size();
        for (int r = 0; r < oldRowCount; r++) {
            Row oldRow = project.rows.get(r);
           
            if (oldRow.isCellBlank(keyCellIndex)) {
                newRows.add(oldRow.dup());
                continue;
            }
           
            int r2 = r + 1;
            while (r2 < oldRowCount && project.rows.get(r2).isCellBlank(keyCellIndex)) {
                r2++;
            }
           
            if (r2 == r + 1) {
                newRows.add(oldRow.dup());
                continue;
            }
           
            StringBuffer sb = new StringBuffer();
            for (int r3 = r; r3 < r2; r3++) {
                Object value = project.rows.get(r3).getCellValue(cellIndex);
                if (ExpressionUtils.isNonBlankData(value)) {
                    if (sb.length() > 0) {
                        sb.append(_separator);
                    }
                    sb.append(value.toString());
                }
            }
           
            for (int r3 = r; r3 < r2; r3++) {
                Row newRow = project.rows.get(r3).dup();
                if (r3 == r) {
                    newRow.setCell(cellIndex, new Cell(sb.toString(), null));
                } else {
                    newRow.setCell(cellIndex, null);
                }
               
                if (!newRow.isEmpty()) {
                    newRows.add(newRow);
                }
            }
           
            r = r2 - 1; // r will be incremented by the for loop anyway
View Full Code Here


        }
       
        List<Row> oldRows = project.rows;
        List<Row> newRows = new ArrayList<Row>(oldRows.size() / _rowCount);
        for (int r = 0; r < oldRows.size(); r += _rowCount) {
            Row firstNewRow = new Row(newColumns.size());
           
            for (int r2 = 0; r2 < _rowCount && r + r2 < oldRows.size(); r2++) {
                Row oldRow = oldRows.get(r + r2);
                Row newRow = r2 == 0 ? firstNewRow : new Row(newColumns.size());
                boolean hasData = r2 == 0;
               
                for (int c = 0; c < oldColumns.size(); c++) {
                    Column column = oldColumns.get(c);
                    Cell cell = oldRow.getCell(column.getCellIndex());
                   
                    if (cell != null && cell.value != null) {
                        if (c == columnIndex) {
                            firstNewRow.setCell(columnIndex + r2, cell);
                        } else if (c < columnIndex) {
                            newRow.setCell(c, cell);
                            hasData = true;
                        } else {
                            newRow.setCell(c + _rowCount - 1, cell);
                            hasData = true;
                        }
                    }
                }
               
View Full Code Here

        }
       
        List<Row> oldRows = project.rows;
        List<Row> newRows = new ArrayList<Row>(oldRows.size() * columnCount);
        for (int r = 0; r < oldRows.size(); r++) {
            Row oldRow = project.rows.get(r);
            Row firstNewRow = new Row(newColumns.size());
            int firstNewRowIndex = newRows.size();
           
            newRows.add(firstNewRow);
           
            int transposedCells = 0;
            for (int c = 0; c < oldColumns.size(); c++) {
                Column column = oldColumns.get(c);
                Cell cell = oldRow.getCell(column.getCellIndex());
               
                if (c < startColumnIndex) {
                    firstNewRow.setCell(c, cell);
                } else if (c == startColumnIndex || c < startColumnIndex + columnCount) {
                    if (_combinedColumnName != null) {
                        Cell newCell;
                        if (cell == null || cell.value == null) {
                            if (_prependColumnName && !_ignoreBlankCells) {
                                newCell = new Cell(column.getName() + _separator, null);
                            } else {
                                continue;
                            }
                        } else if (_prependColumnName) {
                            newCell = new Cell(column.getName() + _separator + cell.value, null);
                        } else {
                            newCell = cell;
                        }
                       
                        Row rowToModify;
                        if (transposedCells == 0) {
                            rowToModify = firstNewRow;
                        } else {
                            rowToModify = new Row(newColumns.size());
                            newRows.add(rowToModify);
                        }
                        rowToModify.setCell(startColumnIndex, newCell);
                       
                        transposedCells++;
                    } else {
                        if (_ignoreBlankCells && (cell == null || cell.value == null)) {
                            continue;
                        }
                       
                        Row rowToModify;
                        if (transposedCells == 0) {
                            rowToModify = firstNewRow;
                        } else {
                            rowToModify = new Row(newColumns.size());
                            newRows.add(rowToModify);
                        }
                        rowToModify.setCell(startColumnIndex, new Cell(column.getName(), null));
                        rowToModify.setCell(startColumnIndex + 1, cell);
                       
                        transposedCells++;
                    }
                   
                } else {
                    firstNewRow.setCell(
                        c - columnCount + (_combinedColumnName != null ? 1 : 2),
                        cell);
                }
            }
           
            if (_fillDown) {
                for (int r2 = firstNewRowIndex + 1; r2 < newRows.size(); r2++) {
                    Row newRow = newRows.get(r2);
                    for (int c = 0; c < newColumns.size(); c++) {
                        if (c < startColumnIndex ||
                            (_combinedColumnName != null ?
                                c > startColumnIndex :
                                c > startColumnIndex + 1)) {
                            Column column = newColumns.get(c);
                            int cellIndex = column.getCellIndex();
                           
                            Cell cellToCopy = firstNewRow.getCell(cellIndex);
                            if (cellToCopy != null && newRow.getCell(cellIndex) == null) {
                                newRow.setCell(cellIndex, cellToCopy);
                            }
                        }
                    }
                }
            }
View Full Code Here

                try {
                    visitor.start(project);

                    int c = project.rows.size();
                    for (int rowIndex = 0; rowIndex < c; rowIndex++) {
                        Row row = project.rows.get(rowIndex);
                        if (visitor.visit(project, rowIndex, row)) {
                            break;
                        }
                    }
                } finally {
View Full Code Here

       
        List<Row> newRows = new ArrayList<Row>();
       
        int oldRowCount = project.rows.size();
        for (int r = 0; r < oldRowCount; r++) {
            Row oldRow = project.rows.get(r);
            if (oldRow.isCellBlank(cellIndex)) {
                newRows.add(oldRow.dup());
                continue;
            }
           
            Object value = oldRow.getCellValue(cellIndex);
            String s = value instanceof String ? ((String) value) : value.toString();
            String[] values = null;
            if (_mode.equals("regex")) {
                values = s.split(_separator);
            } else {
                values = StringUtils.splitByWholeSeparatorPreserveAllTokens(s, _separator);
            }
           
            if (values.length < 2) {
                newRows.add(oldRow.dup());
                continue;
            }
           
            // First value goes into the same row
            {
                Row firstNewRow = oldRow.dup();
                firstNewRow.setCell(cellIndex, new Cell(values[0].trim(), null));
               
                newRows.add(firstNewRow);
            }
           
            int r2 = r + 1;
            for (int v = 1; v < values.length; v++) {
                Cell newCell = new Cell(values[v].trim(), null);
               
                if (r2 < project.rows.size()) {
                    Row oldRow2 = project.rows.get(r2);
                    if (oldRow2.isCellBlank(cellIndex) &&
                        oldRow2.isCellBlank(keyCellIndex)) {
                       
                        Row newRow = oldRow2.dup();
                        newRow.setCell(cellIndex, newCell);
                       
                        newRows.add(newRow);
                        r2++;
                       
                        continue;
                    }
                }
               
                Row newRow = new Row(cellIndex + 1);
                newRow.setCell(cellIndex, newCell);
               
                newRows.add(newRow);
            }
           
            r = r2 - 1; // r will be incremented by the for loop anyway
View Full Code Here

    protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
        List<Row> newRows = new ArrayList<Row>();
       
        List<Row> oldRows = project.rows;
        for (int r = 0; r < oldRows.size(); r++) {
            Row oldRow = oldRows.get(r);
            Row newRow = null;
           
            RowDependency rd = project.recordModel.getRowDependency(r);
            if (rd.cellDependencies != null) {
                newRow = oldRow.dup();

                for (CellDependency cd : rd.cellDependencies) {
                    if (cd != null) {
                        int contextRowIndex = cd.rowIndex;
                        int contextCellIndex = cd.cellIndex;

                        if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
                            Row contextRow = oldRows.get(contextRowIndex);
                            Cell contextCell = contextRow.getCell(contextCellIndex);

                            newRow.setCell(contextCellIndex, contextCell);
                        }
                    }
                }
View Full Code Here

    protected void iterate(Project project, RowEvaluable rowEvaluable, List<Long> allValues) {
       
        Properties bindings = ExpressionUtils.createBindings(project);
       
        for (int i = 0; i < project.rows.size(); i++) {
            Row row = project.rows.get(i);
           
            preprocessing();
           
            processRow(project, rowEvaluable, allValues, i, row, bindings);
           
View Full Code Here

        row.flagged = newFlagged;
    }

    @Override
    public void revert(Project project) {
        Row row = project.rows.get(rowIndex);
       
        row.flagged = oldFlagged;
    }
View Full Code Here

               
                for (int i = 0; i < _rowIndices.size(); i++) {
                    int r = _rowIndices.get(i);
                    List<Serializable> tuple = _tuples.get(i);
               
                    Row oldRow = project.rows.get(r);
                    Row newRow = oldRow.dup();
                   
                    _oldRows.add(oldRow);
                    _newRows.add(newRow);
                   
                    for (int c = 0; c < tuple.size(); c++) {
                        Serializable value = tuple.get(c);
                        if (value != null) {
                            newRow.setCell(_firstNewCellIndex + c, new Cell(value, null));
                        }
                    }
                   
                    if (_removeOriginalColumn) {
                        newRow.setCell(cellIndex, null);
                    }
                }
            }
           
            int columnGroupCount = project.columnModel.columnGroups.size();
            int columnCountChange = _columnNames.size() - (_removeOriginalColumn ? 1 : 0);
            _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 column being split is in the middle of the group
                       
                        if (columnGroup.keyColumnIndex == _columnIndex) {
                            if (_removeOriginalColumn) {
                                // the key column is being split and removed
                                project.columnModel.columnGroups.remove(i);
                            } else {
                                project.columnModel.columnGroups.set(i, new ColumnGroup(
                                    columnGroup.startColumnIndex,
                                    columnGroup.columnSpan + columnCountChange,
                                    columnGroup.keyColumnIndex
                                ));
                            }
                        } else {
                            project.columnModel.columnGroups.set(i, new ColumnGroup(
                                columnGroup.startColumnIndex,
                                columnGroup.columnSpan + columnCountChange,
                                columnGroup.keyColumnIndex < _columnIndex ?
                                    columnGroup.keyColumnIndex :
                                    (columnGroup.keyColumnIndex + columnCountChange)
                            ));
                        }
                    }
                } else {
                    // the new column precedes this whole group
                    project.columnModel.columnGroups.set(i, new ColumnGroup(
                        columnGroup.startColumnIndex + columnCountChange,
                        columnGroup.columnSpan,
                        columnGroup.keyColumnIndex + columnCountChange
                    ));
                }
            }
           
            for (int i = 0; i < _rowIndices.size(); i++) {
                int r = _rowIndices.get(i);
                Row newRow = _newRows.get(i);
               
                project.rows.set(r, newRow);
            }
           
            for (int i = 0; i < _columnNames.size(); i++) {
View Full Code Here

    @Override
    public void revert(Project project) {
        synchronized (project) {
            for (int i = 0; i < _rowIndices.size(); i++) {
                int r = _rowIndices.get(i);
                Row oldRow = _oldRows.get(i);
               
                project.rows.set(r, oldRow);
            }
           
            if (_removeOriginalColumn) {
View Full Code Here

TOP

Related Classes of com.google.refine.model.Row

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.