remove class

This commit is contained in:
Looly 2024-07-12 18:29:12 +08:00
parent 3e20e48f54
commit 3d70db0041

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* https://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.core.bean;
import org.dromara.hutool.core.map.reference.WeakConcurrentMap;
import java.util.function.Supplier;
/**
* Bean属性缓存<br>
* 缓存用于防止多次反射造成的性能问题
*
* @author Looly
*/
public enum BeanDescCache {
/**
* 单例
*/
INSTANCE;
private final WeakConcurrentMap<Class<?>, BeanDesc> bdCache = new WeakConcurrentMap<>();
/**
* 获得属性名和{@link BeanDesc}Map映射
*
* @param beanClass Bean的类
* @param supplier 对象不存在时创建对象的函数
* @param <T> BeanDesc子类
* @return 属性名和 {@link BeanDesc}映射
* @since 5.4.2
*/
@SuppressWarnings("unchecked")
public <T extends BeanDesc> T getBeanDesc(final Class<?> beanClass, final Supplier<T> supplier) {
return (T) bdCache.computeIfAbsent(beanClass, (key) -> supplier.get());
}
/**
* 清空全局的Bean属性缓存
*
* @since 5.7.21
*/
public void clear() {
this.bdCache.clear();
}
}