Package org.aoju.bus.core.lang
Class Dictionary
字典对象,扩充了HashMap中的方法
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescription构造Dictionary(boolean caseInsensitive) 构造Dictionary(int initialCapacity) 构造Dictionary(int initialCapacity, boolean caseInsensitive) 构造Dictionary(int initialCapacity, float loadFactor) 构造Dictionary(int initialCapacity, float loadFactor, boolean caseInsensitive) 构造Dictionary(Map<String, Object> map) 构造 -
Method Summary
Modifier and TypeMethodDescriptionclone()compute(String key, BiFunction<? super String, ? super Object, ?> remappingFunction) computeIfAbsent(String key, Function<? super String, ?> mappingFunction) computeIfPresent(String key, BiFunction<? super String, ? super Object, ?> remappingFunction) booleancontainsKey(Object key) static Dictionarycreate()创建Dict过滤Map保留指定键值对,如果键不存在跳过<T> T获得特定类型值<T> T获得特定类型值getBigDecimal(String attr) 获取BigDecimal型属性值getBigInteger(String attr) 获取BigInteger型属性值getBoolean(String attr) 获取boolean型属性值<T> T通过表达式获取JSON中嵌套的对象 .表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值<T> T通过表达式获取JSON中嵌套的对象 .表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值获取byte型属性值byte[]获取char型属性值获取Date类型值获取double型属性值<E extends Enum<E>>
E获得Enum类型的值获取float型属性值获取int型属性值获取long型属性值获取Object属性值getOrDefault(Object key, Object defaultValue) 获取short型属性值获取字符串型属性值getTimestamp(String attr) static Dictionary根据给定的键值对数组创建Dict对象,传入参数必须为key,value,key,value...static Dictionary根据给定的Pair数组创建Dict对象static <T> Dictionaryparse(T bean) 将PO对象转为Dict<T> DictionaryparseBean(T bean) 将值对象转换为Dict 类名会被当作表名,小写第一个字母<T> DictionaryparseBean(T bean, boolean isToUnderlineCase, boolean ignoreNullValue) 将值对象转换为Dict 类名会被当作表名,小写第一个字母voidputIfAbsent(String key, Object value) boolean<T extends Dictionary>
voidremoveEqual(T dict, String... withoutNames) 与给定实体对比并去除相同的部分 此方法用于在更新操作时避免所有字段被更新,跳过不需要更新的字段 version from 2.0.0boolean设置列通过lambda批量设置值 实际使用时,可以使用getXXX的方法引用来完成键值对的赋值:setIgnoreNull(String attr, Object value) 设置列,当键或值为null时忽略<T> TtoBean(T bean) 转换为Bean对象<T> TtoBean(T bean, boolean isToCamelCase) 转换为Bean对象<T> TtoBeanIgnoreCase(Class<T> clazz) 填充Value Object对象,忽略大小写<T> TtoBeanIgnoreCase(T bean) 转换为Bean对象<T> TtoBeanWithCamelCase(T bean) 转换为Bean对象,并使用驼峰法模式转换Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, keySet, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
Dictionary
public Dictionary()构造 -
Dictionary
public Dictionary(boolean caseInsensitive) 构造- Parameters:
caseInsensitive- 是否大小写不敏感
-
Dictionary
public Dictionary(int initialCapacity) 构造- Parameters:
initialCapacity- 初始容量
-
Dictionary
构造- Parameters:
map- Map
-
Dictionary
public Dictionary(int initialCapacity, boolean caseInsensitive) 构造- Parameters:
initialCapacity- 初始容量caseInsensitive- 是否大小写不敏感
-
Dictionary
public Dictionary(int initialCapacity, float loadFactor) 构造- Parameters:
initialCapacity- 初始容量loadFactor- 容量增长因子,0~1,即达到容量的百分之多少时扩容
-
Dictionary
public Dictionary(int initialCapacity, float loadFactor, boolean caseInsensitive) 构造- Parameters:
initialCapacity- 初始容量loadFactor- 容量增长因子,0~1,即达到容量的百分之多少时扩容caseInsensitive- 是否大小写不敏感
-
-
Method Details
-
create
创建Dict- Returns:
- Dict
-
parse
将PO对象转为Dict- Type Parameters:
T- Bean类型- Parameters:
bean- Bean对象- Returns:
- Vo
-
of
根据给定的Pair数组创建Dict对象- Parameters:
pairs- 键值对- Returns:
- Dict
-
of
根据给定的键值对数组创建Dict对象,传入参数必须为key,value,key,value... 奇数参数必须为key,key最后会转换为String类型 奇数参数必须为value,可以为任意类型Dict dict = Dict.of( "RED", "#FF0000", "GREEN", "#00FF00", "BLUE", "#0000FF" );- Parameters:
keysAndValues- 键值对列表,必须奇数参数为key,偶数参数为value- Returns:
- Dict
-
get
-
put
-
clone
-
getObject
Description copied from interface:BasicType获取Object属性值 -
getString
Description copied from interface:BasicType获取字符串型属性值 -
getInt
Description copied from interface:BasicType获取int型属性值 -
getLong
Description copied from interface:BasicType获取long型属性值 -
getFloat
Description copied from interface:BasicType获取float型属性值 -
getShort
Description copied from interface:BasicType获取short型属性值 -
getChar
Description copied from interface:BasicType获取char型属性值 -
getDouble
Description copied from interface:BasicType获取double型属性值 -
getByte
Description copied from interface:BasicType获取byte型属性值 -
getBoolean
Description copied from interface:BasicType获取boolean型属性值- Specified by:
getBooleanin interfaceBasicType<String>- Parameters:
attr- 属性名- Returns:
- 属性值
-
getBigDecimal
Description copied from interface:BasicType获取BigDecimal型属性值- Specified by:
getBigDecimalin interfaceBasicType<String>- Parameters:
attr- 属性名- Returns:
- 属性值
-
getBigInteger
Description copied from interface:BasicType获取BigInteger型属性值- Specified by:
getBigIntegerin interfaceBasicType<String>- Parameters:
attr- 属性名- Returns:
- 属性值
-
getEnum
Description copied from interface:BasicType获得Enum类型的值 -
getDate
Description copied from interface:BasicType获取Date类型值 -
putAll
-
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object> - Overrides:
containsKeyin classHashMap<String,Object>
-
remove
-
remove
-
replace
-
replace
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<String,Object> - Overrides:
getOrDefaultin classLinkedHashMap<String,Object>
-
computeIfPresent
public Object computeIfPresent(String key, BiFunction<? super String, ? super Object, ?> remappingFunction) - Specified by:
computeIfPresentin interfaceMap<String,Object> - Overrides:
computeIfPresentin classHashMap<String,Object>
-
compute
-
merge
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<String,Object> - Overrides:
putIfAbsentin classHashMap<String,Object>
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceMap<String,Object> - Overrides:
computeIfAbsentin classHashMap<String,Object>
-
getBytes
- Parameters:
attr- 字段名- Returns:
- 字段值
-
getTime
- Parameters:
attr- 字段名- Returns:
- 字段值
-
getTimestamp
- Parameters:
attr- 字段名- Returns:
- 字段值
-
getNumber
- Parameters:
attr- 字段名- Returns:
- 字段值
-
getByPath
通过表达式获取JSON中嵌套的对象- .表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值
- []表达式,可以获取集合等对象中对应index的值
表达式栗子:
persion persion.name persons[3] person.friends[5].name
- Type Parameters:
T- 泛型对象- Parameters:
expression- 表达式- Returns:
- 对象
- See Also:
-
getByPath
通过表达式获取JSON中嵌套的对象- .表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值
- []表达式,可以获取集合等对象中对应index的值
表达式栗子:
persion persion.name persons[3] person.friends[5].name
获取表达式对应值后转换为对应类型的值
- Type Parameters:
T- 返回值类型- Parameters:
expression- 表达式resultType- 返回值类型- Returns:
- 对象
- See Also:
-
toBean
public <T> T toBean(T bean) 转换为Bean对象- Type Parameters:
T- Bean类型- Parameters:
bean- Bean- Returns:
- Bean
-
toBean
public <T> T toBean(T bean, boolean isToCamelCase) 转换为Bean对象- Type Parameters:
T- Bean类型- Parameters:
bean- BeanisToCamelCase- 是否转换为驼峰模式- Returns:
- Bean
-
toBeanIgnoreCase
public <T> T toBeanIgnoreCase(T bean) 转换为Bean对象- Type Parameters:
T- Bean类型- Parameters:
bean- Bean- Returns:
- Bean
-
toBeanWithCamelCase
public <T> T toBeanWithCamelCase(T bean) 转换为Bean对象,并使用驼峰法模式转换- Type Parameters:
T- Bean类型- Parameters:
bean- Bean- Returns:
- Bean
-
toBeanIgnoreCase
填充Value Object对象,忽略大小写- Type Parameters:
T- Bean类型- Parameters:
clazz- Value Object(或者POJO)的类- Returns:
- vo
-
parseBean
将值对象转换为Dict 类名会被当作表名,小写第一个字母- Type Parameters:
T- Bean类型- Parameters:
bean- 值对象- Returns:
- 自己
-
parseBean
将值对象转换为Dict 类名会被当作表名,小写第一个字母- Type Parameters:
T- Bean类型- Parameters:
bean- 值对象isToUnderlineCase- 是否转换为下划线模式ignoreNullValue- 是否忽略值为空的字段- Returns:
- 自己
-
removeEqual
与给定实体对比并去除相同的部分 此方法用于在更新操作时避免所有字段被更新,跳过不需要更新的字段 version from 2.0.0- Type Parameters:
T- 字典对象类型- Parameters:
dict- 字典对象withoutNames- 不需要去除的字段名
-
filter
过滤Map保留指定键值对,如果键不存在跳过- Parameters:
keys- 键列表- Returns:
- Dict 结果
-
getBean
获得特定类型值- Type Parameters:
T- 值类型- Parameters:
attr- 字段名- Returns:
- 字段值
-
setIgnoreNull
设置列,当键或值为null时忽略- Parameters:
attr- 属性value- 值- Returns:
- 本身
-
set
设置列- Parameters:
attr- 属性value- 值- Returns:
- 本身
-
get
获得特定类型值- Type Parameters:
T- 值类型- Parameters:
attr- 字段名defaultValue- 默认值- Returns:
- 字段值
-
setFields
通过lambda批量设置值 实际使用时,可以使用getXXX的方法引用来完成键值对的赋值:User user = GenericBuilder.of(User::new).with(User::setUsername, "bus").build(); Dict.create().setFields(user::getNickname, user::getUsername);- Parameters:
fields- lambda,不能为空- Returns:
- this
-