Replace tabs with spaces. No functional changes.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1942 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2010-11-29 06:27:06 +00:00
parent 3a8f9306bd
commit a560cb56df

View File

@ -46,56 +46,56 @@ import com.google.refine.Jsonizable;
import com.google.refine.expr.ExpressionUtils; import com.google.refine.expr.ExpressionUtils;
public class RecordModel implements Jsonizable { public class RecordModel implements Jsonizable {
final static public class CellDependency { final static public class CellDependency {
final public int rowIndex; final public int rowIndex;
final public int cellIndex; final public int cellIndex;
public CellDependency(int rowIndex, int cellIndex) { public CellDependency(int rowIndex, int cellIndex) {
this.rowIndex = rowIndex; this.rowIndex = rowIndex;
this.cellIndex = cellIndex; this.cellIndex = cellIndex;
} }
} }
final static public class RowDependency { final static public class RowDependency {
public int recordIndex; public int recordIndex;
public CellDependency[] cellDependencies; public CellDependency[] cellDependencies;
public List<Integer> contextRows; public List<Integer> contextRows;
} }
protected List<RowDependency> _rowDependencies; protected List<RowDependency> _rowDependencies;
protected List<Record> _records; protected List<Record> _records;
public RowDependency getRowDependency(int rowIndex) { public RowDependency getRowDependency(int rowIndex) {
return _rowDependencies != null && rowIndex >= 0 && rowIndex < _rowDependencies.size() ? return _rowDependencies != null && rowIndex >= 0 && rowIndex < _rowDependencies.size() ?
_rowDependencies.get(rowIndex) : null; _rowDependencies.get(rowIndex) : null;
} }
public int getRecordCount() { public int getRecordCount() {
return _records.size(); return _records.size();
} }
public Record getRecord(int recordIndex) { public Record getRecord(int recordIndex) {
return _records != null && recordIndex >= 0 && recordIndex < _records.size() ? return _records != null && recordIndex >= 0 && recordIndex < _records.size() ?
_records.get(recordIndex) : null; _records.get(recordIndex) : null;
} }
public Record getRecordOfRow(int rowIndex) { public Record getRecordOfRow(int rowIndex) {
RowDependency rd = getRowDependency(rowIndex); RowDependency rd = getRowDependency(rowIndex);
if (rd != null) { if (rd != null) {
if (rd.recordIndex < 0) { if (rd.recordIndex < 0) {
rd = getRowDependency(rd.contextRows.get(0)); rd = getRowDependency(rd.contextRows.get(0));
} }
return getRecord(rd.recordIndex); return getRecord(rd.recordIndex);
} }
return null; return null;
} }
synchronized public void write(JSONWriter writer, Properties options) synchronized public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("hasRecords"); writer.value(_records.size() < _rowDependencies.size()); writer.key("hasRecords"); writer.value(_records.size() < _rowDependencies.size());
writer.endObject(); writer.endObject();
} }
static protected class KeyedGroup { static protected class KeyedGroup {
@ -104,83 +104,83 @@ public class RecordModel implements Jsonizable {
} }
synchronized public void update(Project project) { synchronized public void update(Project project) {
synchronized (project) { synchronized (project) {
List<Row> rows = project.rows; List<Row> rows = project.rows;
int rowCount = rows.size(); int rowCount = rows.size();
ColumnModel columnModel = project.columnModel; ColumnModel columnModel = project.columnModel;
List<KeyedGroup> keyedGroups = computeKeyedGroups(columnModel); List<KeyedGroup> keyedGroups = computeKeyedGroups(columnModel);
int groupCount = keyedGroups.size(); int groupCount = keyedGroups.size();
int[] lastNonBlankRowsByGroup = new int[keyedGroups.size()]; int[] lastNonBlankRowsByGroup = new int[keyedGroups.size()];
for (int i = 0; i < lastNonBlankRowsByGroup.length; i++) { for (int i = 0; i < lastNonBlankRowsByGroup.length; i++) {
lastNonBlankRowsByGroup[i] = -1; lastNonBlankRowsByGroup[i] = -1;
} }
_rowDependencies = new ArrayList<RowDependency>(rowCount); _rowDependencies = new ArrayList<RowDependency>(rowCount);
int recordIndex = 0; int recordIndex = 0;
for (int r = 0; r < rowCount; r++) { for (int r = 0; r < rowCount; r++) {
Row row = rows.get(r); Row row = rows.get(r);
RowDependency rowDependency = new RowDependency(); RowDependency rowDependency = new RowDependency();
for (int g = 0; g < groupCount; g++) { for (int g = 0; g < groupCount; g++) {
KeyedGroup group = keyedGroups.get(g); KeyedGroup group = keyedGroups.get(g);
if (!ExpressionUtils.isNonBlankData(row.getCellValue(group.keyCellIndex))) { if (!ExpressionUtils.isNonBlankData(row.getCellValue(group.keyCellIndex))) {
int contextRowIndex = lastNonBlankRowsByGroup[g]; int contextRowIndex = lastNonBlankRowsByGroup[g];
if (contextRowIndex >= 0) { if (contextRowIndex >= 0) {
for (int dependentCellIndex : group.cellIndices) { for (int dependentCellIndex : group.cellIndices) {
if (ExpressionUtils.isNonBlankData(row.getCellValue(dependentCellIndex))) { if (ExpressionUtils.isNonBlankData(row.getCellValue(dependentCellIndex))) {
setRowDependency( setRowDependency(
project, project,
rowDependency, rowDependency,
dependentCellIndex, dependentCellIndex,
contextRowIndex, contextRowIndex,
group.keyCellIndex group.keyCellIndex
); );
} }
} }
} }
} else { } else {
lastNonBlankRowsByGroup[g] = r; lastNonBlankRowsByGroup[g] = r;
} }
} }
if (rowDependency.cellDependencies != null && rowDependency.cellDependencies.length > 0) { if (rowDependency.cellDependencies != null && rowDependency.cellDependencies.length > 0) {
rowDependency.recordIndex = -1; rowDependency.recordIndex = -1;
rowDependency.contextRows = new ArrayList<Integer>(); rowDependency.contextRows = new ArrayList<Integer>();
for (CellDependency cd : rowDependency.cellDependencies) { for (CellDependency cd : rowDependency.cellDependencies) {
if (cd != null) { if (cd != null) {
rowDependency.contextRows.add(cd.rowIndex); rowDependency.contextRows.add(cd.rowIndex);
} }
} }
Collections.sort(rowDependency.contextRows); Collections.sort(rowDependency.contextRows);
} else { } else {
rowDependency.recordIndex = recordIndex++; rowDependency.recordIndex = recordIndex++;
} }
_rowDependencies.add(rowDependency); _rowDependencies.add(rowDependency);
} }
_records = new ArrayList<Record>(recordIndex); _records = new ArrayList<Record>(recordIndex);
if (recordIndex > 0) { if (recordIndex > 0) {
recordIndex = 0; recordIndex = 0;
int recordRowIndex = 0; int recordRowIndex = 0;
for (int r = 1; r < rowCount; r++) { for (int r = 1; r < rowCount; r++) {
RowDependency rd = _rowDependencies.get(r); RowDependency rd = _rowDependencies.get(r);
if (rd.recordIndex >= 0) { if (rd.recordIndex >= 0) {
_records.add(new Record(recordRowIndex, r, recordIndex++)); _records.add(new Record(recordRowIndex, r, recordIndex++));
recordIndex = rd.recordIndex; recordIndex = rd.recordIndex;
recordRowIndex = r; recordRowIndex = r;
} }
} }
_records.add(new Record(recordRowIndex, rowCount, recordIndex++)); _records.add(new Record(recordRowIndex, rowCount, recordIndex++));
} }
} }
} }
protected List<KeyedGroup> computeKeyedGroups(ColumnModel columnModel) { protected List<KeyedGroup> computeKeyedGroups(ColumnModel columnModel) {
@ -236,20 +236,20 @@ public class RecordModel implements Jsonizable {
} }
protected void setRowDependency( protected void setRowDependency(
Project project, Project project,
RowDependency rowDependency, RowDependency rowDependency,
int cellIndex, int cellIndex,
int contextRowIndex, int contextRowIndex,
int contextCellIndex int contextCellIndex
) { ) {
if (rowDependency.cellDependencies == null) { if (rowDependency.cellDependencies == null) {
int count = project.columnModel.getMaxCellIndex() + 1; int count = project.columnModel.getMaxCellIndex() + 1;
rowDependency.cellDependencies = new CellDependency[count]; rowDependency.cellDependencies = new CellDependency[count];
} }
rowDependency.cellDependencies[cellIndex] = rowDependency.cellDependencies[cellIndex] =
new CellDependency(contextRowIndex, contextCellIndex); new CellDependency(contextRowIndex, contextCellIndex);
} }
} }