refactor!: 将 Ref 类从 base 包移动到 util 包
This commit is contained in:
@@ -15,56 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* <h2>基础组件</h2>
|
||||
*
|
||||
* <h3>1. Ref</h3>
|
||||
* <p>
|
||||
* {@link Ref} 包装了一个值,表示对该值的应用。
|
||||
*
|
||||
* <p>灵感来自于 C# 的 {@code ref} 参数修饰符。C# 允许通过以下方式,将值返回给调用端:</p>
|
||||
* <pre>
|
||||
* void Method(ref int refArgument)
|
||||
* {
|
||||
* refArgument = refArgument + 44;
|
||||
* }
|
||||
*
|
||||
* int number = 1;
|
||||
* Method(ref number);
|
||||
* Console.WriteLine(number); // Output: 45
|
||||
* </pre>
|
||||
* {@link Ref} 使 Java 可以达到类似的效果,如:
|
||||
* <pre>
|
||||
* void method(Ref<Integer> refArgument) {
|
||||
* refArgument.transformValue(i -> i + 44);
|
||||
* }
|
||||
*
|
||||
* Ref<Integer> number = Ref.of(1);
|
||||
* method(number);
|
||||
* System.out.println(number.getValue()); // Output: 45
|
||||
* </pre>
|
||||
* <p>
|
||||
* 当一个方法需要产生多个结果时,无法有多个返回值,可以使用 {@link Ref} 作为参数传入,方法内部修改 {@link Ref} 的值。
|
||||
* 调用方在调用方法之后,使用 {@code getValue()} 获取结果。
|
||||
*
|
||||
* <pre>
|
||||
* String method(Ref<Integer> intRefArgument, Ref<String> strRefArgument) {
|
||||
* intRefArgument.transformValue(i -> i + 44);
|
||||
* strRefArgument.setValue("Hello " + strRefArgument.getValue());
|
||||
* return "Return string";
|
||||
* }
|
||||
*
|
||||
* Ref<Integer> number = Ref.of(1);
|
||||
* Ref<String> str = Ref.of("Java");
|
||||
* String result = method(number, str);
|
||||
* System.out.println(number.getValue()); // Output: 45
|
||||
* System.out.println(str.getValue()); // Output: Hello Java
|
||||
* System.out.println(result); // Output: Return string
|
||||
* </pre>
|
||||
*
|
||||
* <h3>2. IWithCode</h3>
|
||||
* <p>
|
||||
* 类似于枚举这样的类型,通常需要设置固定的码值表示对应的含义。
|
||||
* 可实现 {@link IWithCode}、{@link IWithIntCode}、{@link IWithLongCode},便于在需要的地方对这些接口的实现进行处理。
|
||||
* 基础内容
|
||||
*
|
||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||
*/
|
||||
@@ -73,4 +24,5 @@
|
||||
package xyz.zhouxy.plusone.commons.base;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import javax.annotation.CheckReturnValue;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package xyz.zhouxy.plusone.commons.base;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package xyz.zhouxy.plusone.commons.base;
|
||||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
Reference in New Issue
Block a user