@@ -17,7 +17,6 @@ public class BasicTable extends AbstractEntity implements Table{
17
17
private List <String > colNames = new ArrayList <String >();
18
18
private Map <String , Integer > colNamesIndex = new HashMap <String , Integer >();
19
19
private int [] colCompresses = null ;
20
- private int colRows ;
21
20
22
21
public BasicTable (ExtendedDataInput in ) throws IOException {
23
22
int rows = in .readInt ();
@@ -61,7 +60,6 @@ public BasicTable(ExtendedDataInput in) throws IOException{
61
60
}
62
61
if (vector .rows () != rows && vector .rows ()!= 1 )
63
62
throw new IOException ("The number of rows for column " + colNames .get (i ) + " is not consistent with other columns" );
64
- this .colRows = rows ;
65
63
columns .add (vector );
66
64
}
67
65
if (collection != null )
@@ -73,10 +71,10 @@ public BasicTable(final List<String> colNames, final List<Vector> cols) {
73
71
throw new Error ("The length of column name and column data is unequal." );
74
72
}
75
73
76
- this . colRows = cols .get (0 ).rows ();
74
+ int rowsCount = cols .get (0 ).rows ();
77
75
for (int i =0 ;i <cols .size ();i ++) {
78
76
Vector v = cols .get (i );
79
- if (v .rows () != this . colRows )
77
+ if (v .rows () != rowsCount )
80
78
throw new Error ("The length of column " + colNames .get (i ) + " must be the same as the first column length." );
81
79
}
82
80
this .setColName (colNames );
@@ -171,7 +169,7 @@ public int rows() {
171
169
if (columns ()<=0 )
172
170
return 0 ;
173
171
else
174
- return this . colRows ;
172
+ return columns . get ( 0 ). rows () ;
175
173
}
176
174
177
175
@ Override
@@ -390,13 +388,12 @@ public void addColumn(String colName, Vector col) {
390
388
if (colNames .contains (colName ))
391
389
throw new RuntimeException ("The table already contains column '" + colName + "'." );
392
390
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 () +"." );
395
393
396
394
colNames .add (colName );
397
395
colNamesIndex .put (colName , colNamesIndex .size ());
398
396
columns .add (col );
399
- this .colRows = col .rows ();
400
397
}
401
398
402
399
@ Override
@@ -407,8 +404,8 @@ public void replaceColumn(String colName, Vector col) {
407
404
if (!colNames .contains (colName ))
408
405
throw new RuntimeException ("The column '" + colName + "' to be replaced doesn't exist in the table." );
409
406
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 () +"." );
412
409
413
410
int index = colNames .indexOf (colName );
414
411
columns .set (index , col );
0 commit comments