@@ -17,6 +17,7 @@ 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 ;
2021
2122 public BasicTable (ExtendedDataInput in ) throws IOException {
2223 int rows = in .readInt ();
@@ -60,6 +61,7 @@ public BasicTable(ExtendedDataInput in) throws IOException{
6061 }
6162 if (vector .rows () != rows && vector .rows ()!= 1 )
6263 throw new IOException ("The number of rows for column " + colNames .get (i ) + " is not consistent with other columns" );
64+ this .colRows = rows ;
6365 columns .add (vector );
6466 }
6567 if (collection != null )
@@ -70,10 +72,11 @@ public BasicTable(final List<String> colNames, final List<Vector> cols) {
7072 if (colNames .size () != cols .size ()){
7173 throw new Error ("The length of column name and column data is unequal." );
7274 }
73- int rowsCount = cols .get (0 ).rows ();
75+
76+ this .colRows = cols .get (0 ).rows ();
7477 for (int i =0 ;i <cols .size ();i ++) {
7578 Vector v = cols .get (i );
76- if (v .rows () != rowsCount )
79+ if (v .rows () != this . colRows )
7780 throw new Error ("The length of column " + colNames .get (i ) + " must be the same as the first column length." );
7881 }
7982 this .setColName (colNames );
@@ -165,7 +168,7 @@ public int rows() {
165168 if (columns ()<=0 )
166169 return 0 ;
167170 else
168- return columns . get ( 0 ). rows () ;
171+ return this . colRows ;
169172 }
170173
171174 @ Override
@@ -380,9 +383,14 @@ public void addColumn(String colName, Vector col) {
380383
381384 if (colNames .contains (colName ))
382385 throw new RuntimeException ("The table already contains column '" + colName + "'." );
386+
387+ if (this .colRows != 0 && col .rows () != this .colRows )
388+ throw new RuntimeException ("The length of column " + colName + " must be the same as the first column length: " + this .colRows +"." );
389+
383390 colNames .add (colName );
384391 colNamesIndex .put (colName , colNamesIndex .size ());
385392 columns .add (col );
393+ this .colRows = col .rows ();
386394 }
387395
388396 @ Override
0 commit comments