com.dahuatech.hutool.core.bean.BeanInfoCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-sdk-common Show documentation
Show all versions of java-sdk-common Show documentation
Dahua ICC Open API SDK for Java
package com.dahuatech.hutool.core.bean;
import com.dahuatech.hutool.core.lang.SimpleCache;
import java.beans.PropertyDescriptor;
import java.util.Map;
/**
* Bean属性缓存
* 缓存用于防止多次反射造成的性能问题
*
* @author Looly
*/
public enum BeanInfoCache {
INSTANCE;
private SimpleCache, Map> pdCache = new SimpleCache<>();
private SimpleCache, Map> ignoreCasePdCache =
new SimpleCache<>();
/**
* 获得属性名和{@link PropertyDescriptor}Map映射
*
* @param beanClass Bean的类
* @param ignoreCase 是否忽略大小写
* @return 属性名和{@link PropertyDescriptor}Map映射
*/
public Map getPropertyDescriptorMap(
Class> beanClass, boolean ignoreCase) {
return (ignoreCase ? ignoreCasePdCache : pdCache).get(beanClass);
}
/**
* 加入缓存
*
* @param beanClass Bean的类
* @param fieldNamePropertyDescriptorMap 属性名和{@link PropertyDescriptor}Map映射
* @param ignoreCase 是否忽略大小写
*/
public void putPropertyDescriptorMap(
Class> beanClass,
Map fieldNamePropertyDescriptorMap,
boolean ignoreCase) {
(ignoreCase ? ignoreCasePdCache : pdCache).put(beanClass, fieldNamePropertyDescriptorMap);
}
}