@@ -17,7 +17,6 @@ public class BasicTable extends AbstractEntity implements Table{
1717 private List <String > colNames = new ArrayList <String >();
1818 private Map <String , Integer > colNamesIndex = new HashMap <String , Integer >();
1919 private int [] colCompresses = null ;
20- private int colRows ;
2120
2221 public BasicTable (ExtendedDataInput in ) throws IOException {
2322 int rows = in .readInt ();
@@ -61,7 +60,6 @@ public BasicTable(ExtendedDataInput in) throws IOException{
6160 }
6261 if (vector .rows () != rows && vector .rows ()!= 1 )
6362 throw new IOException ("The number of rows for column " + colNames .get (i ) + " is not consistent with other columns" );
64- this .colRows = rows ;
6563 columns .add (vector );
6664 }
6765 if (collection != null )
@@ -73,10 +71,10 @@ public BasicTable(final List<String> colNames, final List<Vector> cols) {
7371 throw new Error ("The length of column name and column data is unequal." );
7472 }
7573
76- this . colRows = cols .get (0 ).rows ();
74+ int rowsCount = cols .get (0 ).rows ();
7775 for (int i =0 ;i <cols .size ();i ++) {
7876 Vector v = cols .get (i );
79- if (v .rows () != this . colRows )
77+ if (v .rows () != rowsCount )
8078 throw new Error ("The length of column " + colNames .get (i ) + " must be the same as the first column length." );
8179 }
8280 this .setColName (colNames );
@@ -171,7 +169,7 @@ public int rows() {
171169 if (columns ()<=0 )
172170 return 0 ;
173171 else
174- return this . colRows ;
172+ return columns . get ( 0 ). rows () ;
175173 }
176174
177175 @ Override
@@ -390,13 +388,12 @@ public void addColumn(String colName, Vector col) {
390388 if (colNames .contains (colName ))
391389 throw new RuntimeException ("The table already contains column '" + colName + "'." );
392390
393- if (this .colRows != 0 && col . rows () != this . colRows )
394- throw new RuntimeException ("The length of column " + colName + " must be the same as the first column length: " + this .colRows +"." );
391+ if (Objects . nonNull ( this .columns ) && Objects . nonNull ( this . columns . get ( 0 )) && this . getColumn ( 0 ). rows () != col . rows () )
392+ throw new RuntimeException ("The length of column " + colName + " must be the same as the first column length: " + this .getColumn ( 0 ). rows () +"." );
395393
396394 colNames .add (colName );
397395 colNamesIndex .put (colName , colNamesIndex .size ());
398396 columns .add (col );
399- this .colRows = col .rows ();
400397 }
401398
402399 @ Override
@@ -407,8 +404,8 @@ public void replaceColumn(String colName, Vector col) {
407404 if (!colNames .contains (colName ))
408405 throw new RuntimeException ("The column '" + colName + "' to be replaced doesn't exist in the table." );
409406
410- if (this .colRows != 0 && col . rows () != this . colRows )
411- throw new RuntimeException ("The length of column " + colName + " must be the same as the first column length: " + this .colRows +"." );
407+ if (Objects . nonNull ( this .columns ) && Objects . nonNull ( this . columns . get ( 0 )) && this . getColumn ( 0 ). rows () != col . rows () )
408+ throw new RuntimeException ("The length of column " + colName + " must be the same as the first column length: " + this .getColumn ( 0 ). rows () +"." );
412409
413410 int index = colNames .indexOf (colName );
414411 columns .set (index , col );
0 commit comments