connectionUtils/src/main/java/com/ge/research/semtk/resultSet/Table.java
public static Table merge(ArrayList<Table> tables) throws Exception {

		if(tables == null || tables.size() == 0){
			throw new Exception("Cannot merge tables: no tables provided");
		}
		if(tables.size() == 1){
			return tables.get(0);  	// if only one table given, then pass it back
		}
		
		String[] mergedTableCols = null;
		String[] mergedTableColTypes = null;
		ArrayList<ArrayList<String>> mergedTableRows = new ArrayList<ArrayList<String>>();
		ArrayList<String> rowReordered;
		
		for(Table t : tables){
		
			if(mergedTableCols == null){  	// for the first table...				
				mergedTableCols = t.getColumnNames();
				mergedTableColTypes = t.getColumnTypes();
				mergedTableRows = t.getRows();
			}else{							// for subsequent tables...											
				if(!Utility.arraysSameMinusOrder(mergedTableCols, t.getColumnNames())){
					throw new Exception("Cannot merge tables: column set is not the same");
				}
				if(!Utility.arraysSameMinusOrder(mergedTableColTypes, t.getColumnTypes())){
					throw new Exception("Cannot merge tables: column type set is not the same");
				}
				// TODO should also check that the column-type PAIRS are the same
				
				// reorder and collect the table's rows
				for(ArrayList<String> row : t.getRows()){
					rowReordered = new ArrayList<String>();
					if(Arrays.equals(mergedTableCols, t.getColumnNames())){						
						rowReordered = row; // columns are in the same order, faster to just add the row as is
					}else{
						// columns are not in the same order - reorder the row 
						for(String col : mergedTableCols){
							int i = Arrays.asList(t.getColumnNames()).indexOf(col);
							rowReordered.add(row.get(i));
						}						
					}
					mergedTableRows.add(rowReordered);  // collect the (reordered) row
				}			
			}			
		}
		
		// return the merged table
		return new Table(mergedTableCols, mergedTableColTypes, mergedTableRows);
	}
/**
	 * Merge multiple tables into a single table
	 * @param tables
	 * @return
	 * @throws Exception
	 */
Merge multiple tables into a single table
@param tables
@return
@throws Exception
Merge multiple tables into a single table @param tables @return @throws Exception
public static Table merge(ArrayList<Table> tables) throws Exception {
		if(tables == null || tables.size() == 0){
			throw new Exception("Cannot merge tables: no tables provided");
		}
		if(tables.size() == 1){
			return tables.get(0);  	
		}
		String[] mergedTableCols = null;
		String[] mergedTableColTypes = null;
		ArrayList<ArrayList<String>> mergedTableRows = new ArrayList<ArrayList<String>>();
		ArrayList<String> rowReordered;
		for(Table t : tables){
			if(mergedTableCols == null){  	
				mergedTableCols = t.getColumnNames();
				mergedTableColTypes = t.getColumnTypes();
				mergedTableRows = t.getRows();
			}else{							
				if(!Utility.arraysSameMinusOrder(mergedTableCols, t.getColumnNames())){
					throw new Exception("Cannot merge tables: column set is not the same");
				}
				if(!Utility.arraysSameMinusOrder(mergedTableColTypes, t.getColumnTypes())){
					throw new Exception("Cannot merge tables: column type set is not the same");
				}
				for(ArrayList<String> row : t.getRows()){
					rowReordered = new ArrayList<String>();
					if(Arrays.equals(mergedTableCols, t.getColumnNames())){						
						rowReordered = row; 
					}else{
						for(String col : mergedTableCols){
							int i = Arrays.asList(t.getColumnNames()).indexOf(col);
							rowReordered.add(row.get(i));
						}						
					}
					mergedTableRows.add(rowReordered);  
				}			
			}			
		}
		return new Table(mergedTableCols, mergedTableColTypes, mergedTableRows);
	}
public static Table merge ( ArrayList < Table > tables ) throws Exception { if ( tables == null || tables . size ( ) == 0 ) { throw new Exception ( "Cannot merge tables: no tables provided" ) ; } if ( tables . size ( ) == 1 ) { return tables . get ( 0 ) ; } String [ ] mergedTableCols = null ; String [ ] mergedTableColTypes = null ; ArrayList < ArrayList < String > > mergedTableRows = new ArrayList < ArrayList < String > > ( ) ; ArrayList < String > rowReordered ; for ( Table t : tables ) { if ( mergedTableCols == null ) { mergedTableCols = t . getColumnNames ( ) ; mergedTableColTypes = t . getColumnTypes ( ) ; mergedTableRows = t . getRows ( ) ; } else { if ( ! Utility . arraysSameMinusOrder ( mergedTableCols , t . getColumnNames ( ) ) ) { throw new Exception ( "Cannot merge tables: column set is not the same" ) ; } if ( ! Utility . arraysSameMinusOrder ( mergedTableColTypes , t . getColumnTypes ( ) ) ) { throw new Exception ( "Cannot merge tables: column type set is not the same" ) ; } for ( ArrayList < String > row : t . getRows ( ) ) { rowReordered = new ArrayList < String > ( ) ; if ( Arrays . equals ( mergedTableCols , t . getColumnNames ( ) ) ) { rowReordered = row ; } else { for ( String col : mergedTableCols ) { int i = Arrays . asList ( t . getColumnNames ( ) ) . indexOf ( col ) ; rowReordered . add ( row . get ( i ) ) ; } } mergedTableRows . add ( rowReordered ) ; } } } return new Table ( mergedTableCols , mergedTableColTypes , mergedTableRows ) ; }
Merge multiple tables into a single table
 @param tables
 @return
 @throws Exception
Merge multiple tables into a single table @param tables @return @throws Exception
// if only one table given, then pass it back // for the first table...				 // for subsequent tables...											 // TODO should also check that the column-type PAIRS are the same // reorder and collect the table's rows // columns are in the same order, faster to just add the row as is // columns are not in the same order - reorder the row  // collect the (reordered) row // return the merged table