package com.winsun.utils;

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

public class MapUtil {
	
	/**
	 * 
	 * @param list 集合
	 * @param key 作为key的字段名
	 * @param keyValue 作为key的value值字段名
	 * @return
	 */
	public static Map<String,Object> listToMap(List<Map<String, Object>> list,String key,String keyValue){
		Map<String,Object> map = new HashMap<String, Object>();
		for(Map<String, Object> theMap : list) {
			if(null != theMap.get(key) && null != theMap.get(keyValue)) {
				map.put(theMap.get(key).toString(), theMap.get(keyValue));
			}
		}
		
		return map;
	}
	
	/**
	 * 
	 * @param list 集合
	 * @param key 作为key的字段名
	 * @return
	 */
	public static Map<String,Object> listToMap(List<Map<String, Object>> list,String key){
		Map<String,Object> map = new HashMap<String, Object>();
		for(Map<String, Object> theMap : list) {
			if(null != theMap.get(key)) {
				map.put(theMap.get(key).toString(), theMap);
			}
		}
		
		return map;
	}
}
