All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lone.common.util.CommUtils Maven / Gradle / Ivy

The newest version!
package com.lone.common.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.lone.common.exception.BusinessException;

/**   
 * @author 王春勇
 * @version V1.0   
 */
public class CommUtils {
	
	
	/**
	 * 排除相应名称的属性,返回剩余属性键对
	 * String filterName[]={"name1","name2","name3"};
	 * @param filterName
	 * @return
	 */
    @SuppressWarnings("unchecked")
	public static Map attributeMapFilter(Map map,String[] filterName)
    {
      for(int i=0;i mapConvert(Map map) {
    	Map dataMap= new HashMap(0);
        if(map!=null){
	        Iterator it=map.entrySet().iterator();
	        while(it.hasNext()){
		        Map.Entry entry=(Map.Entry)it.next();
		        Object ok=entry.getKey();
		        Object ov=entry.getValue()==null?"":entry.getValue();
		        String key=ok.toString();
		        String keyval="";
		        String[] value=new String[1];
                if(ov instanceof String[]){
                    value=(String[])ov;
                }else{
                    value[0]=ov.toString();
                }
                keyval+=value[0];
                for(int k=1;k mapConvertO(Map map) {
    	Map dataMap= new HashMap(0);
        if(map!=null){
	        Iterator it=map.entrySet().iterator();
	        while(it.hasNext()){
		        Map.Entry entry=(Map.Entry)it.next();
		        Object ok=entry.getKey();
		        Object ov=entry.getValue()==null?"":entry.getValue();
		        String key=ok.toString();
		        String keyval="";
		        Object[] value=new Object[1];
                if(ov instanceof String[]){
                    value=(String[])ov;
                }else{
                    value[0]=ov;
                }
                keyval+=value[0];
                for(int k=1;k> mapKeytoLowerCase(List> lstMap) {
		List> result = new ArrayList<>();
		if (lstMap != null) {
			for (int i = 0; i < lstMap.size(); i++) {
				Map map = lstMap.get(i);
				map = mapKeytoLowerCase(map);
				result.add(map);
			}
		}
		return result;
    }
	
	public static Map mapKeytoLowerCase(Map map) {
		Map dataMap= new HashMap(0);
        if(map!=null){
	        Iterator it=map.entrySet().iterator();
	        while(it.hasNext()){
		        Map.Entry entry=(Map.Entry)it.next();
		        Object ok=entry.getKey();
		        Object ov=entry.getValue()==null?"":entry.getValue();
		        String key=ok.toString();

		        dataMap.put(key.toLowerCase(), ov);
		        dataMap.put(key, ov);
	        }
        }
        return dataMap;
    }
    
    @SuppressWarnings("unchecked")
	public static Map>> mapConvertMore(Map map,String tableName) {
    	Map>> fanalMap = new HashMap>>();
    	Map> dataMap= new HashMap>(0);
    	Map mapField = null;
        if(map!=null){
	        Iterator it=map.entrySet().iterator();
	        while(it.hasNext()){
		        Map.Entry entry=(Map.Entry)it.next();
		        Object ok=entry.getKey();
		        Object ov=entry.getValue()==null?"":entry.getValue();
		        String key=ok.toString();
		        String keyval="";
		        String[] value=new String[1];
                if(ov instanceof String[]){
                    value=(String[])ov;
                }else{
                    value[0]=ov.toString();
                }
                keyval+=value[0];
                for(int k=1;k(0);
                if(keyArr.length==1){
                	if(dataMap.get(tableName)!=null){
                		mapField = dataMap.get(tableName);
                	}
                	mapField.put(keyArr[0], keyval);
                	dataMap.put(tableName, mapField);
                }else if(keyArr.length==2){
                	if(dataMap.get(keyArr[0])!=null){
                		mapField = dataMap.get(keyArr[0]);
                	}
                	mapField.put(keyArr[1], keyval);
                	dataMap.put(keyArr[0], mapField);
                }
	        }
        }
        List> listField = null;
        if(dataMap.size()>0){
        	Iterator it=dataMap.entrySet().iterator();
        	while(it.hasNext()){
        		Map.Entry entry=(Map.Entry)it.next();
        		String ok=(String)entry.getKey();
        		Map ov=(Map)entry.getValue();
        		listField = new ArrayList>();
        		if(ok.indexOf("[")!=-1){
        			ok = ok.substring(0,ok.indexOf("["));
        		}
        		if(fanalMap.get(ok)!=null){
    				listField = fanalMap.get(ok);
    			}
    			listField.add(ov);
    			fanalMap.put(ok, listField);
        		
        	}
        }
        return fanalMap;
    }
    

    public static Map convertFKMap(Map fieldMap,Map mainMap,List> fkFieldList) throws BusinessException {
    	if(fkFieldList!=null){
    		for(Map fkField:fkFieldList){
    			if(mainMap.get((String)fkField.get("main_field"))!=null){
    				fieldMap.put((String)fkField.get("field_name"), mainMap.get((String)fkField.get("main_field")));
    			}else{
    				throw new BusinessException("表单中没有外键:"+(String)fkField.get("main_field"));
    			}
    		}
    	}
        return fieldMap;
    }
    
//    public static void main(String[] args) {
//    	String str = "jform_tbd[0].name";
//    	String strs [] = str.split("\\.");
//	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy