Skip to content

Commit 0f88552

Browse files
author
chengyitian
committed
AJ-458: add check for replaceColumn method.
1 parent e917787 commit 0f88552

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/com/xxdb/data/BasicTable.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,18 @@ public void addColumn(String colName, Vector col) {
395395

396396
@Override
397397
public void replaceColumn(String colName, Vector col) {
398-
if (colNames.contains(colName)) {
399-
int index = colNames.indexOf(colName);
400-
columns.set(index, col);
401-
} else {
402-
colNames.add(colName);
403-
columns.add(col);
404-
colNamesIndex.put(colName, colNamesIndex.size());
405-
}
398+
if (Objects.isNull(colName) || Objects.isNull(col))
399+
throw new RuntimeException("The param 'colName' or 'col' in table cannot be null.");
400+
401+
if (!colNames.contains(colName))
402+
throw new RuntimeException("The column '" + colName + "' to be replaced doesn't exist in the table.");
403+
404+
if (this.colRows != 0 && col.rows() != this.colRows)
405+
throw new RuntimeException("The length of column " + colName + " must be the same as the first column length: " + this.colRows +".");
406+
407+
colNames.add(colName);
408+
colNamesIndex.put(colName, colNamesIndex.size());
409+
columns.add(col);
410+
this.colRows = col.rows();
406411
}
407412
}

0 commit comments

Comments
 (0)