package frame.file.office; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class IOMappingRuntime { private List InsertMappingRuntimeList; private Map InsertfromMap; private Map InserttoMap; private List updateMappingRuntimeList; private Map updatefromMap; private Map updatetoMap; public IOMappingRuntime(List insertMappingRuntime, List updateMappingRuntime) { InsertMappingRuntimeList = new ArrayList(); InsertfromMap = new HashMap(); InserttoMap = new HashMap(); updateMappingRuntimeList = new ArrayList(); updatefromMap = new HashMap(); updatetoMap = new HashMap(); for (IOMappingItemRuntime ioMappingItemRuntime : insertMappingRuntime) { addItem(ioMappingItemRuntime, "insert"); } for (IOMappingItemRuntime ioMappingItemRuntime : updateMappingRuntime) { addItem(ioMappingItemRuntime, "update"); } } private void addItem(IOMappingItemRuntime ioMappingItemRuntime, String type) { // base,add if ("insert".equalsIgnoreCase(type)) { InsertMappingRuntimeList.add(ioMappingItemRuntime); InsertfromMap.put(ioMappingItemRuntime.getFromField(), ioMappingItemRuntime); InserttoMap.put(ioMappingItemRuntime.getToField(), ioMappingItemRuntime); } else if ("update".equalsIgnoreCase(type)) { updateMappingRuntimeList.add(ioMappingItemRuntime); updatefromMap.put(ioMappingItemRuntime.getFromField(), ioMappingItemRuntime); updatetoMap.put(ioMappingItemRuntime.getToField(), ioMappingItemRuntime); } } public boolean contaisFromField(String fromField, String type) { boolean containsField = containsField(fromField, "from", type); return containsField; } public boolean contaisToField(String toField, String type) { boolean containsField = containsField(toField, "to", type); return containsField; } private boolean containsField(String field, String directionType, String dataType) { if (field == null) { return false; } if ("insert".equalsIgnoreCase(dataType)) { if ("from".equalsIgnoreCase(directionType)) { return InsertfromMap.containsKey(field.toLowerCase()); } else if ("to".equalsIgnoreCase(directionType)) { return InserttoMap.containsKey(field.toLowerCase()); } } else if ("update".equalsIgnoreCase(dataType)) { if ("from".equalsIgnoreCase(directionType)) { return updatefromMap.containsKey(field.toLowerCase()); } else if ("to".equalsIgnoreCase(directionType)) { return updatetoMap.containsKey(field.toLowerCase()); } } return false; } public List getUpdateMappingRuntime() { return updateMappingRuntimeList; } public List getInsertMappingRuntime() { return InsertMappingRuntimeList; } }