public class MapUtils
extends cn.hutool.core.map.MapUtil
Modifier and Type | Field and Description |
---|---|
static com.alibaba.fastjson.JSONObject |
FINAL_EMPTY_JSON
不可变的空Json常量
|
Constructor and Description |
---|
MapUtils() |
Modifier and Type | Method and Description |
---|---|
static BigDecimal |
getBigDecimal(Map<?,?> paramMap,
Object key)
以安全的方式从Map中获取BigDecimal
|
static Boolean |
getBoolean(Map<?,?> paramMap,
Object key)
以安全的方式从Map中获取Boolean
|
static Double |
getDouble(Map<?,?> paramMap,
Object key)
以安全的方式从Map中获取Double
|
static Integer |
getInteger(Map<?,?> paramMap,
Object key)
以安全的方式从Map中获取Integer
|
static com.alibaba.fastjson.JSONArray |
getJSONArray(Map<?,?> paramMap,
String key)
以安全的方式从Map中获取JSONArray
|
static com.alibaba.fastjson.JSONObject |
getJSONObject(Map<?,?> paramMap,
String key)
以安全的方式从Map中获取JSONObject
|
static com.alibaba.fastjson.JSONObject |
getJSONObject(Map<String,Object> paramMap,
String... keys)
以安全的方式从Map中获取一组数据,组合成一个新的JSONObject
|
static Long |
getLong(Map<?,?> paramMap,
Object key)
以安全的方式从Map中获取Long
|
static Number |
getNumber(Map<?,?> paramMap,
Object key)
以安全的方式从Map中获取Number
|
static <T> T |
getObject(Map<?,?> paramMap,
Object key,
Class<T> clazz)
以安全的方式从Map中获取对象
|
static String |
getString(Map<?,?> paramMap,
Object key)
以安全的方式从Map中获取字符串
|
static boolean |
isContainsOneOfKey(Map<String,Object> paramMap,
String[] keys)
判断Map数据结构是否包含 keys 之一
|
static boolean |
isEmptys(Map<String,Object>[] paramMaps)
判断Map数组是否为空
|
static boolean |
isKeys(Map<String,Object> paramMap,
String[] mustContainKeys,
String... canContainKeys)
判断Map数据结构key的一致性
|
static boolean |
isKeysEqual(Map<String,Object> paramMap,
String[] keys)
判断Map数据结构所有的key是否与数组完全匹配
|
static boolean |
isMapsKeys(Map<String,Object>[] paramMaps,
String[] keys)
判断Map数组第一个元素,是否包含所有的key
|
static boolean |
isStringValueEmpty(Map<String,Object> paramMap)
判断Map是否为空,或者Map中String类型的value值是否为空
|
static List<String> |
keyList(Map<String,Object> paramMap)
获取所有的key
|
static <T> Map<String,List<T>> |
listPOJOExtractKeyToList(List<T> objectList,
String key)
将指定值提取出来作为map key,map的值为相同key值的list
|
static <T> Map<String,T> |
listPOJOExtractKeyToPOJO(List<T> objectList,
String key)
将list对象中数据提取为单个map键值对
|
static void |
remove(Map<String,Object> paramMap,
String[] keys)
批量移除
|
static void |
removeBlankStr(Map<String,Object> paramMap)
移除空白字符串
|
static void |
removeEmpty(Map<String,Object> paramMap)
移除空对象
|
static void |
replaceKey(Map<String,Object> paramMap,
String key,
String replaceKey)
替换key
|
static com.alibaba.fastjson.JSONObject |
toCamelCase(Object param)
属性命名策略转换-驼峰命名法
|
static com.alibaba.fastjson.JSONObject |
toPropertyNamingStrategy(Object param,
com.alibaba.fastjson.PropertyNamingStrategy propertyNamingStrategy)
属性命名策略转换
|
static com.alibaba.fastjson.JSONObject |
toSnakeCase(Object param)
属性命名策略转换-下划线命名法
|
static com.alibaba.fastjson.JSONObject |
toUnderlineCase(Object param)
属性命名策略转换-下划线命名法
|
static void |
trimStringValues(Map<String,Object> paramMap)
删除Value字符串前后空格
|
builder, builder, builder, clear, createMap, createProxy, defaultIfEmpty, empty, empty, emptyIfNull, filter, filter, filter, get, get, get, get, getAny, getBool, getBool, getChar, getChar, getDate, getDate, getDouble, getFloat, getFloat, getInt, getInt, getLong, getQuietly, getQuietly, getShort, getShort, getStr, getStr, inverse, isEmpty, isNotEmpty, join, join, joinIgnoreNull, newConcurrentHashMap, newConcurrentHashMap, newConcurrentHashMap, newHashMap, newHashMap, newHashMap, newHashMap, newIdentityMap, newTreeMap, newTreeMap, of, of, of, of, removeAny, removeNullValue, renameKey, reverse, sort, sort, sortByValue, sortJoin, toCamelCaseMap, toListMap, toMapList, toObjectArray, unmodifiable, wrap
public static final com.alibaba.fastjson.JSONObject FINAL_EMPTY_JSON
public static boolean isKeys(Map<String,Object> paramMap, String[] mustContainKeys, String... canContainKeys)
paramMap
- 参数mustContainKeys
- 必须包含的key(必传)canContainKeys
- 可包含的key(非必传)public static boolean isKeysEqual(Map<String,Object> paramMap, String[] keys)
paramMap
- 需要确认的Mapkeys
- 条件public static boolean isContainsOneOfKey(Map<String,Object> paramMap, String[] keys)
paramMap
- 需要确认的Mapkeys
- 条件public static boolean isMapsKeys(Map<String,Object>[] paramMaps, String[] keys)
弱比较,只判断数组中第一个元素是否包含所有的key
paramMaps
- 需要确认的Map数组keys
- 条件数组public static boolean isEmptys(Map<String,Object>[] paramMaps)
弱判断,只确定数组中第一个元素是否为空
paramMaps
- 要判断的Map[]数组public static boolean isStringValueEmpty(Map<String,Object> paramMap)
paramMap
- 要判断的Mappublic static void trimStringValues(Map<String,Object> paramMap)
paramMap
- 需要处理的mappublic static void remove(Map<String,Object> paramMap, String[] keys)
paramMap
- 要操作的Mapkeys
- 被移除的key数组public static void removeEmpty(Map<String,Object> paramMap)
paramMap
- 要操作的Mappublic static void removeBlankStr(Map<String,Object> paramMap)
空白的定义如下:
1、为null
2、为不可见字符(如空格)
3、""
paramMap
- 要操作的Mappublic static void replaceKey(Map<String,Object> paramMap, String key, String replaceKey)
paramMap
- 要操作的Mapkey
- 被替换的keyreplaceKey
- 替换的keypublic static List<String> keyList(Map<String,Object> paramMap)
paramMap
- 需要获取keys的mappublic static com.alibaba.fastjson.JSONObject getJSONObject(Map<String,Object> paramMap, String... keys)
paramMap
- 需要从中获取数据的mapkeys
- 获取的keyspublic static <T> T getObject(Map<?,?> paramMap, Object key, Class<T> clazz)
T
- 泛型paramMap
- 参数mapkey
- keyclazz
- 泛型类型public static Number getNumber(Map<?,?> paramMap, Object key)
paramMap
- 参数mapkey
- keypublic static String getString(Map<?,?> paramMap, Object key)
paramMap
- 参数mapkey
- keypublic static Boolean getBoolean(Map<?,?> paramMap, Object key)
paramMap
- 参数mapkey
- keypublic static Integer getInteger(Map<?,?> paramMap, Object key)
paramMap
- 参数mapkey
- keypublic static Long getLong(Map<?,?> paramMap, Object key)
paramMap
- 参数mapkey
- keypublic static Double getDouble(Map<?,?> paramMap, Object key)
paramMap
- 参数mapkey
- keypublic static BigDecimal getBigDecimal(Map<?,?> paramMap, Object key)
paramMap
- 参数mapkey
- keypublic static com.alibaba.fastjson.JSONObject getJSONObject(Map<?,?> paramMap, String key)
paramMap
- 参数mapkey
- keypublic static com.alibaba.fastjson.JSONArray getJSONArray(Map<?,?> paramMap, String key)
paramMap
- 参数mapkey
- keypublic static com.alibaba.fastjson.JSONObject toCamelCase(Object param)
param
- Json参数 或 POJO对象public static com.alibaba.fastjson.JSONObject toUnderlineCase(Object param)
param
- Json参数 或 POJO对象public static com.alibaba.fastjson.JSONObject toSnakeCase(Object param)
param
- Json参数 或 POJO对象public static com.alibaba.fastjson.JSONObject toPropertyNamingStrategy(Object param, com.alibaba.fastjson.PropertyNamingStrategy propertyNamingStrategy)
param
- Json参数 或 POJO对象propertyNamingStrategy
- 属性命名策略public static <T> Map<String,List<T>> listPOJOExtractKeyToList(List<T> objectList, String key)
例:一个用户集合中的对象有key、name、sex
数据1:key:1,name:张三,sex:man
数据2:key:2,name:李四,sex:woman
数据3:key:3,name:王五,sex:man
方法调用:ListPOJOExtractKeyToList(list,"sex");
处理后返回结果为一个map,值为一个list,json表示为:
{"man":[{"key":"1","name":"张三","sex":"man"},{"key":"3","name":"王五","sex":"man"}],
"woman":[{"key":"2","name":"李四","sex":"woman"}]}
objectList
- 对象listpublic static <T> Map<String,T> listPOJOExtractKeyToPOJO(List<T> objectList, String key)
将list对象中数据提取为单个map键值对
注:如果有相同的key时,后面的值会覆盖第一次出现的key对应的值
例:一个用户集合中的对象有key、name、sex
数据1:key:1,name:张三,sex:man
数据2:key:2,name:李四,sex:woman
数据3:key:3,name:王五,sex:man
方法调用:ListPOJOExtractKeyToList(list,"key");
处理后返回结果为一个map,值为一个对象,json表示为:
{"1":{"key":"1","name":"张三","sex":"man"},"2":{"key":"2","name":"李四","sex":"woman"},"3":{"key":"3","name":"王五","sex":"man"}}
T
- 泛型对象objectList
- list数据key
- 需要提取的keyCopyright © 2022 Pivotal Software, Inc.. All rights reserved.