/**
*
*/
package main;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.dom4j.Document;
import org.dom4j.Element;
import common.Config;
import cputils.DataItem;
import cputils.XmlUtils;
/**
* @author zhengweiwei
* @date 2014年8月20日
*/
public class StatSSCOpened {
public static void main(String[] args) {
everyPos();
}
public static List<String> everyPos() {
List<String> resList = new ArrayList<String>();
XmlUtils utils = new XmlUtils();
Map<Integer, Map<Integer, Integer>> posMap = new HashMap<Integer, Map<Integer, Integer>>();
Map<Integer, Integer> dataMap1 = new HashMap<Integer, Integer>();
Map<Integer, Integer> dataMap2 = new HashMap<Integer, Integer>();
Map<Integer, Integer> dataMap3 = new HashMap<Integer, Integer>();
Map<Integer, Integer> dataMap4 = new HashMap<Integer, Integer>();
Map<Integer, Integer> dataMap5 = new HashMap<Integer, Integer>();
Map<Integer, Integer> first2 = new HashMap<Integer, Integer>();
Map<Integer, Integer> first3 = new HashMap<Integer, Integer>();
Map<Integer, Integer> first4 = new HashMap<Integer, Integer>();
Map<Integer, Integer> first5 = new HashMap<Integer, Integer>();
for (int i = 0; i <= 9; i++) {
first2.put(i, 0);
first3.put(i, 0);
first4.put(i, 0);
first5.put(i, 0);
dataMap1.put(i, 0);
dataMap2.put(i, 0);
dataMap3.put(i, 0);
dataMap4.put(i, 0);
dataMap5.put(i, 0);
}
List<DataItem> list = new ArrayList<DataItem>();
try {
Document root = utils.getDocumentComm(Config.DATA_FILE_PATH + "ssc.xml");
Element rootEl = root.getRootElement();
Iterator<Element> it = rootEl.elementIterator();
Element el;
DataItem item1;
while (it.hasNext()) {
el = it.next();
item1 = new DataItem(el.attributeValue("ID"),
el.attributeValue("opencode"), el.attributeValue("type"));
list.add(item1);
}
System.out.println("all size:" + list.size());
for (DataItem item : list) {
String[] codeArr = item.getOpencode().split(" ");
Integer[] intCodeArr = new Integer[codeArr.length];
for (int i = 0; i < codeArr.length; i++) {
intCodeArr[i] = Integer.parseInt(codeArr[i]);
}
addMapData(dataMap1, intCodeArr[0]);
addMapData(dataMap2, intCodeArr[1]);
addMapData(dataMap3, intCodeArr[2]);
addMapData(dataMap4, intCodeArr[3]);
addMapData(dataMap5, intCodeArr[4]);
addMapData(first2, intCodeArr[0]);
addMapData(first2, intCodeArr[1]);
addMapData(first3, intCodeArr[0]);
addMapData(first3, intCodeArr[1]);
addMapData(first3, intCodeArr[2]);
addMapData(first4, intCodeArr[0]);
addMapData(first4, intCodeArr[1]);
addMapData(first4, intCodeArr[2]);
addMapData(first4, intCodeArr[3]);
addMapData(first5, intCodeArr[0]);
addMapData(first5, intCodeArr[1]);
addMapData(first5, intCodeArr[2]);
addMapData(first5, intCodeArr[3]);
addMapData(first5, intCodeArr[4]);
}
} catch (Exception e) {
e.printStackTrace();
}
posMap.put(1, XmlUtils.makeSortedMap(dataMap1));
posMap.put(2, XmlUtils.makeSortedMap(dataMap2));
posMap.put(3, XmlUtils.makeSortedMap(dataMap3));
posMap.put(4, XmlUtils.makeSortedMap(dataMap4));
posMap.put(5, XmlUtils.makeSortedMap(dataMap5));
System.out.println("/*****************every position**********************/");
for (Entry<Integer, Map<Integer, Integer>> tem : posMap.entrySet()) {
System.out.println(tem.getKey() + ": " + tem.getValue());
}
// First two
System.out
.println("/*****************first2 3 4 5 position**********************/");
System.out.println("first2:" + XmlUtils.makeSortedMap(first2));
System.out.println("first3:" + XmlUtils.makeSortedMap(first3));
System.out.println("first4:" + XmlUtils.makeSortedMap(first4));
System.out
.println("/*****************all position**********************/");
System.out.println("all:" + XmlUtils.makeSortedMap(first5));
return resList;
}
private static void addMapData(Map<Integer, Integer> dataMap, Integer key) {
dataMap.put(key, addCount(dataMap, key));
}
private static int addCount(Map<Integer, Integer> dataMap, Integer key) {
return (dataMap.get(key) != null ? dataMap.get(key) : 0) + 1;
}
}