add method

This commit is contained in:
Looly 2020-08-01 15:06:24 +08:00
parent f6f97668cf
commit 6e4d897b46
2 changed files with 151 additions and 3 deletions

View File

@ -10,6 +10,7 @@
* 【core 】 增加PhoneUtilpr#990@Github
* 【core 】 改进Img目标图片类型未定义使用源图片类型issue#I1PB0B@Gitee
* 【json 】 JSONConfig增加Transient选项issue#I1PLHN@Gitee
* 【core 】 MapUtil增加getXXX的默认值重载issue#I1PTGI@Gitee
### Bug修复

View File

@ -526,7 +526,7 @@ public class MapUtil {
* @since 5.0.4
*/
public static String sortJoin(Map<?, ?> params, String separator, String keyValueSeparator, boolean isIgnoreNull,
String... otherParams) {
String... otherParams) {
return join(sort(params), separator, keyValueSeparator, isIgnoreNull, otherParams);
}
@ -895,6 +895,19 @@ public class MapUtil {
return get(map, key, String.class);
}
/**
* 获取Map指定key的值并转换为字符串
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static String getStr(Map<?, ?> map, Object key, String defaultValue) {
return get(map, key, String.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为Integer
*
@ -907,6 +920,19 @@ public class MapUtil {
return get(map, key, Integer.class);
}
/**
* 获取Map指定key的值并转换为Integer
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static Integer getInt(Map<?, ?> map, Object key, Integer defaultValue) {
return get(map, key, Integer.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为Double
*
@ -919,6 +945,19 @@ public class MapUtil {
return get(map, key, Double.class);
}
/**
* 获取Map指定key的值并转换为Double
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static Double getDouble(Map<?, ?> map, Object key, Double defaultValue) {
return get(map, key, Double.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为Float
*
@ -931,6 +970,19 @@ public class MapUtil {
return get(map, key, Float.class);
}
/**
* 获取Map指定key的值并转换为Float
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static Float getFloat(Map<?, ?> map, Object key, Float defaultValue) {
return get(map, key, Float.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为Short
*
@ -943,6 +995,19 @@ public class MapUtil {
return get(map, key, Short.class);
}
/**
* 获取Map指定key的值并转换为Short
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static Short getShort(Map<?, ?> map, Object key, Short defaultValue) {
return get(map, key, Short.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为Bool
*
@ -955,6 +1020,19 @@ public class MapUtil {
return get(map, key, Boolean.class);
}
/**
* 获取Map指定key的值并转换为Bool
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static Boolean getBool(Map<?, ?> map, Object key, Boolean defaultValue) {
return get(map, key, Boolean.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为Character
*
@ -967,6 +1045,19 @@ public class MapUtil {
return get(map, key, Character.class);
}
/**
* 获取Map指定key的值并转换为Character
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static Character getChar(Map<?, ?> map, Object key, Character defaultValue) {
return get(map, key, Character.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为Long
*
@ -979,6 +1070,19 @@ public class MapUtil {
return get(map, key, Long.class);
}
/**
* 获取Map指定key的值并转换为Long
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static Long getLong(Map<?, ?> map, Object key, Long defaultValue) {
return get(map, key, Long.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为{@link Date}
*
@ -991,6 +1095,19 @@ public class MapUtil {
return get(map, key, Date.class);
}
/**
* 获取Map指定key的值并转换为{@link Date}
*
* @param map Map
* @param key
* @param defaultValue 默认值
* @return
* @since 4.1.2
*/
public static Date getDate(Map<?, ?> map, Object key, Date defaultValue) {
return get(map, key, Date.class, defaultValue);
}
/**
* 获取Map指定key的值并转换为指定类型
*
@ -1002,7 +1119,22 @@ public class MapUtil {
* @since 4.0.6
*/
public static <T> T get(Map<?, ?> map, Object key, Class<T> type) {
return null == map ? null : Convert.convert(type, map.get(key));
return get(map, key, type, null);
}
/**
* 获取Map指定key的值并转换为指定类型
*
* @param <T> 目标值类型
* @param map Map
* @param key
* @param type 值类型
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static <T> T get(Map<?, ?> map, Object key, Class<T> type, T defaultValue) {
return null == map ? null : Convert.convert(type, map.get(key), defaultValue);
}
/**
@ -1016,7 +1148,22 @@ public class MapUtil {
* @since 4.5.12
*/
public static <T> T get(Map<?, ?> map, Object key, TypeReference<T> type) {
return null == map ? null : Convert.convert(type, map.get(key));
return get(map, key, type, null);
}
/**
* 获取Map指定key的值并转换为指定类型
*
* @param <T> 目标值类型
* @param map Map
* @param key
* @param type 值类型
* @param defaultValue 默认值
* @return
* @since 5.3.11
*/
public static <T> T get(Map<?, ?> map, Object key, TypeReference<T> type, T defaultValue) {
return null == map ? null : Convert.convert(type, map.get(key), defaultValue);
}
/**