|
@@ -1,72 +0,0 @@
|
|
|
-package com.chelvc.framework.common.model;
|
|
|
-
|
|
|
-import java.io.Serializable;
|
|
|
-import java.util.function.Supplier;
|
|
|
-
|
|
|
-import lombok.NonNull;
|
|
|
-
|
|
|
-/**
|
|
|
- * 对象引用
|
|
|
- *
|
|
|
- * @param <T> 引用对象类型
|
|
|
- * @author Woody
|
|
|
- * @date 2024/1/30
|
|
|
- */
|
|
|
-public final class Reference<T> implements Serializable {
|
|
|
- /**
|
|
|
- * 目标对象实例
|
|
|
- */
|
|
|
- private T target;
|
|
|
-
|
|
|
- public Reference() {
|
|
|
- this(null);
|
|
|
- }
|
|
|
-
|
|
|
- public Reference(T target) {
|
|
|
- this.target = target;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取引用目标
|
|
|
- *
|
|
|
- * @return 目标对象实例
|
|
|
- */
|
|
|
- public T get() {
|
|
|
- return this.target;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取引用目标
|
|
|
- *
|
|
|
- * @param defaultValue 默认值
|
|
|
- * @return 目标对象实例
|
|
|
- */
|
|
|
- public T get(T defaultValue) {
|
|
|
- if (this.target == null) {
|
|
|
- this.target = defaultValue;
|
|
|
- }
|
|
|
- return this.target;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取引用目标
|
|
|
- *
|
|
|
- * @param supplier 默认值函数
|
|
|
- * @return 目标对象实例
|
|
|
- */
|
|
|
- public T get(@NonNull Supplier<T> supplier) {
|
|
|
- if (this.target == null) {
|
|
|
- this.target = supplier.get();
|
|
|
- }
|
|
|
- return this.target;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置引用目标
|
|
|
- *
|
|
|
- * @param target 目标对象实例
|
|
|
- */
|
|
|
- public void set(T target) {
|
|
|
- this.target = target;
|
|
|
- }
|
|
|
-}
|