private boolean checkForeignConstraints(Hashtable<String, Table> tables, Table currentTable, ArrayList<Value> valueList) throws IOException, ClassNotFoundException{
		Hashtable<String, ForeignReferences> foreignTables = currentTable.getReferenceTable();
		if(foreignTables == null){
			return true;
		}

		for(String attrName : foreignTables.keySet()){
			boolean containsValue = false;
			ForeignReferences foreignRefs = foreignTables.get(attrName);

			String foreignTableName = foreignRefs.getTableName();
			String foreignAttrName = foreignRefs.getAttrName();
			
			Table foreignTable = tables.get(foreignTableName);

			if(foreignTable == null){
				throw new Error("INSERT: Foreign References Constraints: No foreign table " + foreignTableName + " exists");
			}

			int foreignAttrPos = foreignTable.getAttrPos(foreignAttrName);
			
			File tupleFile = new File(foreignTableName + ".db");
			ArrayList< ArrayList<Value> > tupleList;

			if(tupleFile.exists()){
				tupleList = this.getTupleList(tupleFile);
			}else{
				throw new Error("INSERT: Foreign References Constraints: No tuple file of foreign table " + foreignTableName);
			}

			if(tupleList.size() == 0){
				throw new Error("INSERT: Foreign References Constraints: No tuple in the foreign table " + foreignTableName);
			}

			int currentValuePos = currentTable.getAttrPos(attrName);

			Value currentValue = valueList.get(currentValuePos);

			for(ArrayList<Value> values : tupleList){
				
				Value foreignValue = values.get(foreignAttrPos);
				if(currentValue.equals(foreignValue)){
					containsValue = true;
				}
				
			}
			if(!containsValue){
				throw new Error("INSERT: Foreign References Constraints: Inserting Value " + currentValue.toString() + " is not contained in the table " + foreignTableName);
			}

		}
		return true;

	}