public class Dict extends LinkedHashMap<String,Object> implements BasicTypeGetter<String>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
Dict()
构造
|
Dict(boolean caseInsensitive)
构造
|
Dict(int initialCapacity)
构造
|
Dict(int initialCapacity,
boolean caseInsensitive)
构造
|
Dict(int initialCapacity,
float loadFactor)
构造
|
Dict(int initialCapacity,
float loadFactor,
boolean caseInsensitive)
构造
|
Dict(Map<String,Object> m)
构造
|
Modifier and Type | Method and Description |
---|---|
Dict |
clone() |
Object |
compute(String key,
BiFunction<? super String,? super Object,?> remappingFunction) |
Object |
computeIfAbsent(String key,
Function<? super String,?> mappingFunction) |
Object |
computeIfPresent(String key,
BiFunction<? super String,? super Object,?> remappingFunction) |
boolean |
containsKey(Object key) |
static Dict |
create()
创建Dict
|
Dict |
filter(String... keys)
过滤Map保留指定键值对,如果键不存在跳过
|
Object |
get(Object key) |
<T> T |
get(String attr,
T defaultValue)
获得特定类型值
|
<T> T |
getBean(String attr)
获得特定类型值
|
BigDecimal |
getBigDecimal(String attr)
获取BigDecimal型属性值
|
BigInteger |
getBigInteger(String attr)
获取BigInteger型属性值
|
Boolean |
getBool(String attr)
获取boolean型属性值
|
<T> T |
getByPath(String expression)
通过表达式获取JSON中嵌套的对象
.表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值 表达式栗子: persion persion.name persons[3] person.friends[5].name |
<T> T |
getByPath(String expression,
Class<T> resultType)
通过表达式获取JSON中嵌套的对象
.表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值 表达式栗子: persion persion.name persons[3] person.friends[5].name 获取表达式对应值后转换为对应类型的值 |
Byte |
getByte(String attr)
获取byte型属性值
|
byte[] |
getBytes(String attr) |
Character |
getChar(String attr)
获取char型属性值
|
Date |
getDate(String attr)
获取Date类型值
|
Double |
getDouble(String attr)
获取double型属性值
|
<E extends Enum<E>> |
getEnum(Class<E> clazz,
String key)
获得Enum类型的值
|
Float |
getFloat(String attr)
获取float型属性值
|
Integer |
getInt(String attr)
获取int型属性值
|
Long |
getLong(String attr)
获取long型属性值
|
Number |
getNumber(String attr) |
Object |
getObj(String key)
获取Object属性值
|
Object |
getOrDefault(Object key,
Object defaultValue) |
Short |
getShort(String attr)
获取short型属性值
|
String |
getStr(String attr)
获取字符串型属性值
|
Time |
getTime(String attr) |
Timestamp |
getTimestamp(String attr) |
Object |
merge(String key,
Object value,
BiFunction<? super Object,? super Object,?> remappingFunction) |
static Dict |
of(Object... keysAndValues)
根据给定的键值对数组创建Dict对象,传入参数必须为key,value,key,value...
|
static Dict |
of(Pair<String,Object>... pairs)
根据给定的Pair数组创建Dict对象
|
static <T> Dict |
parse(T bean)
将PO对象转为Dict
|
<T> Dict |
parseBean(T bean)
将值对象转换为Dict
类名会被当作表名,小写第一个字母 |
<T> Dict |
parseBean(T bean,
boolean isToUnderlineCase,
boolean ignoreNullValue)
将值对象转换为Dict
类名会被当作表名,小写第一个字母 |
Object |
put(String key,
Object value) |
void |
putAll(Map<? extends String,?> m) |
Object |
putIfAbsent(String key,
Object value) |
Object |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
<T extends Dict> |
removeEqual(T dict,
String... withoutNames)
与给定实体对比并去除相同的部分
此方法用于在更新操作时避免所有字段被更新,跳过不需要更新的字段 version from 2.0.0 |
Object |
replace(String key,
Object value) |
boolean |
replace(String key,
Object oldValue,
Object newValue) |
Dict |
set(String attr,
Object value)
设置列
|
Dict |
setFields(Func0<?>... fields)
通过lambda批量设置值
实际使用时,可以使用getXXX的方法引用来完成键值对的赋值: User user = GenericBuilder.of(User::new).with(User::setUsername, "hutool").build(); Dict.create().setFields(user::getNickname, user::getUsername); |
Dict |
setIgnoreNull(String attr,
Object value)
设置列,当键或值为null时忽略
|
<T> T |
toBean(Class<T> clazz)
填充Value Object对象
|
<T> T |
toBean(T bean)
转换为Bean对象
|
<T> T |
toBean(T bean,
boolean isToCamelCase)
转换为Bean对象
|
<T> T |
toBeanIgnoreCase(Class<T> clazz)
填充Value Object对象,忽略大小写
|
<T> T |
toBeanIgnoreCase(T bean)
转换为Bean对象
|
<T> T |
toBeanWithCamelCase(T bean)
转换为Bean对象,并使用驼峰法模式转换
|
clear, containsValue, entrySet, forEach, keySet, removeEldestEntry, replaceAll, values
equals, hashCode, toString
public Dict()
public Dict(boolean caseInsensitive)
caseInsensitive
- 是否大小写不敏感public Dict(int initialCapacity)
initialCapacity
- 初始容量public Dict(int initialCapacity, boolean caseInsensitive)
initialCapacity
- 初始容量caseInsensitive
- 是否大小写不敏感public Dict(int initialCapacity, float loadFactor)
initialCapacity
- 初始容量loadFactor
- 容量增长因子,0~1,即达到容量的百分之多少时扩容public Dict(int initialCapacity, float loadFactor, boolean caseInsensitive)
initialCapacity
- 初始容量loadFactor
- 容量增长因子,0~1,即达到容量的百分之多少时扩容caseInsensitive
- 是否大小写不敏感public static Dict create()
public static <T> Dict parse(T bean)
T
- Bean类型bean
- Bean对象@SafeVarargs public static Dict of(Pair<String,Object>... pairs)
pairs
- 键值对public static Dict of(Object... keysAndValues)
奇数参数必须为key,key最后会转换为String类型。
偶数参数必须为value,可以为任意类型。
Dict dict = Dict.of( "RED", "#FF0000", "GREEN", "#00FF00", "BLUE", "#0000FF" );
keysAndValues
- 键值对列表,必须奇数参数为key,偶数参数为valuepublic <T> T toBean(T bean)
T
- Bean类型bean
- Beanpublic <T> T toBeanIgnoreCase(T bean)
T
- Bean类型bean
- Beanpublic <T> T toBean(T bean, boolean isToCamelCase)
T
- Bean类型bean
- BeanisToCamelCase
- 是否转换为驼峰模式public <T> T toBeanWithCamelCase(T bean)
T
- Bean类型bean
- Beanpublic <T> T toBean(Class<T> clazz)
T
- Bean类型clazz
- Value Object(或者POJO)的类public <T> T toBeanIgnoreCase(Class<T> clazz)
T
- Bean类型clazz
- Value Object(或者POJO)的类public <T> Dict parseBean(T bean)
T
- Bean类型bean
- 值对象public <T> Dict parseBean(T bean, boolean isToUnderlineCase, boolean ignoreNullValue)
T
- Bean类型bean
- 值对象isToUnderlineCase
- 是否转换为下划线模式ignoreNullValue
- 是否忽略值为空的字段public <T extends Dict> void removeEqual(T dict, String... withoutNames)
T
- 字典对象类型dict
- 字典对象withoutNames
- 不需要去除的字段名public Dict filter(String... keys)
keys
- 键列表public Dict setIgnoreNull(String attr, Object value)
attr
- 属性value
- 值public Object getObj(String key)
BasicTypeGetter
getObj
in interface BasicTypeGetter<String>
key
- 属性名public <T> T getBean(String attr)
T
- 值类型attr
- 字段名public <T> T get(String attr, T defaultValue)
T
- 值类型attr
- 字段名defaultValue
- 默认值public String getStr(String attr)
BasicTypeGetter
getStr
in interface BasicTypeGetter<String>
attr
- 字段名public Integer getInt(String attr)
BasicTypeGetter
getInt
in interface BasicTypeGetter<String>
attr
- 字段名public Long getLong(String attr)
BasicTypeGetter
getLong
in interface BasicTypeGetter<String>
attr
- 字段名public Float getFloat(String attr)
BasicTypeGetter
getFloat
in interface BasicTypeGetter<String>
attr
- 字段名public Short getShort(String attr)
BasicTypeGetter
getShort
in interface BasicTypeGetter<String>
attr
- 属性名public Character getChar(String attr)
BasicTypeGetter
getChar
in interface BasicTypeGetter<String>
attr
- 属性名public Double getDouble(String attr)
BasicTypeGetter
getDouble
in interface BasicTypeGetter<String>
attr
- 属性名public Byte getByte(String attr)
BasicTypeGetter
getByte
in interface BasicTypeGetter<String>
attr
- 属性名public Boolean getBool(String attr)
BasicTypeGetter
getBool
in interface BasicTypeGetter<String>
attr
- 字段名public BigDecimal getBigDecimal(String attr)
BasicTypeGetter
getBigDecimal
in interface BasicTypeGetter<String>
attr
- 字段名public BigInteger getBigInteger(String attr)
BasicTypeGetter
getBigInteger
in interface BasicTypeGetter<String>
attr
- 字段名public <E extends Enum<E>> E getEnum(Class<E> clazz, String key)
BasicTypeGetter
getEnum
in interface BasicTypeGetter<String>
E
- 枚举类型clazz
- Enum的Classkey
- KEYpublic byte[] getBytes(String attr)
attr
- 字段名public Date getDate(String attr)
BasicTypeGetter
getDate
in interface BasicTypeGetter<String>
attr
- 字段名public <T> T getByPath(String expression)
表达式栗子:
persion persion.name persons[3] person.friends[5].name
T
- 目标类型expression
- 表达式BeanPath.get(Object)
public <T> T getByPath(String expression, Class<T> resultType)
表达式栗子:
persion persion.name persons[3] person.friends[5].name
获取表达式对应值后转换为对应类型的值
T
- 返回值类型expression
- 表达式resultType
- 返回值类型BeanPath.get(Object)
public boolean containsKey(Object key)
containsKey
in interface Map<String,Object>
containsKey
in class HashMap<String,Object>
public Object getOrDefault(Object key, Object defaultValue)
getOrDefault
in interface Map<String,Object>
getOrDefault
in class LinkedHashMap<String,Object>
public Object computeIfPresent(String key, BiFunction<? super String,? super Object,?> remappingFunction)
computeIfPresent
in interface Map<String,Object>
computeIfPresent
in class HashMap<String,Object>
public Object compute(String key, BiFunction<? super String,? super Object,?> remappingFunction)
public Object merge(String key, Object value, BiFunction<? super Object,? super Object,?> remappingFunction)
public Object putIfAbsent(String key, Object value)
putIfAbsent
in interface Map<String,Object>
putIfAbsent
in class HashMap<String,Object>
public Object computeIfAbsent(String key, Function<? super String,?> mappingFunction)
computeIfAbsent
in interface Map<String,Object>
computeIfAbsent
in class HashMap<String,Object>
public Dict setFields(Func0<?>... fields)
User user = GenericBuilder.of(User::new).with(User::setUsername, "hutool").build(); Dict.create().setFields(user::getNickname, user::getUsername);
fields
- lambda,不能为空Copyright © 2024. All rights reserved.