mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
增加ifInitialized()方法
This commit is contained in:
parent
41719e394c
commit
d848e8cbbd
@ -2,6 +2,7 @@ package cn.hutool.core.lang.loader;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@ -23,6 +24,7 @@ public final class LazyFunLoader<T> extends LazyLoader<T> {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param supplier 用于生成对象的函数
|
||||
*/
|
||||
public LazyFunLoader(Supplier<T> supplier) {
|
||||
@ -47,4 +49,17 @@ public final class LazyFunLoader<T> extends LazyLoader<T> {
|
||||
public boolean isInitialize() {
|
||||
return this.supplier == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果已经初始化,就执行传入函数
|
||||
*
|
||||
* @param consumer 待执行函数
|
||||
*/
|
||||
public void ifInitialized(Consumer<T> consumer) {
|
||||
|
||||
// 已经初始化
|
||||
if (this.isInitialize()) {
|
||||
consumer.accept(this.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user