1. 程式人生 > >hashMap去重

hashMap去重

public List<Object> getWbcPoolValue(DataObject[] workItems,Object[] data){
List<Object> returnList = new ArrayList<Object>();
HashMap<String,DataObject> hashMap = new HashMap<String,DataObject>();
HashMap<String,String> map2 = new HashMap<String,String>();
for(DataObject dataObject : workItems) {
HashMap<String,DataObject> map = new HashMap<String,DataObject>();

DataObject temp = DataObjectUtil.createDataObject("commonj.sdo.DataObject");
String processDefID = dataObject.getString("processDefID");
String activityDefID = dataObject.getString("activityDefID");//activityCode
DataObject bizobj = (DataObject) dataObject.get("bizObject");
String documenttypecode=(String) bizobj.get("documenttypecode");
String businesstypecode=(String) bizobj.get("businesstypecode");

temp.set("processInstName", dataObject.getString("processInstName"));
temp.set("activityInstName", dataObject.getString("activityInstName"));

for(Object obj : data){
DataObject dobj = (DataObject) obj;
String code=dobj.getString("ACTIVITY_CODE");
String businesscode=dobj.getString("BUSINESS_TYPE_CODE");
String documentcode=dobj.getString("DOCUMENT_TYPE_CODE");


if(StringUtil.isNull(documentcode)){
if(StringUtil.equals(activityDefID, code) && StringUtil.equals(businesstypecode, businesscode) ){
temp.set("yValue", dobj.getString("BASIS_VALUE"));
}else{
temp.set("yValue", "");
}
}else{
if(StringUtil.equals(activityDefID, code) && StringUtil.equals(businesstypecode, businesscode) && StringUtil.equals(documenttypecode, documentcode) ){
temp.set("yValue", dobj.getString("BASIS_VALUE"));
}else{
temp.set("yValue", "");
}
}
}
String key = processDefID + activityDefID;//key不能是字串(中文)
DataObject dateobject = hashMap.get(key);
int value=0;
int yval=0;
int svalue=0;
if(dateobject!=null){
value = dateobject.getInt("count");
yval = dateobject.getInt("yValue");
svalue = yval-value-1;
}else{
for(Object obj : data){
DataObject dobj = (DataObject) obj;
String code=dobj.getString("ACTIVITY_CODE");
String businesscode=dobj.getString("BUSINESS_TYPE_CODE");
String documentcode=dobj.getString("DOCUMENT_TYPE_CODE");


if(StringUtil.isNull(documentcode)){
if(StringUtil.equals(activityDefID, code) && StringUtil.equals(businesstypecode, businesscode) ){
yval = Integer.valueOf(dobj.getString("BASIS_VALUE"));
svalue = yval-1;
}
}else{
if(StringUtil.equals(activityDefID, code) && StringUtil.equals(businesstypecode, businesscode) && StringUtil.equals(documenttypecode, documentcode) ){
yval = Integer.valueOf(dobj.getString("BASIS_VALUE"));
svalue = yval-1;
}
}
}
}
//去重處理
if(hashMap.containsKey(key)){
//在Map集合中包含鍵名
temp.set("yValue", yval);
temp.set("sValue", svalue);
temp.set("count", value+1);
map.put(key, temp);
hashMap.putAll(map);
}else{
//在Map集合中不包含鍵名
temp.set("yValue", yval);
temp.set("sValue",svalue);
temp.set("count", 1);
hashMap.put(key, temp);
}
}

Iterator<Map.Entry<String,DataObject>> it = hashMap.entrySet().iterator();
while(it.hasNext()){
Entry<String,DataObject> entry = it.next();
returnList.add(entry.getValue());
}
return returnList;
}