/**
*
*/
package com.cplatform.ir.util;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cplatform.ir.engine.module.ShopCategandGradeMoudle;
/**
* @Description:读取 数据到内存中的工具类。
* @Company:
* @author
* @date Nov
* @version
*/
public class ReadPopulationShopUtil {
private static Logger logger=Logger.getLogger(ReadPopulationShopUtil.class);
private static ReadPopulationShopUtil instance = new ReadPopulationShopUtil();
private static Map<String, String> popuFeatureMap3=null;
private static Map<String, Map<String, String>> popuFeatureMap2=null;
private static Map<String, Map<String, Map<String, String>>> popuFeatureMap1=null;
private ReadPopulationShopUtil(){
}
public static ReadPopulationShopUtil getInstance(){
if(instance==null){
instance = new ReadPopulationShopUtil();
}
return instance;
}
/**
* @Description:
*/
public Map<String, Map<String, Map<String, String>>> getPopulationShopMap() {
if (popuFeatureMap1==null) {
popuFeatureMap1=new HashMap<String, Map<String, Map<String, String>>>();
FileInputStream fin=null;
try {
//存储位置
String path = ShopCategandGradeMoudle.class.getClassLoader().getResource("/shopCategandGradeMoudle.txt").getPath();
fin = new FileInputStream(path);
InputStreamReader in = new InputStreamReader(fin,"UTF-8");
BufferedReader bf = new BufferedReader(in);
String line;
while((line=bf.readLine())!=null){
//遍历每一行的数据
//sex 0 grade 30元以下 0.021868971657516
String[] wordArray=line.split("\t");
if (popuFeatureMap1.get(wordArray[0])!=null) {
popuFeatureMap2=popuFeatureMap1.get(wordArray[0]);
if (popuFeatureMap2.get(wordArray[1])!=null) {
popuFeatureMap3=popuFeatureMap2.get(wordArray[1]);
popuFeatureMap3.put(wordArray[2]+"_"+wordArray[3], wordArray[4]);
}else {
popuFeatureMap3=new HashMap<String, String>();
popuFeatureMap3.put(wordArray[2]+"_"+wordArray[3], wordArray[4]);
popuFeatureMap2.put(wordArray[1], popuFeatureMap3);
}
popuFeatureMap2.put(wordArray[1], popuFeatureMap3);
}else {
popuFeatureMap3=new HashMap<String, String>();
popuFeatureMap2=new HashMap<String, Map<String,String>>();
popuFeatureMap3.put(wordArray[2]+"_"+wordArray[3], wordArray[4]);
popuFeatureMap2.put(wordArray[1], popuFeatureMap3);
popuFeatureMap1.put(wordArray[0], popuFeatureMap2);
}
popuFeatureMap1.put(wordArray[0], popuFeatureMap2);
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
return popuFeatureMap1;
}
}