forked from plusone/plusone-commons
Compare commits
8 Commits
e2e5f50162
...
dev
Author | SHA1 | Date | |
---|---|---|---|
ce9f3edfbc | |||
0f90756f44 | |||
34a49d30ca | |||
f4c3793aab | |||
6556a53163 | |||
56079c29d8 | |||
f111b02c21 | |||
56fd5f0a6a |
12
README.md
12
README.md
@@ -68,16 +68,16 @@ System.out.println(result); // Output: Return string
|
|||||||
`RegexConsts` 包含常见正则表达式;`PatternConsts` 包含对应的 `Pattern` 对象
|
`RegexConsts` 包含常见正则表达式;`PatternConsts` 包含对应的 `Pattern` 对象
|
||||||
|
|
||||||
## 五、exception - 异常
|
## 五、exception - 异常
|
||||||
### 1. MultiTypesException - 多类型异常
|
### 1. IMultiTypesException - 多类型异常
|
||||||
异常在不同场景下被抛出,可以用不同的枚举值,表示不同的场景类型。
|
异常在不同场景下被抛出,可以用不同的枚举值,表示不同的场景类型。
|
||||||
|
|
||||||
异常实现 `MultiTypesException` 的 `MultiTypesException#getType` 方法,返回对应的场景类型。
|
异常实现 `IMultiTypesException` 的 `IMultiTypesException#getType` 方法,返回对应的场景类型。
|
||||||
|
|
||||||
表示场景类型的枚举实现 `MultiTypesException.ExceptionType`,其中的工厂方法用于创建对应类型的异常。
|
表示场景类型的枚举实现 `IMultiTypesException.IExceptionType`,其中的工厂方法用于创建对应类型的异常。
|
||||||
```java
|
```java
|
||||||
public final class LoginException
|
public final class LoginException
|
||||||
extends RuntimeException
|
extends RuntimeException
|
||||||
implements MultiTypesException<LoginException, LoginException.Type> {
|
implements IMultiTypesException<LoginException, LoginException.Type, String> {
|
||||||
private static final long serialVersionUID = 881293090625085616L;
|
private static final long serialVersionUID = 881293090625085616L;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
private LoginException(@Nonnull Type type, @Nonnull String message) {
|
private LoginException(@Nonnull Type type, @Nonnull String message) {
|
||||||
@@ -104,7 +104,7 @@ public final class LoginException
|
|||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
public enum Type implements ExceptionType {
|
public enum Type implements IExceptionType<LoginException, String> {
|
||||||
DEFAULT("00", "当前会话未登录"),
|
DEFAULT("00", "当前会话未登录"),
|
||||||
NOT_TOKEN("10", "未提供token"),
|
NOT_TOKEN("10", "未提供token"),
|
||||||
INVALID_TOKEN("20", "token无效"),
|
INVALID_TOKEN("20", "token无效"),
|
||||||
@@ -211,7 +211,7 @@ throw LoginException.Type.TOKEN_TIMEOUT.create();
|
|||||||
#### 2. UnifiedResponse
|
#### 2. UnifiedResponse
|
||||||
UnifiedResponse 对返回给前端的数据进行封装,包含 `code`、`message`、`data。`
|
UnifiedResponse 对返回给前端的数据进行封装,包含 `code`、`message`、`data。`
|
||||||
|
|
||||||
可使用 `UnifiedResponses` 快速构建 `UnifiedResponse` 对象。 `UnifiedResponses` 默认的成功代码为 "2000000", 用户按测试类 `CustomUnifiedResponseFactoryTests` 中所示范的,继承 `UnifiedResponses` 实现自己的工厂类, 自定义 `SUCCESS_CODE` 和 `DEFAULT_SUCCESS_MSG` 和工厂方法。 见 [issue#22](http://zhouxy.xyz:3000/plusone/plusone-commons/issues/22)。
|
可使用 `UnifiedResponses` 快速构建 `UnifiedResponse` 对象。 `UnifiedResponses` 默认的成功代码为 "2000000", 用户按测试类 `CustomUnifiedResponseFactoryTests` 中所示范的,继承 `UnifiedResponses` 实现自己的工厂类, 自定义 `SUCCESS_CODE` 和 `DEFAULT_SUCCESS_MSG` 和工厂方法。 见 [issue#22](http://gitea.zhouxy.xyz/plusone/plusone-commons/issues/22)。
|
||||||
|
|
||||||
## 八、time - 时间 API
|
## 八、time - 时间 API
|
||||||
### 1. 季度
|
### 1. 季度
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-parent</artifactId>
|
<artifactId>plusone-parent</artifactId>
|
||||||
<version>1.1.0-RC1</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>plusone-commons</artifactId>
|
<artifactId>plusone-commons</artifactId>
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
@@ -28,7 +27,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-dependencies</artifactId>
|
<artifactId>plusone-dependencies</artifactId>
|
||||||
<version>1.1.0-RC1</version>
|
<version>${project.version}</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@@ -27,7 +27,7 @@ import java.lang.annotation.Target;
|
|||||||
* <p>
|
* <p>
|
||||||
* 标识方法是读方法,如 getter。
|
* 标识方法是读方法,如 getter。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see WriterMethod
|
* @see WriterMethod
|
||||||
*/
|
*/
|
||||||
|
@@ -26,7 +26,7 @@ import java.lang.annotation.Target;
|
|||||||
*
|
*
|
||||||
* <p>标识方法为静态工厂方法
|
* <p>标识方法为静态工厂方法
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
|
@@ -27,7 +27,7 @@ import java.lang.annotation.Documented;
|
|||||||
*
|
*
|
||||||
* <p>标识方法为不支持的操作。该方法将抛出 {@link UnsupportedOperationException}。
|
* <p>标识方法为不支持的操作。该方法将抛出 {@link UnsupportedOperationException}。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see UnsupportedOperationException
|
* @see UnsupportedOperationException
|
||||||
|
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
|||||||
/**
|
/**
|
||||||
* ValueObject - 值对象
|
* ValueObject - 值对象
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Inherited
|
@Inherited
|
||||||
|
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
|||||||
* 标识该方法是虚方法。
|
* 标识该方法是虚方法。
|
||||||
* <p>该注解用于提醒、强调父类虽然有默认实现,但子类可以根据自己的需要覆写。</p>
|
* <p>该注解用于提醒、强调父类虽然有默认实现,但子类可以根据自己的需要覆写。</p>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
|
@@ -27,7 +27,7 @@ import java.lang.annotation.Target;
|
|||||||
* <p>
|
* <p>
|
||||||
* 标识方法是写方法,如 setter。
|
* 标识方法是写方法,如 setter。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see ReaderMethod
|
* @see ReaderMethod
|
||||||
*/
|
*/
|
||||||
|
@@ -54,6 +54,6 @@
|
|||||||
* <p>
|
* <p>
|
||||||
* 标记一个类,表示其作为值对象,区别于 Entity。
|
* 标记一个类,表示其作为值对象,区别于 Entity。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
package xyz.zhouxy.plusone.commons.annotation;
|
package xyz.zhouxy.plusone.commons.annotation;
|
||||||
|
@@ -26,7 +26,7 @@ import javax.annotation.Nullable;
|
|||||||
* 用于像自定义异常等需要带有 {@code code} 字段的类,
|
* 用于像自定义异常等需要带有 {@code code} 字段的类,
|
||||||
* 方便其它地方的程序判断该类的是否实现了此接口,以此获取其实例的 {@code code} 字段的值。
|
* 方便其它地方的程序判断该类的是否实现了此接口,以此获取其实例的 {@code code} 字段的值。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public interface IWithCode<T> {
|
public interface IWithCode<T> {
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
|
|||||||
* 用于像自定义异常等需要带有 {@code code} 字段的类,
|
* 用于像自定义异常等需要带有 {@code code} 字段的类,
|
||||||
* 方便其它地方的程序判断该类的是否实现了此接口,以此获取其实例的 {@code code} 字段的值。
|
* 方便其它地方的程序判断该类的是否实现了此接口,以此获取其实例的 {@code code} 字段的值。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public interface IWithIntCode {
|
public interface IWithIntCode {
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
|
|||||||
* 用于像自定义异常等需要带有 {@code code} 字段的类,
|
* 用于像自定义异常等需要带有 {@code code} 字段的类,
|
||||||
* 方便其它地方的程序判断该类的是否实现了此接口,以此获取其实例的 {@code code} 字段的值。
|
* 方便其它地方的程序判断该类的是否实现了此接口,以此获取其实例的 {@code code} 字段的值。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public interface IWithLongCode {
|
public interface IWithLongCode {
|
||||||
|
|
||||||
|
@@ -67,7 +67,7 @@ import javax.annotation.Nullable;
|
|||||||
* System.out.println(result); // Output: Return string
|
* System.out.println(result); // Output: Return string
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public final class Ref<T> {
|
public final class Ref<T> {
|
||||||
|
@@ -66,7 +66,7 @@
|
|||||||
* 类似于枚举这样的类型,通常需要设置固定的码值表示对应的含义。
|
* 类似于枚举这样的类型,通常需要设置固定的码值表示对应的含义。
|
||||||
* 可实现 {@link IWithCode}、{@link IWithIntCode}、{@link IWithLongCode},便于在需要的地方对这些接口的实现进行处理。
|
* 可实现 {@link IWithCode}、{@link IWithIntCode}、{@link IWithLongCode},便于在需要的地方对这些接口的实现进行处理。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@CheckReturnValue
|
@CheckReturnValue
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
|
@@ -33,7 +33,7 @@ import com.google.common.collect.Table;
|
|||||||
/**
|
/**
|
||||||
* 集合工具类
|
* 集合工具类
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class CollectionTools {
|
public class CollectionTools {
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
* </h3>
|
* </h3>
|
||||||
* 集合工具类
|
* 集合工具类
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
package xyz.zhouxy.plusone.commons.collection;
|
package xyz.zhouxy.plusone.commons.collection;
|
||||||
|
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
|
|||||||
/**
|
/**
|
||||||
* 正则表达式常量
|
* 正则表达式常量
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @see RegexConsts
|
* @see RegexConsts
|
||||||
* @see xyz.zhouxy.plusone.commons.util.RegexTools
|
* @see xyz.zhouxy.plusone.commons.util.RegexTools
|
||||||
*/
|
*/
|
||||||
|
@@ -19,7 +19,7 @@ package xyz.zhouxy.plusone.commons.constant;
|
|||||||
/**
|
/**
|
||||||
* 正则表达式常量
|
* 正则表达式常量
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @see PatternConsts
|
* @see PatternConsts
|
||||||
*/
|
*/
|
||||||
public final class RegexConsts {
|
public final class RegexConsts {
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
* </h3>
|
* </h3>
|
||||||
* {@link RegexConsts} 包含常见正则表达式;{@link PatternConsts} 包含对应的 {@link Pattern} 对象。
|
* {@link RegexConsts} 包含常见正则表达式;{@link PatternConsts} 包含对应的 {@link Pattern} 对象。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
package xyz.zhouxy.plusone.commons.constant;
|
package xyz.zhouxy.plusone.commons.constant;
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ package xyz.zhouxy.plusone.commons.exception;
|
|||||||
/**
|
/**
|
||||||
* 数据不存在异常
|
* 数据不存在异常
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public final class DataNotExistsException extends Exception {
|
public final class DataNotExistsException extends Exception {
|
||||||
|
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package xyz.zhouxy.plusone.commons.exception;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常工厂
|
||||||
|
*
|
||||||
|
* @author ZhouXY
|
||||||
|
*/
|
||||||
|
public interface IExceptionFactory<X extends Exception> {
|
||||||
|
/**
|
||||||
|
* 创建异常
|
||||||
|
*
|
||||||
|
* @return 异常对象
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
X create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用指定 {@code message} 创建异常
|
||||||
|
*
|
||||||
|
* @param message 异常信息
|
||||||
|
* @return 异常对象
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
X create(String message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用指定 {@code cause} 创建异常
|
||||||
|
*
|
||||||
|
* @param cause 包装的异常
|
||||||
|
* @return 异常对象
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
X create(Throwable cause);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用指定 {@code message} 和 {@code cause} 创建异常
|
||||||
|
*
|
||||||
|
* @param message 异常信息
|
||||||
|
* @param cause 包装的异常
|
||||||
|
* @return 异常对象
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
X create(String message, Throwable cause);
|
||||||
|
}
|
@@ -15,26 +15,30 @@
|
|||||||
*/
|
*/
|
||||||
package xyz.zhouxy.plusone.commons.exception;
|
package xyz.zhouxy.plusone.commons.exception;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.annotation.Virtual;
|
||||||
import xyz.zhouxy.plusone.commons.base.IWithCode;
|
import xyz.zhouxy.plusone.commons.base.IWithCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MultiTypesException
|
* IMultiTypesException
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 异常在不同场景下被抛出,可以用不同的枚举值,表示不同的场景类型。
|
* 异常在不同场景下被抛出,可以用不同的枚举值,表示不同的场景类型。
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 异常实现 {@link MultiTypesException} 的 {@link #getType} 方法,返回对应的场景类型。
|
* 异常实现 {@link IMultiTypesException} 的 {@link #getType} 方法,返回对应的场景类型。
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 表示场景类型的枚举实现 {@link ExceptionType},其中的工厂方法用于创建对应类型的异常。
|
* 表示场景类型的枚举实现 {@link IExceptionType},各个枚举值本身就是该场景的异常的工厂实例,
|
||||||
|
* 使用其中的工厂方法用于创建对应类型的异常。
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* public final class LoginException
|
* public final class LoginException
|
||||||
* extends RuntimeException
|
* extends RuntimeException
|
||||||
* implements MultiTypesException<LoginException, LoginException.Type> {
|
* implements IMultiTypesException<LoginException, LoginException.Type, String> {
|
||||||
* private static final long serialVersionUID = 881293090625085616L;
|
* private static final long serialVersionUID = 881293090625085616L;
|
||||||
* private final Type type;
|
* private final Type type;
|
||||||
* private LoginException(@Nonnull Type type, @Nonnull String message) {
|
* private LoginException(@Nonnull Type type, @Nonnull String message) {
|
||||||
@@ -61,7 +65,7 @@ import xyz.zhouxy.plusone.commons.base.IWithCode;
|
|||||||
*
|
*
|
||||||
* // ...
|
* // ...
|
||||||
*
|
*
|
||||||
* public enum Type implements ExceptionType<LoginException> {
|
* public enum Type implements IExceptionType<LoginException, String> {
|
||||||
* DEFAULT("00", "当前会话未登录"),
|
* DEFAULT("00", "当前会话未登录"),
|
||||||
* NOT_TOKEN("10", "未提供token"),
|
* NOT_TOKEN("10", "未提供token"),
|
||||||
* INVALID_TOKEN("20", "token无效"),
|
* INVALID_TOKEN("20", "token无效"),
|
||||||
@@ -118,15 +122,20 @@ import xyz.zhouxy.plusone.commons.base.IWithCode;
|
|||||||
* throw LoginException.Type.TOKEN_TIMEOUT.create();
|
* throw LoginException.Type.TOKEN_TIMEOUT.create();
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @param <X> 具体异常类
|
||||||
|
* @param <T> 异常场景
|
||||||
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public interface MultiTypesException<E extends Exception, T extends MultiTypesException.ExceptionType<E>> {
|
public interface IMultiTypesException<
|
||||||
|
X extends Exception,
|
||||||
|
T extends IMultiTypesException.IExceptionType<X, TCode>,
|
||||||
|
TCode extends Serializable> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异常类型
|
* 异常类型
|
||||||
*
|
*
|
||||||
* @return 异常类型。通常是实现了 {@link ExceptionType} 的枚举。
|
* @return 异常类型。通常是实现了 {@link IExceptionType} 的枚举。
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
T getType();
|
T getType();
|
||||||
@@ -136,55 +145,25 @@ public interface MultiTypesException<E extends Exception, T extends MultiTypesEx
|
|||||||
*
|
*
|
||||||
* @return 异常类型编码
|
* @return 异常类型编码
|
||||||
*/
|
*/
|
||||||
default @Nonnull String getTypeCode() {
|
default @Nonnull TCode getTypeCode() {
|
||||||
return getType().getCode();
|
return getType().getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异常类型
|
* 异常类型
|
||||||
*/
|
*/
|
||||||
public static interface ExceptionType<E extends Exception> extends IWithCode<String> {
|
public static interface IExceptionType<X extends Exception, TCode extends Serializable>
|
||||||
|
extends IWithCode<TCode>, IExceptionFactory<X> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认异常信息
|
* 默认异常信息
|
||||||
*/
|
*/
|
||||||
String getDefaultMessage();
|
String getDefaultMessage();
|
||||||
|
|
||||||
/**
|
@Virtual
|
||||||
* 创建异常
|
default String getDescription() {
|
||||||
*
|
return getDefaultMessage();
|
||||||
* @return 异常对象
|
}
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
E create();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用指定 {@code message} 创建异常
|
|
||||||
*
|
|
||||||
* @param message 异常信息
|
|
||||||
* @return 异常对象
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
E create(String message);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用指定 {@code cause} 创建异常
|
|
||||||
*
|
|
||||||
* @param cause 包装的异常
|
|
||||||
* @return 异常对象
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
E create(Throwable cause);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用指定 {@code message} 和 {@code cause} 创建异常
|
|
||||||
*
|
|
||||||
* @param message 异常信息
|
|
||||||
* @param cause 包装的异常
|
|
||||||
* @return 异常对象
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
E create(String message, Throwable cause);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -21,7 +21,7 @@ import java.time.format.DateTimeParseException;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.exception.business.RequestParamsException;
|
import xyz.zhouxy.plusone.commons.exception.business.RequestParamsException;
|
||||||
import xyz.zhouxy.plusone.commons.exception.MultiTypesException.ExceptionType;
|
import xyz.zhouxy.plusone.commons.exception.IMultiTypesException.IExceptionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析失败异常
|
* 解析失败异常
|
||||||
@@ -34,12 +34,12 @@ import xyz.zhouxy.plusone.commons.exception.MultiTypesException.ExceptionType;
|
|||||||
* throw new RequestParamsException(ParsingFailureException.Type.NUMBER_PARSING_FAILURE.create());
|
* throw new RequestParamsException(ParsingFailureException.Type.NUMBER_PARSING_FAILURE.create());
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public final class ParsingFailureException
|
public final class ParsingFailureException
|
||||||
extends RuntimeException
|
extends Exception
|
||||||
implements MultiTypesException<ParsingFailureException, ParsingFailureException.Type> {
|
implements IMultiTypesException<ParsingFailureException, ParsingFailureException.Type, String> {
|
||||||
private static final long serialVersionUID = 795996090625132616L;
|
private static final long serialVersionUID = 795996090625132616L;
|
||||||
|
|
||||||
private final Type type;
|
private final Type type;
|
||||||
@@ -171,7 +171,7 @@ public final class ParsingFailureException
|
|||||||
/** XML 解析失败 */
|
/** XML 解析失败 */
|
||||||
public static final Type XML_PARSING_FAILURE = Type.XML_PARSING_FAILURE;
|
public static final Type XML_PARSING_FAILURE = Type.XML_PARSING_FAILURE;
|
||||||
|
|
||||||
public enum Type implements ExceptionType<ParsingFailureException> {
|
public enum Type implements IExceptionType<ParsingFailureException, String> {
|
||||||
DEFAULT("00", "解析失败"),
|
DEFAULT("00", "解析失败"),
|
||||||
NUMBER_PARSING_FAILURE("10", "数字转换失败"),
|
NUMBER_PARSING_FAILURE("10", "数字转换失败"),
|
||||||
DATE_TIME_PARSING_FAILURE("20", "时间解析失败"),
|
DATE_TIME_PARSING_FAILURE("20", "时间解析失败"),
|
||||||
|
@@ -25,7 +25,7 @@ package xyz.zhouxy.plusone.commons.exception.business;
|
|||||||
* <p>
|
* <p>
|
||||||
* <b>NOTE: 通常表示业务中的意外情况。如:用户错误输入、缺失必填字段、用户余额不足等。</b>
|
* <b>NOTE: 通常表示业务中的意外情况。如:用户错误输入、缺失必填字段、用户余额不足等。</b>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class BizException extends RuntimeException {
|
public class BizException extends RuntimeException {
|
||||||
|
@@ -18,8 +18,8 @@ package xyz.zhouxy.plusone.commons.exception.business;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.exception.MultiTypesException.ExceptionType;
|
import xyz.zhouxy.plusone.commons.exception.IMultiTypesException.IExceptionType;
|
||||||
import xyz.zhouxy.plusone.commons.exception.MultiTypesException;
|
import xyz.zhouxy.plusone.commons.exception.IMultiTypesException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InvalidInputException
|
* InvalidInputException
|
||||||
@@ -30,12 +30,12 @@ import xyz.zhouxy.plusone.commons.exception.MultiTypesException;
|
|||||||
* <p>
|
* <p>
|
||||||
* <b>NOTE: 属业务异常</b>
|
* <b>NOTE: 属业务异常</b>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public final class InvalidInputException
|
public final class InvalidInputException
|
||||||
extends RequestParamsException
|
extends RequestParamsException
|
||||||
implements MultiTypesException<InvalidInputException, InvalidInputException.Type> {
|
implements IMultiTypesException<InvalidInputException, InvalidInputException.Type, String> {
|
||||||
private static final long serialVersionUID = -28994090625082516L;
|
private static final long serialVersionUID = -28994090625082516L;
|
||||||
|
|
||||||
private final Type type;
|
private final Type type;
|
||||||
@@ -109,7 +109,7 @@ public final class InvalidInputException
|
|||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Type implements ExceptionType<InvalidInputException> {
|
public enum Type implements IExceptionType<InvalidInputException, String> {
|
||||||
DEFAULT("00", "用户输入内容非法"),
|
DEFAULT("00", "用户输入内容非法"),
|
||||||
CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS("01", "包含非法恶意跳转链接"),
|
CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS("01", "包含非法恶意跳转链接"),
|
||||||
CONTAINS_ILLEGAL_WORDS("02", "包含违禁敏感词"),
|
CONTAINS_ILLEGAL_WORDS("02", "包含违禁敏感词"),
|
||||||
|
@@ -22,7 +22,7 @@ package xyz.zhouxy.plusone.commons.exception.business;
|
|||||||
* <p>
|
* <p>
|
||||||
* 用户请求参数错误
|
* 用户请求参数错误
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class RequestParamsException extends BizException {
|
public class RequestParamsException extends BizException {
|
||||||
|
@@ -17,6 +17,6 @@
|
|||||||
/**
|
/**
|
||||||
* 业务异常
|
* 业务异常
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
package xyz.zhouxy.plusone.commons.exception.business;
|
package xyz.zhouxy.plusone.commons.exception.business;
|
||||||
|
@@ -17,20 +17,21 @@
|
|||||||
/**
|
/**
|
||||||
* <h2>异常</h2>
|
* <h2>异常</h2>
|
||||||
*
|
*
|
||||||
* <h3>1. {@link MultiTypesException} - 多类型异常</h3>
|
* <h3>1. {@link IMultiTypesException} - 多类型异常</h3>
|
||||||
* <p>
|
* <p>
|
||||||
* 异常在不同场景下被抛出,可以用不同的枚举值,表示不同的场景类型。
|
* 异常在不同场景下被抛出,可以用不同的枚举值,表示不同的场景类型。
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 异常实现 {@link MultiTypesException} 的 {@link MultiTypesException#getType} 方法,返回对应的场景类型。
|
* 异常实现 {@link IMultiTypesException} 的 {@link IMultiTypesException#getType} 方法,返回对应的场景类型。
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 表示场景类型的枚举实现 {@link MultiTypesException.ExceptionType},其中的工厂方法用于创建对应类型的异常。
|
* 表示场景类型的枚举实现 {@link IMultiTypesException.IExceptionType},各个枚举值本身就是该场景的异常的工厂实例,
|
||||||
|
* 使用其中的工厂方法用于创建对应类型的异常。
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* public final class LoginException
|
* public final class LoginException
|
||||||
* extends RuntimeException
|
* extends RuntimeException
|
||||||
* implements MultiTypesException<LoginException, LoginException.Type> {
|
* implements IMultiTypesException<LoginException, LoginException.Type, String> {
|
||||||
* private static final long serialVersionUID = 881293090625085616L;
|
* private static final long serialVersionUID = 881293090625085616L;
|
||||||
* private final Type type;
|
* private final Type type;
|
||||||
* private LoginException(@Nonnull Type type, @Nonnull String message) {
|
* private LoginException(@Nonnull Type type, @Nonnull String message) {
|
||||||
@@ -57,7 +58,7 @@
|
|||||||
*
|
*
|
||||||
* // ...
|
* // ...
|
||||||
*
|
*
|
||||||
* public enum Type implements ExceptionType<LoginException> {
|
* public enum Type implements IExceptionType<LoginException, String> {
|
||||||
* DEFAULT("00", "当前会话未登录"),
|
* DEFAULT("00", "当前会话未登录"),
|
||||||
* NOT_TOKEN("10", "未提供token"),
|
* NOT_TOKEN("10", "未提供token"),
|
||||||
* INVALID_TOKEN("20", "token无效"),
|
* INVALID_TOKEN("20", "token无效"),
|
||||||
@@ -120,7 +121,7 @@
|
|||||||
* <h3>3. 系统异常</h3>
|
* <h3>3. 系统异常</h3>
|
||||||
* 预设常见的系统异常。可继承 {@link SysException} 自定义系统异常。
|
* 预设常见的系统异常。可继承 {@link SysException} 自定义系统异常。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
package xyz.zhouxy.plusone.commons.exception;
|
package xyz.zhouxy.plusone.commons.exception;
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ package xyz.zhouxy.plusone.commons.exception.system;
|
|||||||
* 当出现这种始料未及的诡异情况时,抛出 {@link DataOperationResultException} 并回滚事务。
|
* 当出现这种始料未及的诡异情况时,抛出 {@link DataOperationResultException} 并回滚事务。
|
||||||
* 后续需要排查原因。
|
* 后续需要排查原因。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public final class DataOperationResultException extends SysException {
|
public final class DataOperationResultException extends SysException {
|
||||||
|
@@ -22,7 +22,7 @@ package xyz.zhouxy.plusone.commons.exception.system;
|
|||||||
* <p>
|
* <p>
|
||||||
* 在无法找到可访问的 Mac 地址时抛出
|
* 在无法找到可访问的 Mac 地址时抛出
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class NoAvailableMacFoundException extends SysException {
|
public class NoAvailableMacFoundException extends SysException {
|
||||||
|
@@ -22,7 +22,7 @@ package xyz.zhouxy.plusone.commons.exception.system;
|
|||||||
* <p>
|
* <p>
|
||||||
* 通常表示应用代码存在问题,或因环境问题,引发异常。
|
* 通常表示应用代码存在问题,或因环境问题,引发异常。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class SysException extends RuntimeException {
|
public class SysException extends RuntimeException {
|
||||||
|
@@ -17,6 +17,6 @@
|
|||||||
/**
|
/**
|
||||||
* 系统异常
|
* 系统异常
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
package xyz.zhouxy.plusone.commons.exception.system;
|
package xyz.zhouxy.plusone.commons.exception.system;
|
||||||
|
@@ -25,7 +25,7 @@ import com.google.common.annotations.Beta;
|
|||||||
* 一个特殊的 {@link java.util.function.UnaryOperator}。
|
* 一个特殊的 {@link java.util.function.UnaryOperator}。
|
||||||
* 表示对 {@code boolean} 值的一元操作。
|
* 表示对 {@code boolean} 值的一元操作。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see java.util.function.UnaryOperator
|
* @see java.util.function.UnaryOperator
|
||||||
*/
|
*/
|
||||||
|
@@ -25,7 +25,7 @@ import com.google.common.annotations.Beta;
|
|||||||
* 一个特殊的 {@link java.util.function.UnaryOperator}。
|
* 一个特殊的 {@link java.util.function.UnaryOperator}。
|
||||||
* 表示对 {@code char} 的一元操作。
|
* 表示对 {@code char} 的一元操作。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see java.util.function.UnaryOperator
|
* @see java.util.function.UnaryOperator
|
||||||
*/
|
*/
|
||||||
|
@@ -24,7 +24,7 @@ package xyz.zhouxy.plusone.commons.function;
|
|||||||
*
|
*
|
||||||
* @param <E> 可抛出的异常类型
|
* @param <E> 可抛出的异常类型
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@@ -25,7 +25,7 @@ import java.util.function.Supplier;
|
|||||||
* <p>
|
* <p>
|
||||||
* 返回 {@code Optional<T>} 对象。
|
* 返回 {@code Optional<T>} 对象。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see Optional
|
* @see Optional
|
||||||
* @see Supplier
|
* @see Supplier
|
||||||
|
@@ -24,7 +24,7 @@ import java.util.function.Predicate;
|
|||||||
* <p>
|
* <p>
|
||||||
* {@link Predicate} 相关操作。
|
* {@link Predicate} 相关操作。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see Predicate
|
* @see Predicate
|
||||||
*/
|
*/
|
||||||
|
@@ -22,7 +22,7 @@ package xyz.zhouxy.plusone.commons.function;
|
|||||||
* <p>
|
* <p>
|
||||||
* 允许抛出异常的消费操作。是一个特殊的 {@link java.util.function.Consumer}。
|
* 允许抛出异常的消费操作。是一个特殊的 {@link java.util.function.Consumer}。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see java.util.function.Consumer
|
* @see java.util.function.Consumer
|
||||||
*/
|
*/
|
||||||
|
@@ -25,7 +25,7 @@ package xyz.zhouxy.plusone.commons.function;
|
|||||||
* @param <R> 返回结果类型
|
* @param <R> 返回结果类型
|
||||||
* @param <E> 异常类型
|
* @param <E> 异常类型
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @see java.util.function.Function
|
* @see java.util.function.Function
|
||||||
*/
|
*/
|
||||||
|
@@ -22,7 +22,7 @@ package xyz.zhouxy.plusone.commons.function;
|
|||||||
* <p>
|
* <p>
|
||||||
* 接收一个参数,返回一个布尔值,可抛出异常。
|
* 接收一个参数,返回一个布尔值,可抛出异常。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see java.util.function.Predicate
|
* @see java.util.function.Predicate
|
||||||
*/
|
*/
|
||||||
|
@@ -25,7 +25,7 @@ package xyz.zhouxy.plusone.commons.function;
|
|||||||
* @param <T> 结果类型
|
* @param <T> 结果类型
|
||||||
* @param <E> 异常类型
|
* @param <E> 异常类型
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see java.util.function.Supplier
|
* @see java.util.function.Supplier
|
||||||
*/
|
*/
|
||||||
|
@@ -25,7 +25,7 @@ import java.util.function.BiFunction;
|
|||||||
* <p>
|
* <p>
|
||||||
* 接受类型为 T 和 U 的两个参数,返回 {@code Optional<R>} 对象。
|
* 接受类型为 T 和 U 的两个参数,返回 {@code Optional<R>} 对象。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see Optional
|
* @see Optional
|
||||||
* @see BiFunction
|
* @see BiFunction
|
||||||
|
@@ -25,7 +25,7 @@ import java.util.function.Function;
|
|||||||
* <p>
|
* <p>
|
||||||
* 接受类型为 T 的参数,返回 {@code Optional<R>} 对象。
|
* 接受类型为 T 的参数,返回 {@code Optional<R>} 对象。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see Optional
|
* @see Optional
|
||||||
* @see Function
|
* @see Function
|
||||||
|
@@ -39,6 +39,6 @@
|
|||||||
* | Optional | ToOptionalFunction | Optional<R> apply(T) |
|
* | Optional | ToOptionalFunction | Optional<R> apply(T) |
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
package xyz.zhouxy.plusone.commons.function;
|
package xyz.zhouxy.plusone.commons.function;
|
||||||
|
@@ -33,7 +33,7 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
/**
|
/**
|
||||||
* 包含 JSR-310 相关数据类型的 {@code TypeAdapter}
|
* 包含 JSR-310 相关数据类型的 {@code TypeAdapter}
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
* @see TypeAdapter
|
* @see TypeAdapter
|
||||||
* @see com.google.gson.GsonBuilder
|
* @see com.google.gson.GsonBuilder
|
||||||
|
@@ -42,7 +42,7 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
|
|||||||
* <p>
|
* <p>
|
||||||
* 中国第二代居民身份证号
|
* 中国第二代居民身份证号
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see xyz.zhouxy.plusone.commons.constant.PatternConsts#CHINESE_2ND_ID_CARD_NUMBER
|
* @see xyz.zhouxy.plusone.commons.constant.PatternConsts#CHINESE_2ND_ID_CARD_NUMBER
|
||||||
*/
|
*/
|
||||||
|
@@ -23,7 +23,7 @@ import xyz.zhouxy.plusone.commons.base.IWithIntCode;
|
|||||||
/**
|
/**
|
||||||
* 性别
|
* 性别
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public enum Gender implements IWithIntCode {
|
public enum Gender implements IWithIntCode {
|
||||||
UNKNOWN(0, "Unknown", "未知"),
|
UNKNOWN(0, "Unknown", "未知"),
|
||||||
|
@@ -24,7 +24,7 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
|
|||||||
/**
|
/**
|
||||||
* 身份证号
|
* 身份证号
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public interface IDCardNumber {
|
public interface IDCardNumber {
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ import xyz.zhouxy.plusone.commons.annotation.ReaderMethod;
|
|||||||
/**
|
/**
|
||||||
* 带校验的字符串值对象
|
* 带校验的字符串值对象
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*
|
*
|
||||||
* @deprecated 弃用。使用工厂方法创建对象,并在其中进行校验即可。
|
* @deprecated 弃用。使用工厂方法创建对象,并在其中进行校验即可。
|
||||||
|
@@ -29,7 +29,7 @@ import xyz.zhouxy.plusone.commons.collection.CollectionTools;
|
|||||||
*
|
*
|
||||||
* @param <T> 内容列表的元素类型
|
* @param <T> 内容列表的元素类型
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @see PagingAndSortingQueryParams
|
* @see PagingAndSortingQueryParams
|
||||||
*/
|
*/
|
||||||
public class PageResult<T> {
|
public class PageResult<T> {
|
||||||
|
@@ -39,7 +39,7 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
|
|||||||
* 根据传入的 {@code size} 和 {@code pageNum},
|
* 根据传入的 {@code size} 和 {@code pageNum},
|
||||||
* 提供 {@code getOffset} 方法计算 SQL 语句中 {@code offset} 的值。
|
* 提供 {@code getOffset} 方法计算 SQL 语句中 {@code offset} 的值。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @see PagingParams
|
* @see PagingParams
|
||||||
* @see PageResult
|
* @see PageResult
|
||||||
*/
|
*/
|
||||||
|
@@ -24,7 +24,7 @@ import xyz.zhouxy.plusone.commons.model.dto.PagingAndSortingQueryParams.Sortable
|
|||||||
/**
|
/**
|
||||||
* 分页参数
|
* 分页参数
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @see PagingAndSortingQueryParams
|
* @see PagingAndSortingQueryParams
|
||||||
*/
|
*/
|
||||||
public class PagingParams {
|
public class PagingParams {
|
||||||
|
@@ -22,7 +22,7 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* 统一结果,对返回给前端的数据进行封装。
|
* 统一结果,对返回给前端的数据进行封装。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public class UnifiedResponse<T> {
|
public class UnifiedResponse<T> {
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* UnifiedResponse 工厂
|
* UnifiedResponse 工厂
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see UnifiedResponse
|
* @see UnifiedResponse
|
||||||
*/
|
*/
|
||||||
|
@@ -60,7 +60,7 @@
|
|||||||
* 自定义 SUCCESS_CODE 和 DEFAULT_SUCCESS_MSG 和工厂方法。
|
* 自定义 SUCCESS_CODE 和 DEFAULT_SUCCESS_MSG 和工厂方法。
|
||||||
* 见 <a href="http://zhouxy.xyz:3000/plusone/plusone-commons/issues/22">issue#22</a>。
|
* 见 <a href="http://zhouxy.xyz:3000/plusone/plusone-commons/issues/22">issue#22</a>。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
package xyz.zhouxy.plusone.commons.model.dto;
|
package xyz.zhouxy.plusone.commons.model.dto;
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
* <p>
|
* <p>
|
||||||
* 包含业务建模可能用到的性别、身份证等元素,也包含 DTO 相关类,如分页查询参数,响应结果,分页结果等。
|
* 包含业务建模可能用到的性别、身份证等元素,也包含 DTO 相关类,如分页查询参数,响应结果,分页结果等。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
package xyz.zhouxy.plusone.commons.model;
|
package xyz.zhouxy.plusone.commons.model;
|
||||||
|
@@ -32,7 +32,7 @@ import xyz.zhouxy.plusone.commons.base.IWithIntCode;
|
|||||||
/**
|
/**
|
||||||
* 季度
|
* 季度
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public enum Quarter implements IWithIntCode {
|
public enum Quarter implements IWithIntCode {
|
||||||
/** 第一季度 */
|
/** 第一季度 */
|
||||||
|
@@ -37,7 +37,7 @@ import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
|||||||
/**
|
/**
|
||||||
* 表示年份与季度
|
* 表示年份与季度
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
public final class YearQuarter implements Comparable<YearQuarter>, Serializable {
|
public final class YearQuarter implements Comparable<YearQuarter>, Serializable {
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
* 模仿 JDK 的 {@link java.time.Month} 和 {@link java.time.YearMonth},
|
* 模仿 JDK 的 {@link java.time.Month} 和 {@link java.time.YearMonth},
|
||||||
* 实现 {@link Quarter},{@link YearQuarter},对季度进行建模。
|
* 实现 {@link Quarter},{@link YearQuarter},对季度进行建模。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
package xyz.zhouxy.plusone.commons.time;
|
package xyz.zhouxy.plusone.commons.time;
|
||||||
|
@@ -37,7 +37,7 @@ import javax.annotation.Nullable;
|
|||||||
* <p>
|
* <p>
|
||||||
* 数组工具类
|
* 数组工具类
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class ArrayTools {
|
public class ArrayTools {
|
||||||
|
@@ -39,7 +39,7 @@ import xyz.zhouxy.plusone.commons.exception.system.DataOperationResultException;
|
|||||||
* "must be a well-formed email address");
|
* "must be a well-formed email address");
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public class AssertTools {
|
public class AssertTools {
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
|||||||
* <p>
|
* <p>
|
||||||
* BigDecimal 工具类
|
* BigDecimal 工具类
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class BigDecimals {
|
public class BigDecimals {
|
||||||
|
@@ -40,7 +40,7 @@ import xyz.zhouxy.plusone.commons.time.YearQuarter;
|
|||||||
/**
|
/**
|
||||||
* 日期时间工具类
|
* 日期时间工具类
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public class DateTimeTools {
|
public class DateTimeTools {
|
||||||
|
|
||||||
@@ -374,258 +374,6 @@ public class DateTimeTools {
|
|||||||
// #endregion
|
// #endregion
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJodaInstant
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 {@link java.time.Instant} 转换为 {@link org.joda.time.Instant}
|
|
||||||
*
|
|
||||||
* @param instant {@link java.time.Instant} 对象
|
|
||||||
* @return {@link org.joda.time.Instant} 对象
|
|
||||||
*/
|
|
||||||
public static org.joda.time.Instant toJodaInstant(java.time.Instant instant) {
|
|
||||||
return new org.joda.time.Instant(instant.toEpochMilli());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 {@link java.time.ZonedDateTime} 转换为 {@link org.joda.time.Instant}
|
|
||||||
*
|
|
||||||
* @param zonedDateTime {@link java.time.ZonedDateTime} 对象
|
|
||||||
* @return {@link org.joda.time.Instant} 对象
|
|
||||||
*/
|
|
||||||
public static org.joda.time.Instant toJodaInstant(java.time.ZonedDateTime zonedDateTime) {
|
|
||||||
return toJodaInstant(zonedDateTime.toInstant());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算指定时区的地区时间,对应的时间戳。结果为 {@link org.joda.time.Instant} 对象
|
|
||||||
*
|
|
||||||
* @param localDateTime {@link java.time.LocalDateTime} 对象
|
|
||||||
* @param zone 时区
|
|
||||||
* @return {@link org.joda.time.Instant} 对象
|
|
||||||
*/
|
|
||||||
public static org.joda.time.Instant toJodaInstant(java.time.LocalDateTime localDateTime, java.time.ZoneId zone) {
|
|
||||||
return toJodaInstant(java.time.ZonedDateTime.of(localDateTime, zone));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJavaInstant
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 {@link org.joda.time.Instant} 对象转换为 {@link java.time.Instant} 对象
|
|
||||||
*
|
|
||||||
* @param instant {@link org.joda.time.Instant} 对象
|
|
||||||
* @return {@link java.time.Instant} 对象
|
|
||||||
*/
|
|
||||||
public static java.time.Instant toJavaInstant(org.joda.time.Instant instant) {
|
|
||||||
return toInstant(instant.getMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 joda-time 中的 {@link org.joda.time.DateTime} 对象转换为 Java 的
|
|
||||||
* {@link java.time.Instant} 对象
|
|
||||||
*
|
|
||||||
* @param dateTime joda-time 中表示日期时间的 {@link org.joda.time.DateTime} 对象
|
|
||||||
* @return Java 表示时间戳的 {@link java.time.Instant} 对象
|
|
||||||
*/
|
|
||||||
public static java.time.Instant toJavaInstant(org.joda.time.DateTime dateTime) {
|
|
||||||
return toInstant(dateTime.getMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 joda-time 中的 {@link org.joda.time.LocalDateTime} 对象和
|
|
||||||
* {@link org.joda.time.DateTimeZone} 对象
|
|
||||||
* 转换为 Java 中的 {@link java.time.Instant} 对象
|
|
||||||
*
|
|
||||||
* @param localDateTime
|
|
||||||
* @param zone
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static java.time.Instant toJavaInstant(
|
|
||||||
org.joda.time.LocalDateTime localDateTime,
|
|
||||||
org.joda.time.DateTimeZone zone) {
|
|
||||||
return toJavaInstant(localDateTime.toDateTime(zone));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJodaDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 Java 中表示日期时间的 {@link java.time.ZonedDateTime} 对象
|
|
||||||
* 转换为 joda-time 的 {@link org.joda.time.DateTime} 对象
|
|
||||||
*
|
|
||||||
* @param zonedDateTime 日期时间
|
|
||||||
* @return joda-time 中对应的 {@link org.joda.time.DateTime} 对象
|
|
||||||
*/
|
|
||||||
public static org.joda.time.DateTime toJodaDateTime(java.time.ZonedDateTime zonedDateTime) {
|
|
||||||
org.joda.time.DateTimeZone zone = org.joda.time.DateTimeZone.forID(zonedDateTime.getZone().getId());
|
|
||||||
return toJodaInstant(zonedDateTime.toInstant()).toDateTime(zone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 java.time 中表示日期时间的 {@link java.time.LocalDateTime} 对象和表示时区的
|
|
||||||
* {@link java.time.ZoneId} 对象转换为 joda-time 中对应的 {@link org.joda.time.DateTime}
|
|
||||||
* 对象
|
|
||||||
* 转换为 joda-time 中对应的 {@link org.joda.time.DateTime} 对象
|
|
||||||
*
|
|
||||||
* @param localDateTime 日期时间
|
|
||||||
* @param zone 时区
|
|
||||||
* @return joda-time 中对应的 {@link org.joda.time.DateTime} 对象
|
|
||||||
*/
|
|
||||||
public static org.joda.time.DateTime toJodaDateTime(
|
|
||||||
java.time.LocalDateTime localDateTime,
|
|
||||||
java.time.ZoneId zone) {
|
|
||||||
org.joda.time.DateTimeZone dateTimeZone = toJodaZone(zone);
|
|
||||||
return toJodaInstant(ZonedDateTime.of(localDateTime, zone).toInstant()).toDateTime(dateTimeZone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算时间戳在指定时区对应的时间,结果使用 {@link org.joda.time.DateTime} 表示
|
|
||||||
*
|
|
||||||
* @param instant java.time 中的时间戳
|
|
||||||
* @param zone java.time 中的时区
|
|
||||||
* @return joda-time 中带时区的日期时间
|
|
||||||
*/
|
|
||||||
public static org.joda.time.DateTime toJodaDateTime(
|
|
||||||
java.time.Instant instant,
|
|
||||||
java.time.ZoneId zone) {
|
|
||||||
org.joda.time.DateTimeZone dateTimeZone = toJodaZone(zone);
|
|
||||||
return toJodaInstant(instant).toDateTime(dateTimeZone);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toZonedDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 joda-time 中带时区的日期时间,转换为 java.time 中带时区的日期时间
|
|
||||||
*
|
|
||||||
* @param dateTime joda-time 中带时区的日期时间
|
|
||||||
* @return java.time 中带时区的日期时间
|
|
||||||
*/
|
|
||||||
public static java.time.ZonedDateTime toZonedDateTime(org.joda.time.DateTime dateTime) {
|
|
||||||
java.time.ZoneId zone = dateTime.getZone().toTimeZone().toZoneId();
|
|
||||||
return toJavaInstant(dateTime.toInstant()).atZone(zone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 joda-time 中的 {@link org.joda.time.LocalDateTime} 和
|
|
||||||
* {@link org.joda.time.DateTimeZone}
|
|
||||||
* 转换为 java.time 中的 {@link java.time.ZonedDateTime}
|
|
||||||
*
|
|
||||||
* @param localDateTime joda-time 中的地区时间
|
|
||||||
* @param dateTimeZone joda-time 中的时区
|
|
||||||
* @return java.time 中带时区的日期时间
|
|
||||||
*/
|
|
||||||
public static java.time.ZonedDateTime toZonedDateTime(
|
|
||||||
org.joda.time.LocalDateTime localDateTime,
|
|
||||||
org.joda.time.DateTimeZone dateTimeZone) {
|
|
||||||
java.time.ZoneId zone = toJavaZone(dateTimeZone);
|
|
||||||
return toJavaInstant(localDateTime, dateTimeZone).atZone(zone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取 joda-time 中的 {@link org.joda.time.Instant} 在指定时区的时间,用 Java 8+ 的
|
|
||||||
* {@link java.time.ZonedDateTime} 表示
|
|
||||||
*
|
|
||||||
* @param instant joda-time 中的时间戳
|
|
||||||
* @param dateTimeZone joda-time 中的时区
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static java.time.ZonedDateTime toZonedDateTime(
|
|
||||||
org.joda.time.Instant instant,
|
|
||||||
org.joda.time.DateTimeZone dateTimeZone) {
|
|
||||||
java.time.ZoneId zone = toJavaZone(dateTimeZone);
|
|
||||||
return toJavaInstant(instant).atZone(zone);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJodaLocalDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 {@link java.time.LocalDateTime} 转换为 {@link org.joda.time.LocalDateTime}
|
|
||||||
*
|
|
||||||
* @param localDateTime Java 8 LocalDateTime
|
|
||||||
* @return joda-time LocalDateTime
|
|
||||||
*/
|
|
||||||
public static org.joda.time.LocalDateTime toJodaLocalDateTime(java.time.LocalDateTime localDateTime) {
|
|
||||||
java.time.ZoneId javaZone = java.time.ZoneId.systemDefault();
|
|
||||||
org.joda.time.DateTimeZone jodaZone = toJodaZone(javaZone);
|
|
||||||
return toJodaInstant(localDateTime, javaZone).toDateTime(jodaZone).toLocalDateTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJavaLocalDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 {@link org.joda.time.LocalDateTime} 转换为 {@link java.time.LocalDateTime}
|
|
||||||
*
|
|
||||||
* @param localDateTime joda-time LocalDateTime
|
|
||||||
* @return Java 8 LocalDateTime
|
|
||||||
*/
|
|
||||||
public static java.time.LocalDateTime toJavaLocalDateTime(org.joda.time.LocalDateTime localDateTime) {
|
|
||||||
org.joda.time.DateTimeZone jodaZone = org.joda.time.DateTimeZone.getDefault();
|
|
||||||
java.time.ZoneId javaZone = toJavaZone(jodaZone);
|
|
||||||
return toJavaInstant(localDateTime, jodaZone).atZone(javaZone).toLocalDateTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - ZoneId <--> DateTimeZone
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 转换 Java API 和 joda-time API 表示时区的对象
|
|
||||||
*
|
|
||||||
* @param jodaZone joda-time API 中表示时区的对象
|
|
||||||
* @return Java API 中表示时区的对象
|
|
||||||
*/
|
|
||||||
public static java.time.ZoneId toJavaZone(org.joda.time.DateTimeZone jodaZone) {
|
|
||||||
return jodaZone.toTimeZone().toZoneId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 转换 Java API 和 joda-time API 表示时区的对象
|
|
||||||
*
|
|
||||||
* @param zone Java API 中表示时区的对象
|
|
||||||
* @return joda-time API 中表示时区的对象
|
|
||||||
*/
|
|
||||||
public static org.joda.time.DateTimeZone toJodaZone(java.time.ZoneId zone) {
|
|
||||||
return org.joda.time.DateTimeZone.forID(zone.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
// #region - YearQuarter & Quarter
|
// #region - YearQuarter & Quarter
|
||||||
// ================================
|
// ================================
|
||||||
|
@@ -26,7 +26,7 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* 枚举工具类
|
* 枚举工具类
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public final class EnumTools {
|
public final class EnumTools {
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
|||||||
*
|
*
|
||||||
* 参考 <a href="https://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/">Enumeration classes</a>
|
* 参考 <a href="https://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/">Enumeration classes</a>
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @deprecated 设计 Enumeration 的灵感来自于 .net 社区,因为 C# 的枚举不带行为。
|
* @deprecated 设计 Enumeration 的灵感来自于 .net 社区,因为 C# 的枚举不带行为。
|
||||||
* 但 Java 的枚举可以带行为,故大多数情况下不需要这种设计。
|
* 但 Java 的枚举可以带行为,故大多数情况下不需要这种设计。
|
||||||
*/
|
*/
|
||||||
|
@@ -30,7 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*
|
*
|
||||||
* @see UUID
|
* @see UUID
|
||||||
* @see IdWorker
|
* @see IdWorker
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public class IdGenerator {
|
public class IdGenerator {
|
||||||
|
|
||||||
|
@@ -0,0 +1,284 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.commons.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Joda-Time 工具类
|
||||||
|
*
|
||||||
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
|
*/
|
||||||
|
public class JodaTimeTools {
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJodaInstant
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 {@link java.time.Instant} 转换为 {@link org.joda.time.Instant}
|
||||||
|
*
|
||||||
|
* @param instant {@link java.time.Instant} 对象
|
||||||
|
* @return {@link org.joda.time.Instant} 对象
|
||||||
|
*/
|
||||||
|
public static org.joda.time.Instant toJodaInstant(java.time.Instant instant) {
|
||||||
|
return new org.joda.time.Instant(instant.toEpochMilli());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 {@link java.time.ZonedDateTime} 转换为 {@link org.joda.time.Instant}
|
||||||
|
*
|
||||||
|
* @param zonedDateTime {@link java.time.ZonedDateTime} 对象
|
||||||
|
* @return {@link org.joda.time.Instant} 对象
|
||||||
|
*/
|
||||||
|
public static org.joda.time.Instant toJodaInstant(java.time.ZonedDateTime zonedDateTime) {
|
||||||
|
return toJodaInstant(zonedDateTime.toInstant());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算指定时区的地区时间,对应的时间戳。结果为 {@link org.joda.time.Instant} 对象
|
||||||
|
*
|
||||||
|
* @param localDateTime {@link java.time.LocalDateTime} 对象
|
||||||
|
* @param zone 时区
|
||||||
|
* @return {@link org.joda.time.Instant} 对象
|
||||||
|
*/
|
||||||
|
public static org.joda.time.Instant toJodaInstant(java.time.LocalDateTime localDateTime, java.time.ZoneId zone) {
|
||||||
|
return toJodaInstant(java.time.ZonedDateTime.of(localDateTime, zone));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJavaInstant
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 {@link org.joda.time.Instant} 对象转换为 {@link java.time.Instant} 对象
|
||||||
|
*
|
||||||
|
* @param instant {@link org.joda.time.Instant} 对象
|
||||||
|
* @return {@link java.time.Instant} 对象
|
||||||
|
*/
|
||||||
|
public static java.time.Instant toJavaInstant(org.joda.time.Instant instant) {
|
||||||
|
return DateTimeTools.toInstant(instant.getMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 joda-time 中的 {@link org.joda.time.DateTime} 对象转换为 Java 的
|
||||||
|
* {@link java.time.Instant} 对象
|
||||||
|
*
|
||||||
|
* @param dateTime joda-time 中表示日期时间的 {@link org.joda.time.DateTime} 对象
|
||||||
|
* @return Java 表示时间戳的 {@link java.time.Instant} 对象
|
||||||
|
*/
|
||||||
|
public static java.time.Instant toJavaInstant(org.joda.time.DateTime dateTime) {
|
||||||
|
return DateTimeTools.toInstant(dateTime.getMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 joda-time 中的 {@link org.joda.time.LocalDateTime} 对象和
|
||||||
|
* {@link org.joda.time.DateTimeZone} 对象
|
||||||
|
* 转换为 Java 中的 {@link java.time.Instant} 对象
|
||||||
|
*
|
||||||
|
* @param localDateTime
|
||||||
|
* @param zone
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static java.time.Instant toJavaInstant(
|
||||||
|
org.joda.time.LocalDateTime localDateTime,
|
||||||
|
org.joda.time.DateTimeZone zone) {
|
||||||
|
return toJavaInstant(localDateTime.toDateTime(zone));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJodaDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Java 中表示日期时间的 {@link java.time.ZonedDateTime} 对象
|
||||||
|
* 转换为 joda-time 的 {@link org.joda.time.DateTime} 对象
|
||||||
|
*
|
||||||
|
* @param zonedDateTime 日期时间
|
||||||
|
* @return joda-time 中对应的 {@link org.joda.time.DateTime} 对象
|
||||||
|
*/
|
||||||
|
public static org.joda.time.DateTime toJodaDateTime(java.time.ZonedDateTime zonedDateTime) {
|
||||||
|
org.joda.time.DateTimeZone zone = org.joda.time.DateTimeZone.forID(zonedDateTime.getZone().getId());
|
||||||
|
return toJodaInstant(zonedDateTime.toInstant()).toDateTime(zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 java.time 中表示日期时间的 {@link java.time.LocalDateTime} 对象和表示时区的
|
||||||
|
* {@link java.time.ZoneId} 对象转换为 joda-time 中对应的 {@link org.joda.time.DateTime}
|
||||||
|
* 对象
|
||||||
|
* 转换为 joda-time 中对应的 {@link org.joda.time.DateTime} 对象
|
||||||
|
*
|
||||||
|
* @param localDateTime 日期时间
|
||||||
|
* @param zone 时区
|
||||||
|
* @return joda-time 中对应的 {@link org.joda.time.DateTime} 对象
|
||||||
|
*/
|
||||||
|
public static org.joda.time.DateTime toJodaDateTime(
|
||||||
|
java.time.LocalDateTime localDateTime,
|
||||||
|
java.time.ZoneId zone) {
|
||||||
|
org.joda.time.DateTimeZone dateTimeZone = toJodaZone(zone);
|
||||||
|
return toJodaInstant(java.time.ZonedDateTime.of(localDateTime, zone).toInstant()).toDateTime(dateTimeZone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算时间戳在指定时区对应的时间,结果使用 {@link org.joda.time.DateTime} 表示
|
||||||
|
*
|
||||||
|
* @param instant java.time 中的时间戳
|
||||||
|
* @param zone java.time 中的时区
|
||||||
|
* @return joda-time 中带时区的日期时间
|
||||||
|
*/
|
||||||
|
public static org.joda.time.DateTime toJodaDateTime(
|
||||||
|
java.time.Instant instant,
|
||||||
|
java.time.ZoneId zone) {
|
||||||
|
org.joda.time.DateTimeZone dateTimeZone = toJodaZone(zone);
|
||||||
|
return toJodaInstant(instant).toDateTime(dateTimeZone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toZonedDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 joda-time 中带时区的日期时间,转换为 java.time 中带时区的日期时间
|
||||||
|
*
|
||||||
|
* @param dateTime joda-time 中带时区的日期时间
|
||||||
|
* @return java.time 中带时区的日期时间
|
||||||
|
*/
|
||||||
|
public static java.time.ZonedDateTime toZonedDateTime(org.joda.time.DateTime dateTime) {
|
||||||
|
java.time.ZoneId zone = dateTime.getZone().toTimeZone().toZoneId();
|
||||||
|
return toJavaInstant(dateTime.toInstant()).atZone(zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 joda-time 中的 {@link org.joda.time.LocalDateTime} 和
|
||||||
|
* {@link org.joda.time.DateTimeZone}
|
||||||
|
* 转换为 java.time 中的 {@link java.time.ZonedDateTime}
|
||||||
|
*
|
||||||
|
* @param localDateTime joda-time 中的地区时间
|
||||||
|
* @param dateTimeZone joda-time 中的时区
|
||||||
|
* @return java.time 中带时区的日期时间
|
||||||
|
*/
|
||||||
|
public static java.time.ZonedDateTime toZonedDateTime(
|
||||||
|
org.joda.time.LocalDateTime localDateTime,
|
||||||
|
org.joda.time.DateTimeZone dateTimeZone) {
|
||||||
|
java.time.ZoneId zone = toJavaZone(dateTimeZone);
|
||||||
|
return toJavaInstant(localDateTime, dateTimeZone).atZone(zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 joda-time 中的 {@link org.joda.time.Instant} 在指定时区的时间,用 Java 8+ 的
|
||||||
|
* {@link java.time.ZonedDateTime} 表示
|
||||||
|
*
|
||||||
|
* @param instant joda-time 中的时间戳
|
||||||
|
* @param dateTimeZone joda-time 中的时区
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static java.time.ZonedDateTime toZonedDateTime(
|
||||||
|
org.joda.time.Instant instant,
|
||||||
|
org.joda.time.DateTimeZone dateTimeZone) {
|
||||||
|
java.time.ZoneId zone = toJavaZone(dateTimeZone);
|
||||||
|
return toJavaInstant(instant).atZone(zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJodaLocalDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 {@link java.time.LocalDateTime} 转换为 {@link org.joda.time.LocalDateTime}
|
||||||
|
*
|
||||||
|
* @param localDateTime Java 8 LocalDateTime
|
||||||
|
* @return joda-time LocalDateTime
|
||||||
|
*/
|
||||||
|
public static org.joda.time.LocalDateTime toJodaLocalDateTime(java.time.LocalDateTime localDateTime) {
|
||||||
|
java.time.ZoneId javaZone = java.time.ZoneId.systemDefault();
|
||||||
|
org.joda.time.DateTimeZone jodaZone = toJodaZone(javaZone);
|
||||||
|
return toJodaInstant(localDateTime, javaZone).toDateTime(jodaZone).toLocalDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJavaLocalDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 {@link org.joda.time.LocalDateTime} 转换为 {@link java.time.LocalDateTime}
|
||||||
|
*
|
||||||
|
* @param localDateTime joda-time LocalDateTime
|
||||||
|
* @return Java 8 LocalDateTime
|
||||||
|
*/
|
||||||
|
public static java.time.LocalDateTime toJavaLocalDateTime(org.joda.time.LocalDateTime localDateTime) {
|
||||||
|
org.joda.time.DateTimeZone jodaZone = org.joda.time.DateTimeZone.getDefault();
|
||||||
|
java.time.ZoneId javaZone = toJavaZone(jodaZone);
|
||||||
|
return toJavaInstant(localDateTime, jodaZone).atZone(javaZone).toLocalDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - ZoneId <--> DateTimeZone
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换 Java API 和 joda-time API 表示时区的对象
|
||||||
|
*
|
||||||
|
* @param jodaZone joda-time API 中表示时区的对象
|
||||||
|
* @return Java API 中表示时区的对象
|
||||||
|
*/
|
||||||
|
public static java.time.ZoneId toJavaZone(org.joda.time.DateTimeZone jodaZone) {
|
||||||
|
return jodaZone.toTimeZone().toZoneId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换 Java API 和 joda-time API 表示时区的对象
|
||||||
|
*
|
||||||
|
* @param zone Java API 中表示时区的对象
|
||||||
|
* @return joda-time API 中表示时区的对象
|
||||||
|
*/
|
||||||
|
public static org.joda.time.DateTimeZone toJodaZone(java.time.ZoneId zone) {
|
||||||
|
return org.joda.time.DateTimeZone.forID(zone.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私有构造方法
|
||||||
|
*/
|
||||||
|
private JodaTimeTools() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
|
}
|
||||||
|
}
|
@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* 数字工具类
|
* 数字工具类
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public class Numbers {
|
public class Numbers {
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ import com.google.common.annotations.Beta;
|
|||||||
* <p>
|
* <p>
|
||||||
* 提供一些 Optional 相关的方法
|
* 提供一些 Optional 相关的方法
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @see Optional
|
* @see Optional
|
||||||
* @see OptionalInt
|
* @see OptionalInt
|
||||||
|
@@ -29,7 +29,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
* <p>
|
* <p>
|
||||||
* 建议调用方自行维护 Random 对象
|
* 建议调用方自行维护 Random 对象
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public final class RandomTools {
|
public final class RandomTools {
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ import com.google.common.cache.LoadingCache;
|
|||||||
/**
|
/**
|
||||||
* 封装一些常用的正则操作,并可以缓存 {@link Pattern} 实例以复用。
|
* 封装一些常用的正则操作,并可以缓存 {@link Pattern} 实例以复用。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
public final class RegexTools {
|
public final class RegexTools {
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
|||||||
* <p>
|
* <p>
|
||||||
* 字符串工具类。
|
* 字符串工具类。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class StringTools {
|
public class StringTools {
|
||||||
|
@@ -32,7 +32,7 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* TreeBuilder
|
* TreeBuilder
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class TreeBuilder<T, TSubTree extends T, TIdentity> {
|
public class TreeBuilder<T, TSubTree extends T, TIdentity> {
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
* <p>
|
* <p>
|
||||||
* 包含树构建器({@link TreeBuilder})、断言工具({@link AssertTools})、ID 生成器({@link IdGenerator})及其它实用工具类。
|
* 包含树构建器({@link TreeBuilder})、断言工具({@link AssertTools})、ID 生成器({@link IdGenerator})及其它实用工具类。
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
package xyz.zhouxy.plusone.commons.util;
|
package xyz.zhouxy.plusone.commons.util;
|
||||||
|
@@ -220,7 +220,7 @@ public class PagingAndSortingQueryParamsTests {
|
|||||||
/**
|
/**
|
||||||
* 账号信息查询参数
|
* 账号信息查询参数
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author ZhouXY108 <luquanlion@outlook.com>
|
||||||
*/
|
*/
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
class AccountQueryParams extends PagingAndSortingQueryParams {
|
class AccountQueryParams extends PagingAndSortingQueryParams {
|
||||||
|
@@ -277,144 +277,6 @@ class DateTimeToolsTests {
|
|||||||
// #endregion - toLocalDateTime
|
// #endregion - toLocalDateTime
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJodaInstant
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJodaInstant_JavaInstant() {
|
|
||||||
assertEquals(JODA_INSTANT_WITH_SYS_ZONE, DateTimeTools.toJodaInstant(INSTANT_WITH_SYS_ZONE));
|
|
||||||
assertEquals(JODA_INSTANT, DateTimeTools.toJodaInstant(INSTANT));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJodaInstant_ZonedDateTime() {
|
|
||||||
assertEquals(JODA_INSTANT_WITH_SYS_ZONE, DateTimeTools.toJodaInstant(ZONED_DATE_TIME_WITH_SYS_ZONE));
|
|
||||||
assertEquals(JODA_INSTANT, DateTimeTools.toJodaInstant(ZONED_DATE_TIME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJodaInstant_LocalDateTimeAndZoneId() {
|
|
||||||
assertEquals(JODA_INSTANT_WITH_SYS_ZONE, DateTimeTools.toJodaInstant(LOCAL_DATE_TIME, SYS_ZONE_ID));
|
|
||||||
assertEquals(JODA_INSTANT, DateTimeTools.toJodaInstant(LOCAL_DATE_TIME, ZONE_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion - toJodaInstant
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJavaInstant
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJavaInstant_JodaInstant() {
|
|
||||||
assertEquals(INSTANT_WITH_SYS_ZONE, DateTimeTools.toJavaInstant(JODA_INSTANT_WITH_SYS_ZONE));
|
|
||||||
assertEquals(INSTANT, DateTimeTools.toJavaInstant(JODA_INSTANT));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJavaInstant_JodaDateTime() {
|
|
||||||
assertEquals(INSTANT_WITH_SYS_ZONE, DateTimeTools.toJavaInstant(JODA_DATE_TIME_WITH_SYS_ZONE));
|
|
||||||
assertEquals(INSTANT, DateTimeTools.toJavaInstant(JODA_DATE_TIME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJavaInstant_JodaLocalDateTimeAndJodaDateTimeZone() {
|
|
||||||
assertEquals(INSTANT_WITH_SYS_ZONE, DateTimeTools.toJavaInstant(JODA_LOCAL_DATE_TIME, JODA_SYS_ZONE));
|
|
||||||
assertEquals(INSTANT, DateTimeTools.toJavaInstant(JODA_LOCAL_DATE_TIME, JODA_ZONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion - toJavaInstant
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJodaDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJodaDateTime_ZonedDateTime() {
|
|
||||||
assertEquals(JODA_DATE_TIME_WITH_SYS_ZONE, DateTimeTools.toJodaDateTime(ZONED_DATE_TIME_WITH_SYS_ZONE));
|
|
||||||
assertEquals(JODA_DATE_TIME, DateTimeTools.toJodaDateTime(ZONED_DATE_TIME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJodaDateTime_LocalDateTimeAndZoneId() {
|
|
||||||
assertEquals(JODA_DATE_TIME_WITH_SYS_ZONE, DateTimeTools.toJodaDateTime(LOCAL_DATE_TIME, SYS_ZONE_ID));
|
|
||||||
assertEquals(JODA_DATE_TIME, DateTimeTools.toJodaDateTime(LOCAL_DATE_TIME, ZONE_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJodaDateTime_InstantAndZoneId() {
|
|
||||||
assertEquals(JODA_DATE_TIME_WITH_SYS_ZONE, DateTimeTools.toJodaDateTime(INSTANT_WITH_SYS_ZONE, SYS_ZONE_ID));
|
|
||||||
assertEquals(JODA_DATE_TIME, DateTimeTools.toJodaDateTime(INSTANT, ZONE_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion - toJodaDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toZonedDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toZonedDateTime_JodaDateTime() {
|
|
||||||
assertEquals(ZONED_DATE_TIME_WITH_SYS_ZONE, DateTimeTools.toZonedDateTime(JODA_DATE_TIME_WITH_SYS_ZONE));
|
|
||||||
assertEquals(ZONED_DATE_TIME, DateTimeTools.toZonedDateTime(JODA_DATE_TIME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toZonedDateTime_JodaLocalDateTimeAndJodaDateTimeZone() {
|
|
||||||
assertEquals(ZONED_DATE_TIME_WITH_SYS_ZONE, DateTimeTools.toZonedDateTime(JODA_LOCAL_DATE_TIME, JODA_SYS_ZONE));
|
|
||||||
assertEquals(ZONED_DATE_TIME, DateTimeTools.toZonedDateTime(JODA_LOCAL_DATE_TIME, JODA_ZONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toZonedDateTime_JodaInstantAndJodaDateTimeZone() {
|
|
||||||
assertEquals(ZONED_DATE_TIME_WITH_SYS_ZONE, DateTimeTools.toZonedDateTime(JODA_INSTANT_WITH_SYS_ZONE, JODA_SYS_ZONE));
|
|
||||||
assertEquals(ZONED_DATE_TIME, DateTimeTools.toZonedDateTime(JODA_INSTANT, JODA_ZONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion - toZonedDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - toJodaLocalDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJodaLocalDateTime_JavaLocalDateTime() {
|
|
||||||
assertEquals(JODA_LOCAL_DATE_TIME, DateTimeTools.toJodaLocalDateTime(LOCAL_DATE_TIME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void toJavaLocalDateTime_JodaLocalDateTime() {
|
|
||||||
assertEquals(LOCAL_DATE_TIME, DateTimeTools.toJavaLocalDateTime(JODA_LOCAL_DATE_TIME));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion - toJodaLocalDateTime
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #region - ZoneId <--> DateTimeZone
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void convertJavaZoneIdAndJodaDateTimeZone() {
|
|
||||||
assertEquals(SYS_ZONE_ID, DateTimeTools.toJavaZone(JODA_SYS_ZONE));
|
|
||||||
assertEquals(ZONE_ID, DateTimeTools.toJavaZone(JODA_ZONE));
|
|
||||||
assertEquals(JODA_SYS_ZONE, DateTimeTools.toJodaZone(SYS_ZONE_ID));
|
|
||||||
assertEquals(JODA_ZONE, DateTimeTools.toJodaZone(ZONE_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================
|
|
||||||
// #endregion - ZoneId <--> DateTimeZone
|
|
||||||
// ================================
|
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
// #region - YearQuarter & Quarter
|
// #region - YearQuarter & Quarter
|
||||||
// ================================
|
// ================================
|
||||||
|
@@ -0,0 +1,223 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package xyz.zhouxy.plusone.commons.util;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class JodaTimeToolsTests {
|
||||||
|
|
||||||
|
// Java
|
||||||
|
static final LocalDateTime LOCAL_DATE_TIME = LocalDateTime.of(2024, 12, 29, 12, 58, 30, 333000000);
|
||||||
|
static final LocalDate LOCAL_DATE = LOCAL_DATE_TIME.toLocalDate();
|
||||||
|
static final LocalTime LOCAL_TIME = LOCAL_DATE_TIME.toLocalTime();
|
||||||
|
|
||||||
|
// Java - 2024-12-29 12:58:30.333333333 SystemDefaultZone
|
||||||
|
static final ZoneId SYS_ZONE_ID = ZoneId.systemDefault();
|
||||||
|
static final ZonedDateTime ZONED_DATE_TIME_WITH_SYS_ZONE = LOCAL_DATE_TIME.atZone(SYS_ZONE_ID);
|
||||||
|
static final Instant INSTANT_WITH_SYS_ZONE = ZONED_DATE_TIME_WITH_SYS_ZONE.toInstant();
|
||||||
|
static final long INSTANT_MILLIS = INSTANT_WITH_SYS_ZONE.toEpochMilli();
|
||||||
|
|
||||||
|
static final TimeZone SYS_TIME_ZONE = TimeZone.getDefault();
|
||||||
|
static final Date SYS_DATE = Date.from(INSTANT_WITH_SYS_ZONE);
|
||||||
|
static final Calendar SYS_CALENDAR = Calendar.getInstance(SYS_TIME_ZONE);
|
||||||
|
static {
|
||||||
|
SYS_CALENDAR.setTime(SYS_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Java - 2024-12-29 12:58:30.333333333 GMT+04:00
|
||||||
|
static final ZoneId ZONE_ID = ZoneId.of("GMT+04:00");
|
||||||
|
static final ZonedDateTime ZONED_DATE_TIME = LOCAL_DATE_TIME.atZone(ZONE_ID);
|
||||||
|
static final Instant INSTANT = ZONED_DATE_TIME.toInstant();
|
||||||
|
static final long MILLIS = INSTANT.toEpochMilli();
|
||||||
|
|
||||||
|
static final TimeZone TIME_ZONE = TimeZone.getTimeZone(ZONE_ID);
|
||||||
|
static final Date DATE = Date.from(INSTANT);
|
||||||
|
static final Calendar CALENDAR = Calendar.getInstance(TIME_ZONE);
|
||||||
|
static {
|
||||||
|
CALENDAR.setTime(DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Joda
|
||||||
|
static final org.joda.time.LocalDateTime JODA_LOCAL_DATE_TIME
|
||||||
|
= new org.joda.time.LocalDateTime(2024, 12, 29, 12, 58, 30, 333);
|
||||||
|
static final org.joda.time.LocalDate JODA_LOCAL_DATE = JODA_LOCAL_DATE_TIME.toLocalDate();
|
||||||
|
static final org.joda.time.LocalTime JODA_LOCAL_TIME = JODA_LOCAL_DATE_TIME.toLocalTime();
|
||||||
|
|
||||||
|
// Joda - 2024-12-29 12:58:30.333 SystemDefaultZone
|
||||||
|
static final org.joda.time.DateTimeZone JODA_SYS_ZONE = org.joda.time.DateTimeZone.getDefault();
|
||||||
|
static final org.joda.time.DateTime JODA_DATE_TIME_WITH_SYS_ZONE = JODA_LOCAL_DATE_TIME.toDateTime(JODA_SYS_ZONE);
|
||||||
|
static final org.joda.time.Instant JODA_INSTANT_WITH_SYS_ZONE = JODA_DATE_TIME_WITH_SYS_ZONE.toInstant();
|
||||||
|
static final long JODA_INSTANT_MILLIS = JODA_INSTANT_WITH_SYS_ZONE.getMillis();
|
||||||
|
|
||||||
|
// Joda - 2024-12-29 12:58:30.333 GMT+04:00
|
||||||
|
static final org.joda.time.DateTimeZone JODA_ZONE = org.joda.time.DateTimeZone.forID("GMT+04:00");
|
||||||
|
static final org.joda.time.DateTime JODA_DATE_TIME = JODA_LOCAL_DATE_TIME.toDateTime(JODA_ZONE);
|
||||||
|
static final org.joda.time.Instant JODA_INSTANT = JODA_DATE_TIME.toInstant();
|
||||||
|
static final long JODA_MILLIS = JODA_INSTANT.getMillis();
|
||||||
|
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJodaInstant
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJodaInstant_JavaInstant() {
|
||||||
|
assertEquals(JODA_INSTANT_WITH_SYS_ZONE, JodaTimeTools.toJodaInstant(INSTANT_WITH_SYS_ZONE));
|
||||||
|
assertEquals(JODA_INSTANT, JodaTimeTools.toJodaInstant(INSTANT));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJodaInstant_ZonedDateTime() {
|
||||||
|
assertEquals(JODA_INSTANT_WITH_SYS_ZONE, JodaTimeTools.toJodaInstant(ZONED_DATE_TIME_WITH_SYS_ZONE));
|
||||||
|
assertEquals(JODA_INSTANT, JodaTimeTools.toJodaInstant(ZONED_DATE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJodaInstant_LocalDateTimeAndZoneId() {
|
||||||
|
assertEquals(JODA_INSTANT_WITH_SYS_ZONE, JodaTimeTools.toJodaInstant(LOCAL_DATE_TIME, SYS_ZONE_ID));
|
||||||
|
assertEquals(JODA_INSTANT, JodaTimeTools.toJodaInstant(LOCAL_DATE_TIME, ZONE_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion - toJodaInstant
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJavaInstant
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJavaInstant_JodaInstant() {
|
||||||
|
assertEquals(INSTANT_WITH_SYS_ZONE, JodaTimeTools.toJavaInstant(JODA_INSTANT_WITH_SYS_ZONE));
|
||||||
|
assertEquals(INSTANT, JodaTimeTools.toJavaInstant(JODA_INSTANT));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJavaInstant_JodaDateTime() {
|
||||||
|
assertEquals(INSTANT_WITH_SYS_ZONE, JodaTimeTools.toJavaInstant(JODA_DATE_TIME_WITH_SYS_ZONE));
|
||||||
|
assertEquals(INSTANT, JodaTimeTools.toJavaInstant(JODA_DATE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJavaInstant_JodaLocalDateTimeAndJodaDateTimeZone() {
|
||||||
|
assertEquals(INSTANT_WITH_SYS_ZONE, JodaTimeTools.toJavaInstant(JODA_LOCAL_DATE_TIME, JODA_SYS_ZONE));
|
||||||
|
assertEquals(INSTANT, JodaTimeTools.toJavaInstant(JODA_LOCAL_DATE_TIME, JODA_ZONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion - toJavaInstant
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJodaDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJodaDateTime_ZonedDateTime() {
|
||||||
|
assertEquals(JODA_DATE_TIME_WITH_SYS_ZONE, JodaTimeTools.toJodaDateTime(ZONED_DATE_TIME_WITH_SYS_ZONE));
|
||||||
|
assertEquals(JODA_DATE_TIME, JodaTimeTools.toJodaDateTime(ZONED_DATE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJodaDateTime_LocalDateTimeAndZoneId() {
|
||||||
|
assertEquals(JODA_DATE_TIME_WITH_SYS_ZONE, JodaTimeTools.toJodaDateTime(LOCAL_DATE_TIME, SYS_ZONE_ID));
|
||||||
|
assertEquals(JODA_DATE_TIME, JodaTimeTools.toJodaDateTime(LOCAL_DATE_TIME, ZONE_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJodaDateTime_InstantAndZoneId() {
|
||||||
|
assertEquals(JODA_DATE_TIME_WITH_SYS_ZONE, JodaTimeTools.toJodaDateTime(INSTANT_WITH_SYS_ZONE, SYS_ZONE_ID));
|
||||||
|
assertEquals(JODA_DATE_TIME, JodaTimeTools.toJodaDateTime(INSTANT, ZONE_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion - toJodaDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toZonedDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toZonedDateTime_JodaDateTime() {
|
||||||
|
assertEquals(ZONED_DATE_TIME_WITH_SYS_ZONE, JodaTimeTools.toZonedDateTime(JODA_DATE_TIME_WITH_SYS_ZONE));
|
||||||
|
assertEquals(ZONED_DATE_TIME, JodaTimeTools.toZonedDateTime(JODA_DATE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toZonedDateTime_JodaLocalDateTimeAndJodaDateTimeZone() {
|
||||||
|
assertEquals(ZONED_DATE_TIME_WITH_SYS_ZONE, JodaTimeTools.toZonedDateTime(JODA_LOCAL_DATE_TIME, JODA_SYS_ZONE));
|
||||||
|
assertEquals(ZONED_DATE_TIME, JodaTimeTools.toZonedDateTime(JODA_LOCAL_DATE_TIME, JODA_ZONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toZonedDateTime_JodaInstantAndJodaDateTimeZone() {
|
||||||
|
assertEquals(ZONED_DATE_TIME_WITH_SYS_ZONE, JodaTimeTools.toZonedDateTime(JODA_INSTANT_WITH_SYS_ZONE, JODA_SYS_ZONE));
|
||||||
|
assertEquals(ZONED_DATE_TIME, JodaTimeTools.toZonedDateTime(JODA_INSTANT, JODA_ZONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion - toZonedDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - toJodaLocalDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJodaLocalDateTime_JavaLocalDateTime() {
|
||||||
|
assertEquals(JODA_LOCAL_DATE_TIME, JodaTimeTools.toJodaLocalDateTime(LOCAL_DATE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toJavaLocalDateTime_JodaLocalDateTime() {
|
||||||
|
assertEquals(LOCAL_DATE_TIME, JodaTimeTools.toJavaLocalDateTime(JODA_LOCAL_DATE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion - toJodaLocalDateTime
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #region - ZoneId <--> DateTimeZone
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void convertJavaZoneIdAndJodaDateTimeZone() {
|
||||||
|
assertEquals(SYS_ZONE_ID, JodaTimeTools.toJavaZone(JODA_SYS_ZONE));
|
||||||
|
assertEquals(ZONE_ID, JodaTimeTools.toJavaZone(JODA_ZONE));
|
||||||
|
assertEquals(JODA_SYS_ZONE, JodaTimeTools.toJodaZone(SYS_ZONE_ID));
|
||||||
|
assertEquals(JODA_ZONE, JodaTimeTools.toJodaZone(ZONE_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// #endregion - ZoneId <--> DateTimeZone
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
}
|
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-parent</artifactId>
|
<artifactId>plusone-parent</artifactId>
|
||||||
<version>1.1.0-RC1</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>plusone-dependencies</artifactId>
|
<artifactId>plusone-dependencies</artifactId>
|
||||||
@@ -18,11 +18,6 @@
|
|||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
|
|
||||||
<guava.version>33.4.8-jre</guava.version>
|
<guava.version>33.4.8-jre</guava.version>
|
||||||
<joda-time.version>2.14.0</joda-time.version>
|
<joda-time.version>2.14.0</joda-time.version>
|
||||||
|
|
||||||
@@ -214,7 +209,7 @@
|
|||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
@@ -223,7 +218,7 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-clean-plugin</artifactId>
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.4.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
@@ -231,31 +226,31 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.13.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.0.0</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.4.2</version>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.1.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.1.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
<version>4.0.0-M7</version>
|
<version>3.12.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>3.6.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
|
6
pom.xml
6
pom.xml
@@ -6,9 +6,13 @@
|
|||||||
|
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-parent</artifactId>
|
<artifactId>plusone-parent</artifactId>
|
||||||
<version>1.1.0-RC1</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>plusone-commons</module>
|
<module>plusone-commons</module>
|
||||||
<module>plusone-dependencies</module>
|
<module>plusone-dependencies</module>
|
||||||
|
Reference in New Issue
Block a user