// Path: src/main/cn/ict/zyq/bestConf/cluster/Interface/ConfigReadin.java
// public interface ConfigReadin {
// 	void initial(String server, String username, String password, String localPath, String remotePath);
// 	void downLoadConfigFile(String fileName);
// 	HashMap modifyConfigFile(HashMap hm, String filepath);
// 	HashMap modifyConfigFile(HashMap hm);
// }
// 
// Path: src/main/cn/ict/zyq/bestConf/cluster/Utils/PropertiesUtil.java
// public class PropertiesUtil {
// 
// 	public PropertiesUtil() {
// 	}
//     public static String GetValueByKey(String filePath, String key) {
//         Properties pps = new Properties();
//         try {
//             InputStream in = new BufferedInputStream (new FileInputStream(filePath));  
//             pps.load(in);
//             String value = pps.getProperty(key);
//             System.out.println(key + " = " + value);
//             return value;
//             
//         }catch (IOException e) {
//             e.printStackTrace();
//             return null;
//         }
//     }
//     
//     
//     public static Properties GetAllProperties(String filePath) throws IOException {
//         Properties pps = new Properties();
//         InputStream in = new BufferedInputStream(new FileInputStream(filePath));
//         pps.load(in);
//         return pps;
//     }
//     
//     public static void WriteProperties (String filePath, String pKey, String pValue) throws IOException {
//         Properties pps = new Properties();
//         
//         File propFile = new File(filePath);
//         if(!propFile.exists())
//         	propFile.createNewFile();
//         
//         InputStream in = new FileInputStream(filePath);
//         pps.load(in); 
//         OutputStream out = new FileOutputStream(filePath);
//         pps.setProperty(pKey, pValue);
//         pps.store(out, "Update " + pKey + " name");
//     }
//     
//     public static void main(String [] args) throws IOException{
//         WriteProperties("data/Test.properties","long", "212");
//     }
// 
// 
// }


import ch.ethz.ssh2.Connection;
import cn.ict.zyq.bestConf.cluster.Interface.ConfigReadin;
import cn.ict.zyq.bestConf.cluster.Utils.PropertiesUtil;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

		HashMap hashmap = null;
		try {
			Properties pps = PropertiesUtil.GetAllProperties(filePath);
			hashmap = new HashMap((Map) pps);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return hashmap;
	}

	public void modify(HashMap toModify, HashMap updatedValues) {
		boolean flag;
		Iterator itrUpdated = updatedValues.entrySet().iterator();
		while(itrUpdated.hasNext()){
			Map.Entry entUpdated = (Map.Entry)itrUpdated.next();
			Object tempObj = toModify.get(entUpdated.getKey().toString());
			if(tempObj!=null){
				if (!entUpdated.getValue().toString().equals("NaN")) {
					if (Double.parseDouble(entUpdated.getValue().toString()) < 1.0 && Double.parseDouble(entUpdated.getValue().toString()) > 0.0) {
						toModify.put(entUpdated.getKey().toString(), entUpdated.getValue().toString());
					} else if(Double.parseDouble(entUpdated.getValue().toString()) == 0.0){
						toModify.put(entUpdated.getKey().toString(), Integer.parseInt("0"));
					} else {
						toModify.put(entUpdated.getKey().toString(), Math.round(Double.parseDouble(entUpdated.getValue().toString())));
					}
				}
			}else

// Path: src/main/cn/ict/zyq/bestConf/cluster/Interface/ConfigReadin.java
// public interface ConfigReadin {
// 	void initial(String server, String username, String password, String localPath, String remotePath);
// 	void downLoadConfigFile(String fileName);
// 	HashMap modifyConfigFile(HashMap hm, String filepath);
// 	HashMap modifyConfigFile(HashMap hm);
// }
// 
// Path: src/main/cn/ict/zyq/bestConf/cluster/Utils/PropertiesUtil.java
// public class PropertiesUtil {
// 
// 	public PropertiesUtil() {
// 	}
//     public static String GetValueByKey(String filePath, String key) {
//         Properties pps = new Properties();
//         try {
//             InputStream in = new BufferedInputStream (new FileInputStream(filePath));  
//             pps.load(in);
//             String value = pps.getProperty(key);
//             System.out.println(key + " = " + value);
//             return value;
//             
//         }catch (IOException e) {
//             e.printStackTrace();
//             return null;
//         }
//     }
//     
//     
//     public static Properties GetAllProperties(String filePath) throws IOException {
//         Properties pps = new Properties();
//         InputStream in = new BufferedInputStream(new FileInputStream(filePath));
//         pps.load(in);
//         return pps;
//     }
//     
//     public static void WriteProperties (String filePath, String pKey, String pValue) throws IOException {
//         Properties pps = new Properties();
//         
//         File propFile = new File(filePath);
//         if(!propFile.exists())
//         	propFile.createNewFile();
//         
//         InputStream in = new FileInputStream(filePath);
//         pps.load(in); 
//         OutputStream out = new FileOutputStream(filePath);
//         pps.setProperty(pKey, pValue);
//         pps.store(out, "Update " + pKey + " name");
//     }
//     
//     public static void main(String [] args) throws IOException{
//         WriteProperties("data/Test.properties","long", "212");
//     }
// 
// 
// }


// Path: src/iotdb/cn/ict/zyq/bestConf/cluster/InterfaceImpl/IoTDBConfigReadin.java
import ch.ethz.ssh2.Connection;
import cn.ict.zyq.bestConf.cluster.Interface.ConfigReadin;
import cn.ict.zyq.bestConf.cluster.Utils.PropertiesUtil;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

		HashMap hashmap = null;
		try {
			Properties pps = PropertiesUtil.GetAllProperties(filePath);
			hashmap = new HashMap((Map) pps);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return hashmap;
	}

	public void modify(HashMap toModify, HashMap updatedValues) {
		boolean flag;
		Iterator itrUpdated = updatedValues.entrySet().iterator();
		while(itrUpdated.hasNext()){
			Map.Entry entUpdated = (Map.Entry)itrUpdated.next();
			Object tempObj = toModify.get(entUpdated.getKey().toString());
			if(tempObj!=null){
				if (!entUpdated.getValue().toString().equals("NaN")) {
					if (Double.parseDouble(entUpdated.getValue().toString()) < 1.0 && Double.parseDouble(entUpdated.getValue().toString()) > 0.0) {
						toModify.put(entUpdated.getKey().toString(), entUpdated.getValue().toString());
					} else if(Double.parseDouble(entUpdated.getValue().toString()) == 0.0){
						toModify.put(entUpdated.getKey().toString(), Integer.parseInt("0"));
					} else {
						toModify.put(entUpdated.getKey().toString(), Math.round(Double.parseDouble(entUpdated.getValue().toString())));
					}
				}
			}else

				System.out.println(entUpdated.getKey().toString() + " Doesn't exit in original list!");
