package com.qianwen.core.tool.utils;
|
|
import java.io.Serializable;
|
import java.util.function.Supplier;
|
import org.springframework.lang.Nullable;
|
|
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/utils/Lazy.class */
|
public class Lazy<T> implements Supplier<T>, Serializable {
|
@Nullable
|
private volatile transient Supplier<? extends T> supplier;
|
@Nullable
|
private T value;
|
|
public static <T> Lazy<T> of(final Supplier<T> supplier) {
|
return new Lazy<>(supplier);
|
}
|
|
/* JADX WARN: Multi-variable type inference failed */
|
private Lazy(final Supplier<T> supplier) {
|
this.supplier = supplier;
|
}
|
|
@Override // java.util.function.Supplier
|
@Nullable
|
public T get() {
|
return this.supplier == null ? this.value : computeValue();
|
}
|
|
@Nullable
|
private synchronized T computeValue() {
|
Supplier<? extends T> s = this.supplier;
|
if (s != null) {
|
this.value = s.get();
|
this.supplier = null;
|
}
|
return this.value;
|
}
|
}
|