import java.util.*;

public class Table {	
	String tableName;
	ArrayList<Record> alRecord;
	ArrayList<Field> alField;
	
//=====================================================================	
// Constructor for Table Class	
//=====================================================================	
	public Table(ArrayList<Field> _alField, String _tableName){
		
		tableName = _tableName;
		alField = _alField;
		alRecord = new ArrayList<Record>();
	}


// Can create table before creating field information =================
	public Table(String _tableName){
		
		tableName = _tableName;
		alRecord = new ArrayList<Record>();
	}

//=====================================================================
//	Get Field Index to get Field Object in alField
//=====================================================================		
	public int getFieldIdx(Field _field){
		int idx = -1;
		for (int i=0;i<alField.size();i++){
			if(alField.get(i).compareTo(_field)==0){
				idx = i;
				break;
			}				
		}
		return idx;
	}
	
	public int getFieldIdx(String _fname){
		int idx = -1;
		for (int i=0;i<alField.size();i++){
			if(alField.get(i).compareTo(_fname)==0){
				idx = i;
				break;
			}				
		}
		return idx;
	}
	
//=====================================================================
//	Get Field with Field Name
//=====================================================================		
	public Field getField(String _fname){
		int index = getFieldIdx(_fname);
//		if(index >=0)
			return alField.get(index);
//		else
//			throw Exception
	}
	
//=====================================================================	
// Add Record to Table
// 	Return 	true : success to add
//			false : Fail to add (Non valid Field)	
//=====================================================================		
	public boolean addRow(Record _record){	
		ArrayList<Value> alValueTemp = _record.getAlRecord();		
		
		if(alValueTemp.size() > alField.size()){
			System.out.println("Input record size is bigger than the Table's field size");
			return false;
		}
		
		for (int i=0;i<alValueTemp.size();i++){
			for (int j=i+1;j<alValueTemp.size();j++){
				if(alValueTemp.get(i).field.compareTo(alValueTemp.get(j).field) ==0 ){
					System.out.println("There is a duplicate Field in the Record");
					return false;		
				}
			}
		}
		
		for (int i=0; i< alValueTemp.size();i++){
			boolean found = false;
			
			for (int j=0; j< alField.size();j++){				
				if(alValueTemp.get(i).field.compareTo(alField.get(j)) == 0){
					found = true;
					break;	
				}
			}
			
			if(!found){
				System.out.println("Target record has non-valid Field in Table");
				return false;
			}
		}

		alRecord.add(_record);
		return true;
	}
	
	public String toString(){
		String result ="";
		
		if(alField !=null){
			for (int i=0;i<alField.size();i++){
				result += alField.get(i).fName + "\t";
			}
			result += "\n";
		}
		
		if(alRecord !=null){
			for (int i=0;i<alRecord.size();i++){
				result += alRecord.get(i).toString() + "\n";
			}		
		}
		return result;
	}
}

@@ -623,16 +623,387 @@
 ();%0A%09%7D%0A%0A
+//=====================================================================%0A//%09Clone table %0A//=====================================================================%0A%09public Table clone()%7B%0A%09%09Table retTable = new Table(this.tableName);%0A%09%09retTable.alRecord = (ArrayList%3CRecord%3E) alRecord.clone();%0A%09%09retTable.alField = (ArrayList%3CField%3E) alField.clone();%0A%09%09%0A%09%09return retTable;%0A%09%7D%0A
 //======

Add table clone method to make temporary table