package com.amarsoft.app.base.businessobject; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import com.amarsoft.app.base.util.StringHelper; import com.amarsoft.are.jbo.JBOException; public class BusinessObjectSet { private final static String NULL_VALUE_STRING="SYS_NULL_VALUE"; private String[] indexNameArray; private Map>> objectIndex=new HashMap>>(); private List dataList=new ArrayList(); protected BusinessObjectSet(String indexNameString){ String[] indexNameArray=indexNameString.toUpperCase().split(","); this.indexNameArray=indexNameArray; for(String indexname:indexNameArray){ objectIndex.put(indexname, new HashMap>()); } } public void clear(){ objectIndex.clear(); dataList.clear(); } /** * 获取集合中的对象列表 * @param parameterMap * @return * @throws Exception */ public List getList(Map filterParameters) throws Exception{ Collection resultList = null; Set filterKeySet = filterParameters.keySet(); for(String indexName:filterKeySet){ Object indexValue = filterParameters.get(indexName); if(indexValue==null||"".equals(indexValue)) indexValue=NULL_VALUE_STRING; Map> indexData = this.objectIndex.get(indexName.toUpperCase()); if(indexData==null) continue; Map dataIndexMap = indexData.get(indexValue); if(dataIndexMap==null) return null; Collection dataIndexList = dataIndexMap.values(); if(resultList==null){ resultList=dataIndexList; } else{ resultList.containsAll(dataIndexList); } if(resultList.isEmpty()) break; } List l = new ArrayList(); for(int i:resultList){ l.add(dataList.get(i)); } return BusinessObjectHelper.getBusinessObjectsByAttributes(l, filterParameters); } public void remove(BusinessObject o){ } public void remove(List l){ for(BusinessObject o:l){ remove(o); } } /** * 获取集合中的对象列表 * @param parameterString * @param splitChar * @param operateChar * @return * @throws Exception */ public List getList(String parameterString,String splitChar,String operateChar) throws Exception{ Map parameterMap = StringHelper.stringToHashMap(parameterString, splitChar, operateChar); return getList(parameterMap); } /** * 获取集合中的对象列表 * @param parameterString * @param splitChar * @return * @throws ALSException */ public List getList(String parameterString,String splitChar) throws Exception{ Map parameterMap = StringHelper.stringToHashMap(parameterString, splitChar, "="); return getList(parameterMap); } /** * 获取集合中的对象列表 * @param parameterString * @return * @throws ALSException */ public List getList(String parameterString) throws Exception{ Map parameterMap = StringHelper.stringToHashMap(parameterString, ",", "="); return getList(parameterMap); } /** * 获取集合中的对象 * @param parameterString * @param splitChar * @param operateChar * @return * @throws ALSException */ public BusinessObject getBusinessObject(String parameterString,String splitChar,String operateChar) throws Exception{ Map parameterMap = StringHelper.stringToHashMap(parameterString, splitChar, operateChar); return getBusinessObject(parameterMap); } /** * 获取集合中的对象 * @param parameterString * @param splitChar * @return * @throws ALSException */ public BusinessObject getBusinessObject(String parameterString,String splitChar) throws Exception{ Map parameterMap = StringHelper.stringToHashMap(parameterString, splitChar, "="); return getBusinessObject(parameterMap); } /** * 获取集合中的对象 * @param parameterString * @return * @throws ALSException */ public BusinessObject getBusinessObject(String parameterString) throws Exception{ Map parameterMap = StringHelper.stringToHashMap(parameterString, ";", "="); return getBusinessObject(parameterMap); } /** * 获取集合中的对象 * @param parameterMap * @return * @throws ALSException */ public BusinessObject getBusinessObject(Map parameterMap) throws Exception{ List list = this.getList(parameterMap); if(list==null||list.isEmpty()) return null; if(list.size()>1){ String desc ="集合数据中根据参数可以找到多个对象,不适用此方法,请确认传入参数值是否足够!ParameterString = {" + parameterMap.toString() + "}!"; throw new Exception(desc); } return list.get(0); } public void setBusinessObjects(List list) throws Exception{ for(BusinessObject businessObject:list){ this.setBusinessObject(businessObject); } } public void setBusinessObject(BusinessObject businessObject) throws Exception{ String[] objectKey = {businessObject.getBizClassName(),businessObject.getKeyString()}; int objectPosition = this.dataList.indexOf(businessObject); if(objectPosition<0){ this.dataList.add(businessObject); objectPosition=this.dataList.size()-1; } for(int i=0;i> indexData = this.objectIndex.get(indexName); if(indexData==null){ indexData=new HashMap>(); this.objectIndex.put(indexName.toUpperCase(),indexData); } Map data = indexData.get(indexValue); if(data==null){ data=new HashMap(); indexData.put(indexValue, data); } data.put(objectKey, objectPosition); } } /** * 将List转换为Key-Value形式,多个key以逗号隔开 * @param list * @param keyAttributeString * @return * @throws ALSException * @throws JBOException */ public static BusinessObjectSet createBusinessObjectSet(List list,String dimAttributeString) throws Exception{ BusinessObjectSet businessObjectSet = createBusinessObjectSet(dimAttributeString); businessObjectSet.setBusinessObjects(list); return businessObjectSet; } public static BusinessObjectSet createBusinessObjectSet(String dimAttributeString){ BusinessObjectSet businessObjectSet = new BusinessObjectSet(dimAttributeString); return businessObjectSet; } }