forked from plusone/plusone-validator
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f84051aa6b | |||
| 38ae9bd523 | |||
| 7330e28579 | |||
| d73b8f445d | |||
| ba9ccebb56 | |||
| 821f43d154 | |||
| 4a604a64c4 | |||
| 9aa510820d | |||
| 98a7ed573b | |||
| f3c173818c | |||
| fdabd29347 | |||
| e22a95861d | |||
| edeaec85da |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,6 +4,8 @@ target/
|
|||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
.classpath
|
.classpath
|
||||||
|
|||||||
9
NOTICE
Normal file
9
NOTICE
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Plusone Validator
|
||||||
|
Copyright 2022-present Zhou Xingyi
|
||||||
|
|
||||||
|
This product includes software developed by
|
||||||
|
Zhou Xingyi (周兴毅) (https://gitea.zhouxy.xyz/plusone).
|
||||||
|
|
||||||
|
This product is licensed to you under the Apache License, Version 2.0
|
||||||
|
(the "License"). You may not use this product except in compliance with
|
||||||
|
the License.
|
||||||
157
README.md
157
README.md
@@ -1,16 +1,41 @@
|
|||||||
# Plusone Validator
|
# Plusone Validator
|
||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
Plusone Validator 是一个校验库,使用 lambda 表达式(包括方法引用)和流式 API 构建校验规则,对对象进行校验。
|
|
||||||
|
Plusone Validator 是一个受 [FluentValidation](https://github.com/FluentValidation/FluentValidation) 启发的 Java 校验库,使用 Lambda 表达式(方法引用)和流式 API 构建声明式校验规则。
|
||||||
|
|
||||||
|
**特性:**
|
||||||
|
- 链式调用
|
||||||
|
- 支持 **POJO** 和 **Map** 两种校验模式
|
||||||
|
- 每种校验规则支持四种错误信息提供方式(默认/自定义字符串/自定义异常/含属性值的自定义异常)
|
||||||
|
- 基于 JDK 1.8
|
||||||
|
|
||||||
|
## 环境要求
|
||||||
|
|
||||||
|
- **JDK**:1.8 及以上
|
||||||
|
- **编码**:UTF-8
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
Plusone Validator 暂未提交 maven 中央仓库,可 clone 代码仓库,通过 maven 安装到本地库,然后在项目中引入。
|
|
||||||
|
Plusone Validator 暂未发布至 Maven 中央仓库,需 clone 代码仓库后通过 `mvn install` 安装到本地仓库,然后在项目中引入:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
|
<artifactId>plusone-validator</artifactId>
|
||||||
|
<version>${plusone-validator.version}</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
> 该项目依赖 [plusone-commons](https://gitea.zhouxy.xyz/plusone/plusone-commons),它本身依赖 Guava。
|
||||||
|
|
||||||
## 示例
|
## 示例
|
||||||
|
|
||||||
### 校验对象
|
以下示例基于一个包含姓名、邮箱、会员等级、客户编号、生日、地址等字段的 `Customer` 对象。
|
||||||
|
|
||||||
定义校验器:
|
### 校验 POJO 对象
|
||||||
|
|
||||||
|
继承 `BaseValidator<T>`,在构造器中通过 `ruleFor` 添加规则链:
|
||||||
```java
|
```java
|
||||||
class CustomerValidator extends BaseValidator<Customer> {
|
class CustomerValidator extends BaseValidator<Customer> {
|
||||||
|
|
||||||
@@ -46,7 +71,11 @@ public void foo(Customer customer) {
|
|||||||
|
|
||||||
### 校验 Map
|
### 校验 Map
|
||||||
|
|
||||||
定义校验器:
|
继承 `MapValidator<K,V>`,在构造器中通过 `ruleForString`、`ruleForInt` 等方法按 key 添加规则链。
|
||||||
|
|
||||||
|
`validateAndCopy()` 会**先校验,然后仅保留白名单 key**(构造时传入的 `FIELD_NAMES`),多余字段会被自动剥离,可防止 Map 注入攻击。
|
||||||
|
|
||||||
|
> 注意泛型类型见证语法 `this.<LocalDate>ruleFor(...)` — 当 Map 的 value 类型是 `Object` 时,需显式指定实际类型。
|
||||||
```java
|
```java
|
||||||
class CustomerMapValidator extends MapValidator<String, Object> {
|
class CustomerMapValidator extends MapValidator<String, Object> {
|
||||||
|
|
||||||
@@ -86,10 +115,120 @@ public void foo(Map<String, Object> customer) {
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 快速参考
|
||||||
|
|
||||||
|
### ruleFor 方法一览
|
||||||
|
|
||||||
|
| 方法 | 属性类型 | 适用场景 |
|
||||||
|
|------|---------|---------|
|
||||||
|
| `ruleFor(getter)` | 任意类型 | 通用对象属性校验 |
|
||||||
|
| `ruleForString(getter)` | `String` | 字符串属性校验 |
|
||||||
|
| `ruleForInt(getter)` | `Integer` | 整数属性校验 |
|
||||||
|
| `ruleForLong(getter)` | `Long` | 长整数属性校验 |
|
||||||
|
| `ruleForDouble(getter)` | `Double` | 浮点数属性校验 |
|
||||||
|
| `ruleForBool(getter)` | `Boolean` | 布尔属性校验 |
|
||||||
|
| `ruleForComparable(getter)` | `Comparable` | 可比较类型属性校验 |
|
||||||
|
| `ruleForCollection(getter)` | `Collection<E>` | 集合属性校验 |
|
||||||
|
| `ruleForArray(getter)` | `E[]` | 数组属性校验 |
|
||||||
|
| `ruleFor(g1, g2)` | 二元组 | 两个属性的联合校验 |
|
||||||
|
|
||||||
|
### 校验规则一览
|
||||||
|
|
||||||
|
| 规则 | Object | Comparable | 数值 | String | Bool | 集合/数组 | 说明 |
|
||||||
|
|------|:---:|:---:|:---:|:---:|:---:|:---:|------|
|
||||||
|
| `notNull()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 不为 null |
|
||||||
|
| `isNull()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 必须为 null |
|
||||||
|
| `equal(obj)` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 等于给定值 |
|
||||||
|
| `notEqual(obj)` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 不等于给定值 |
|
||||||
|
| `must(pred)` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 自定义条件 |
|
||||||
|
| `gt/ge/lt/le` | — | — | ✅ | — | — | — | 大于/大于等于/小于/小于等于 |
|
||||||
|
| `inRange(range)` | — | ✅ | ✅ | ✅ | — | — | 值在指定区间内 |
|
||||||
|
| `notBlank()` | — | — | — | ✅ | — | — | 不为空白字符串 |
|
||||||
|
| `notEmpty()` | — | — | — | ✅ | — | ✅ | 不为空(长度 > 0) |
|
||||||
|
| `isEmpty()` | — | — | — | — | — | ✅ | 必须为空 |
|
||||||
|
| `length(min, max)` | — | — | — | ✅ | — | ✅ | 长度/大小在范围内 |
|
||||||
|
| `emailAddress()` | — | — | — | ✅ | — | — | 满足邮箱格式 |
|
||||||
|
| `matches(pattern)` | — | — | — | ✅ | — | — | 匹配正则表达式 |
|
||||||
|
| `matchesAny(patterns)` | — | — | — | ✅ | — | — | 匹配任一正则 |
|
||||||
|
| `matchesAll(patterns)` | — | — | — | ✅ | — | — | 匹配所有正则 |
|
||||||
|
| `allMatch(pred)` | — | — | — | — | — | ✅ | 所有元素满足条件 |
|
||||||
|
| `isTrueValue()` | — | — | — | — | ✅ | — | 必须为 true |
|
||||||
|
| `isFalseValue()` | — | — | — | — | ✅ | — | 必须为 false |
|
||||||
|
|
||||||
|
### 自定义错误信息
|
||||||
|
|
||||||
|
每个校验规则都支持四种错误信息提供方式:
|
||||||
|
|
||||||
|
```java
|
||||||
|
// 1. 默认消息
|
||||||
|
ruleFor(Person::getName).notNull();
|
||||||
|
|
||||||
|
// 2. 自定义字符串
|
||||||
|
ruleFor(Person::getName).notNull("姓名不能为空");
|
||||||
|
|
||||||
|
// 3. 自定义异常(Supplier)
|
||||||
|
ruleFor(Person::getName).notNull(() -> new BizException("姓名不能为空"));
|
||||||
|
|
||||||
|
// 4. 自定义异常 + 属性值注入(Function)
|
||||||
|
ruleFor(Person::getAge).gt(0, age -> new BizException("年龄必须 > 0,当前值:%d", age));
|
||||||
|
```
|
||||||
|
|
||||||
|
### Null 值处理
|
||||||
|
|
||||||
|
多数校验规则对 `null` **宽松处理**(视为通过),让用户通过 `notNull()` 显式控制 null 行为:
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ✅ null 视为通过 — 不会因 NPE 失败
|
||||||
|
ruleFor(Person::getEmail).emailAddress();
|
||||||
|
|
||||||
|
// ✅ 显式拒绝 null
|
||||||
|
ruleFor(Person::getEmail).notNull("邮箱不能为空").emailAddress();
|
||||||
|
```
|
||||||
|
|
||||||
|
例外:`notBlank()` 和 `notEmpty()` 将 `null` 视为不通过(null 本身就是 blank/empty)。
|
||||||
|
|
||||||
|
### 嵌套对象校验
|
||||||
|
|
||||||
|
使用 `withRule(Consumer)` 在子类构造器中调用嵌套校验器:
|
||||||
|
|
||||||
|
```java
|
||||||
|
class OrderValidator extends BaseValidator<Order> {
|
||||||
|
private static final OrderValidator INSTANCE = new OrderValidator();
|
||||||
|
|
||||||
|
private OrderValidator() {
|
||||||
|
ruleFor(Order::getOrderId).notBlank("订单号不能为空");
|
||||||
|
|
||||||
|
// 嵌套校验 Customer
|
||||||
|
withRule(order -> {
|
||||||
|
Customer customer = order.getCustomer();
|
||||||
|
CustomerValidator.getInstance().validate(customer);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 需要自定义错误信息时,try-catch 重新包装
|
||||||
|
withRule(order -> {
|
||||||
|
try {
|
||||||
|
AddressValidator.getInstance().validate(order.getAddress());
|
||||||
|
} catch (ValidationException e) {
|
||||||
|
throw ValidationException.withMessage("地址校验失败:%s", e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 对象整体校验
|
||||||
|
|
||||||
|
使用 `withRule(Predicate)` 对多个属性进行联合校验:
|
||||||
|
|
||||||
|
```java
|
||||||
|
// 三个及以上字段的联合校验
|
||||||
|
withRule(order -> order.getTotalAmount().compareTo(order.getPaidAmount()) >= 0,
|
||||||
|
"订单金额不能小于已付金额");
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 其他
|
## 关于本项目
|
||||||
|
|
||||||
Plusone Validator 是个人在学习 Microsoft 的 [eShop](https://github.com/dotnet/eShop) 时,被其中 [FluentValidation](https://github.com/FluentValidation/FluentValidation) 的 API 所吸引,出于学习和个人使用的目的进行开发和维护。使用 [Apache License 2.0](./LICENSE) 开源。
|
Plusone Validator 受 .NET 的 [FluentValidation](https://github.com/FluentValidation/FluentValidation) API 启发,使用 [Apache License 2.0](./LICENSE) 开源。
|
||||||
|
|
||||||
欢迎通过 issue 反馈使用过程中发现的问题和建议。
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-validator-parent</artifactId>
|
<artifactId>plusone-validator-parent</artifactId>
|
||||||
<version>1.0.0-RC2</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>plusone-validator</artifactId>
|
<artifactId>plusone-validator</artifactId>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -31,7 +31,7 @@ import xyz.zhouxy.plusone.commons.util.AssertTools;
|
|||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @param <E> 数组元素的类型
|
* @param <E> 数组元素的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class ArrayPropertyValidator<T, E>
|
public class ArrayPropertyValidator<T, E>
|
||||||
extends BasePropertyValidator<T, E[], ArrayPropertyValidator<T, E>> {
|
extends BasePropertyValidator<T, E[], ArrayPropertyValidator<T, E>> {
|
||||||
@@ -151,11 +151,17 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当数组为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @return 当前校验器实例,用于链式调用
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> allMatch(final Predicate<E> condition) {
|
public final ArrayPropertyValidator<T, E> allMatch(final Predicate<E> condition) {
|
||||||
return withRule(c -> {
|
return withRule(c -> {
|
||||||
|
if (ArrayTools.isEmpty(c)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (E element : c) {
|
for (E element : c) {
|
||||||
if (!condition.test(element)) {
|
if (!condition.test(element)) {
|
||||||
throw ValidationException.withMessage("All elements must match the condition.");
|
throw ValidationException.withMessage("All elements must match the condition.");
|
||||||
@@ -167,6 +173,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当数组为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 当前校验器实例,用于链式调用
|
* @return 当前校验器实例,用于链式调用
|
||||||
@@ -174,6 +183,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
public final ArrayPropertyValidator<T, E> allMatch(
|
public final ArrayPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final String errorMessage) {
|
final Predicate<E> condition, final String errorMessage) {
|
||||||
return withRule(c -> {
|
return withRule(c -> {
|
||||||
|
if (ArrayTools.isEmpty(c)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (E element : c) {
|
for (E element : c) {
|
||||||
if (!condition.test(element)) {
|
if (!condition.test(element)) {
|
||||||
throw ValidationException.withMessage(errorMessage);
|
throw ValidationException.withMessage(errorMessage);
|
||||||
@@ -185,6 +197,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当数组为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
@@ -193,6 +208,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(c -> {
|
return withRule(c -> {
|
||||||
|
if (ArrayTools.isEmpty(c)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (E element : c) {
|
for (E element : c) {
|
||||||
if (!condition.test(element)) {
|
if (!condition.test(element)) {
|
||||||
throw exceptionSupplier.get();
|
throw exceptionSupplier.get();
|
||||||
@@ -204,6 +222,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当数组为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
@@ -212,6 +233,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
||||||
return withRule(c -> {
|
return withRule(c -> {
|
||||||
|
if (ArrayTools.isEmpty(c)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (E element : c) {
|
for (E element : c) {
|
||||||
if (!condition.test(element)) {
|
if (!condition.test(element)) {
|
||||||
throw exceptionFunction.apply(element);
|
throw exceptionFunction.apply(element);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -29,7 +29,7 @@ import com.google.common.collect.Range;
|
|||||||
* @param <TProperty> 待校验属性的类型,必须实现 {@code Comparable} 接口
|
* @param <TProperty> 待校验属性的类型,必须实现 {@code Comparable} 接口
|
||||||
* @param <TPropertyValidator> 具体校验器类型,用于支持链式调用
|
* @param <TPropertyValidator> 具体校验器类型,用于支持链式调用
|
||||||
* @see Range
|
* @see Range
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public abstract class BaseComparablePropertyValidator<
|
public abstract class BaseComparablePropertyValidator<
|
||||||
T,
|
T,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2024-2025 the original author or authors.
|
* Copyright 2024-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -33,7 +33,7 @@ import java.util.function.Supplier;
|
|||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @param <TProperty> 待校验属性的类型
|
* @param <TProperty> 待校验属性的类型
|
||||||
* @param <TPropertyValidator> 具体校验器类型,用于支持链式调用
|
* @param <TPropertyValidator> 具体校验器类型,用于支持链式调用
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public abstract class BasePropertyValidator<
|
public abstract class BasePropertyValidator<
|
||||||
T,
|
T,
|
||||||
@@ -258,6 +258,9 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
* @return 当前校验器实例,用于链式调用
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
@@ -269,6 +272,9 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 当前校验器实例,用于链式调用
|
* @return 当前校验器实例,用于链式调用
|
||||||
@@ -281,6 +287,9 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
@@ -294,6 +303,9 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
@@ -313,7 +325,10 @@ public abstract class BasePropertyValidator<
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否不等于给定值
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
*
|
*
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
* @return 当前校验器实例,用于链式调用
|
* @return 当前校验器实例,用于链式调用
|
||||||
@@ -324,7 +339,10 @@ public abstract class BasePropertyValidator<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否不等于给定值
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
*
|
*
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
@@ -335,7 +353,10 @@ public abstract class BasePropertyValidator<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否不等于给定值
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
@@ -348,7 +369,10 @@ public abstract class BasePropertyValidator<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否不等于给定值
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 当值为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param obj 用于比较的对象
|
* @param obj 用于比较的对象
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2022-2025 the original author or authors.
|
* Copyright 2022-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,7 +34,7 @@ import xyz.zhouxy.plusone.validator.function.*;
|
|||||||
* 子类可通过添加不同的校验规则,构建完整的校验逻辑,用于校验对象。
|
* 子类可通过添加不同的校验规则,构建完整的校验逻辑,用于校验对象。
|
||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public abstract class BaseValidator<T> implements IValidator<T> {
|
public abstract class BaseValidator<T> implements IValidator<T> {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,7 +27,7 @@ import java.util.function.Supplier;
|
|||||||
* 用于构建校验 {@code Boolean} 类型属性的规则链。
|
* 用于构建校验 {@code Boolean} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class BoolPropertyValidator<T>
|
public class BoolPropertyValidator<T>
|
||||||
extends BasePropertyValidator<T, Boolean, BoolPropertyValidator<T>> {
|
extends BasePropertyValidator<T, Boolean, BoolPropertyValidator<T>> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,7 +32,7 @@ import xyz.zhouxy.plusone.commons.util.AssertTools;
|
|||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @param <E> 集合元素的类型
|
* @param <E> 集合元素的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class CollectionPropertyValidator<T, E>
|
public class CollectionPropertyValidator<T, E>
|
||||||
extends BasePropertyValidator<T, Collection<E>, CollectionPropertyValidator<T, E>> {
|
extends BasePropertyValidator<T, Collection<E>, CollectionPropertyValidator<T, E>> {
|
||||||
@@ -151,36 +151,56 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当集合为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @return 当前校验器实例,用于链式调用
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> allMatch(
|
public final CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition) {
|
final Predicate<E> condition) {
|
||||||
return withRule(c -> c.forEach(element -> {
|
return withRule(c -> {
|
||||||
if (!condition.test(element)) {
|
if (CollectionTools.isEmpty(c)) {
|
||||||
throw ValidationException.withMessage("All elements must match the condition.");
|
return;
|
||||||
}
|
}
|
||||||
}));
|
c.forEach(element -> {
|
||||||
|
if (!condition.test(element)) {
|
||||||
|
throw ValidationException.withMessage("All elements must match the condition.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 当集合为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 当前校验器实例,用于链式调用
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> allMatch(
|
public final CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final String errorMessage) {
|
final Predicate<E> condition, final String errorMessage) {
|
||||||
return withRule(c -> c.forEach(element -> {
|
return withRule(c -> {
|
||||||
if (!condition.test(element)) {
|
if (CollectionTools.isEmpty(c)) {
|
||||||
throw ValidationException.withMessage(errorMessage);
|
return;
|
||||||
}
|
}
|
||||||
}));
|
c.forEach(element -> {
|
||||||
|
if (!condition.test(element)) {
|
||||||
|
throw ValidationException.withMessage(errorMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当集合为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
@@ -188,16 +208,24 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(c -> c.forEach(element -> {
|
return withRule(c -> {
|
||||||
if (!condition.test(element)) {
|
if (CollectionTools.isEmpty(c)) {
|
||||||
throw exceptionSupplier.get();
|
return;
|
||||||
}
|
}
|
||||||
}));
|
c.forEach(element -> {
|
||||||
|
if (!condition.test(element)) {
|
||||||
|
throw exceptionSupplier.get();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 当集合为 {@code null} 时,视为通过。如果需要校验值不为 {@code null},请使用 {@link #notNull()} 方法。
|
||||||
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
@@ -205,11 +233,16 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
||||||
return withRule(c -> c.forEach(element -> {
|
return withRule(c -> {
|
||||||
if (!condition.test(element)) {
|
if (CollectionTools.isEmpty(c)) {
|
||||||
throw exceptionFunction.apply(element);
|
return;
|
||||||
}
|
}
|
||||||
}));
|
c.forEach(element -> {
|
||||||
|
if (!condition.test(element)) {
|
||||||
|
throw exceptionFunction.apply(element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,7 +24,7 @@ import java.util.function.Function;
|
|||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @param <TProperty> 待校验属性的类型,必须实现 {@code Comparable} 接口
|
* @param <TProperty> 待校验属性的类型,必须实现 {@code Comparable} 接口
|
||||||
* @see com.google.common.collect.Range
|
* @see com.google.common.collect.Range
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class ComparablePropertyValidator<T, TProperty extends Comparable<? super TProperty>>
|
public class ComparablePropertyValidator<T, TProperty extends Comparable<? super TProperty>>
|
||||||
extends BaseComparablePropertyValidator<T, TProperty, ComparablePropertyValidator<T, TProperty>> {
|
extends BaseComparablePropertyValidator<T, TProperty, ComparablePropertyValidator<T, TProperty>> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,7 +27,7 @@ import java.util.function.Supplier;
|
|||||||
* 用于构建校验 {@code Double} 类型属性的规则链。
|
* 用于构建校验 {@code Double} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class DoublePropertyValidator<T>
|
public class DoublePropertyValidator<T>
|
||||||
extends BaseComparablePropertyValidator<T, Double, DoublePropertyValidator<T>> {
|
extends BaseComparablePropertyValidator<T, Double, DoublePropertyValidator<T>> {
|
||||||
@@ -48,7 +48,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> gt(final double min) {
|
public final DoublePropertyValidator<T> gt(final double min) {
|
||||||
return withRule(Conditions.greaterThan(min),
|
return withRule(Conditions.greaterThan(min),
|
||||||
"The input must be greater than '%s'.", min);
|
"The input must be greater than '%f'.", min);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +105,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> ge(final double min) {
|
public final DoublePropertyValidator<T> ge(final double min) {
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min),
|
return withRule(Conditions.greaterThanOrEqualTo(min),
|
||||||
"The input must be greater than or equal to '%s'.", min);
|
"The input must be greater than or equal to '%f'.", min);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,7 +162,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> lt(final double max) {
|
public final DoublePropertyValidator<T> lt(final double max) {
|
||||||
return withRule(Conditions.lessThan(max),
|
return withRule(Conditions.lessThan(max),
|
||||||
"The input must be less than '%s'.", max);
|
"The input must be less than '%f'.", max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,7 +219,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> le(final double max) {
|
public final DoublePropertyValidator<T> le(final double max) {
|
||||||
return withRule(Conditions.lessThanOrEqualTo(max),
|
return withRule(Conditions.lessThanOrEqualTo(max),
|
||||||
"The input must be less than or equal to '%s'.", max);
|
"The input must be less than or equal to '%f'.", max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,7 +19,7 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
/**
|
/**
|
||||||
* 自带校验方法,校验不通过时直接抛异常。
|
* 自带校验方法,校验不通过时直接抛异常。
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*
|
*
|
||||||
* @see BaseValidator
|
* @see BaseValidator
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,7 +23,7 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public interface IValidator<T> {
|
public interface IValidator<T> {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,7 +27,7 @@ import java.util.function.Supplier;
|
|||||||
* 用于构建校验 {@code Integer} 类型属性的规则链。
|
* 用于构建校验 {@code Integer} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class IntPropertyValidator<T>
|
public class IntPropertyValidator<T>
|
||||||
extends BaseComparablePropertyValidator<T, Integer, IntPropertyValidator<T>> {
|
extends BaseComparablePropertyValidator<T, Integer, IntPropertyValidator<T>> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,7 +27,7 @@ import java.util.function.Supplier;
|
|||||||
* 用于构建校验 {@code Long} 类型属性的规则链。
|
* 用于构建校验 {@code Long} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class LongPropertyValidator<T>
|
public class LongPropertyValidator<T>
|
||||||
extends BaseComparablePropertyValidator<T, Long, LongPropertyValidator<T>> {
|
extends BaseComparablePropertyValidator<T, Long, LongPropertyValidator<T>> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2024-2025 the original author or authors.
|
* Copyright 2024-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
|||||||
* <p>
|
* <p>
|
||||||
* 校验后拷贝出一个新的 Map 对象,仅保留指定的 key。
|
* 校验后拷贝出一个新的 Map 对象,仅保留指定的 key。
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public abstract class MapValidator<K, V> extends BaseValidator<Map<K, V>> {
|
public abstract class MapValidator<K, V> extends BaseValidator<Map<K, V>> {
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ public abstract class MapValidator<K, V> extends BaseValidator<Map<K, V>> {
|
|||||||
validate(obj);
|
validate(obj);
|
||||||
return obj.entrySet().stream()
|
return obj.entrySet().stream()
|
||||||
.filter(kv -> keys.contains(kv.getKey()))
|
.filter(kv -> keys.contains(kv.getKey()))
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,12 +23,12 @@ import java.util.function.Function;
|
|||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @param <TProperty> 待校验属性的类型
|
* @param <TProperty> 待校验属性的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class ObjectPropertyValidator<T, TProperty>
|
public class ObjectPropertyValidator<T, TProperty>
|
||||||
extends BasePropertyValidator<T, TProperty, ObjectPropertyValidator<T, TProperty>> {
|
extends BasePropertyValidator<T, TProperty, ObjectPropertyValidator<T, TProperty>> {
|
||||||
|
|
||||||
ObjectPropertyValidator(Function<T, TProperty> getter) {
|
ObjectPropertyValidator(Function<T, ? extends TProperty> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,7 +27,7 @@ import java.util.function.Supplier;
|
|||||||
* @param <T> 被验证对象类型
|
* @param <T> 被验证对象类型
|
||||||
* @param <V1> 第一个元素的类型
|
* @param <V1> 第一个元素的类型
|
||||||
* @param <V2> 第二个元素的类型
|
* @param <V2> 第二个元素的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class PairPropertyValidator<T, V1, V2>
|
public class PairPropertyValidator<T, V1, V2>
|
||||||
extends BasePropertyValidator<T, Entry<V1, V2>, PairPropertyValidator<T, V1, V2>> {
|
extends BasePropertyValidator<T, Entry<V1, V2>, PairPropertyValidator<T, V1, V2>> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -35,7 +35,7 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
|
|||||||
* 用于构建校验 {@code String} 类型属性的规则链。
|
* 用于构建校验 {@code String} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
* @param <T> 待校验对象的类型
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class StringPropertyValidator<T>
|
public class StringPropertyValidator<T>
|
||||||
extends BaseComparablePropertyValidator<T, String, StringPropertyValidator<T>> {
|
extends BaseComparablePropertyValidator<T, String, StringPropertyValidator<T>> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,7 +18,7 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
/**
|
/**
|
||||||
* 校验失败异常
|
* 校验失败异常
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class ValidationException extends RuntimeException {
|
public class ValidationException extends RuntimeException {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,7 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Function<T, Boolean>
|
* Function<T, Boolean>
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ToBoolObjectFunction<T> extends Function<T, Boolean>, Serializable {
|
public interface ToBoolObjectFunction<T> extends Function<T, Boolean>, Serializable {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,7 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Function<T, Double>
|
* Function<T, Double>
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ToDoubleObjectFunction<T> extends Function<T, Double>, Serializable {
|
public interface ToDoubleObjectFunction<T> extends Function<T, Double>, Serializable {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,7 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Function<T, Integer>
|
* Function<T, Integer>
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ToIntegerFunction<T> extends Function<T, Integer>, Serializable {
|
public interface ToIntegerFunction<T> extends Function<T, Integer>, Serializable {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,7 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Function<T, Long>
|
* Function<T, Long>
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ToLongObjectFunction<T> extends Function<T, Long>, Serializable {
|
public interface ToLongObjectFunction<T> extends Function<T, Long>, Serializable {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,7 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Function<T, String>
|
* Function<T, String>
|
||||||
*
|
*
|
||||||
* @author ZhouXY108 <luquanlion@outlook.com>
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ToStringFunction<T> extends Function<T, String>, Serializable {
|
public interface ToStringFunction<T> extends Function<T, String>, Serializable {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -293,8 +293,18 @@ public class ArrayPropertyValidatorTests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ExampleCommand command = exampleCommandWithStringArrayProperty(new String[] { "1234", "12345", "123456" });
|
{
|
||||||
assertDoesNotThrow(() -> validator.validate(command));
|
ExampleCommand command = exampleCommandWithStringArrayProperty(new String[] { "1234", "12345", "123456" });
|
||||||
|
assertDoesNotThrow(() -> validator.validate(command));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ExampleCommand command = exampleCommandWithStringArrayProperty(new String[0]);
|
||||||
|
assertDoesNotThrow(() -> validator.validate(command));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ExampleCommand command = exampleCommandWithStringArrayProperty(null);
|
||||||
|
assertDoesNotThrow(() -> validator.validate(command));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -298,8 +298,14 @@ public class CollectionPropertyValidatorTests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ExampleCommand command = exampleCommandWithStringListProperty(Lists.newArrayList("1234", "12345", "123456"));
|
{
|
||||||
assertDoesNotThrow(() -> validator.validate(command));
|
ExampleCommand command = exampleCommandWithStringListProperty(Lists.newArrayList("1234", "12345", "123456"));
|
||||||
|
assertDoesNotThrow(() -> validator.validate(command));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ExampleCommand command = exampleCommandWithStringListProperty(null);
|
||||||
|
assertDoesNotThrow(() -> validator.validate(command));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -87,7 +87,7 @@ public class DoublePropertyValidatorTests {
|
|||||||
|
|
||||||
ValidationException e = assertThrows(
|
ValidationException e = assertThrows(
|
||||||
ValidationException.class, () -> validator.validate(command));
|
ValidationException.class, () -> validator.validate(command));
|
||||||
assertEquals(String.format("The input must be greater than '%s'.", MIN), e.getMessage());
|
assertEquals(String.format("The input must be greater than '%f'.", MIN), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -196,7 +196,7 @@ public class DoublePropertyValidatorTests {
|
|||||||
|
|
||||||
ValidationException e = assertThrows(
|
ValidationException e = assertThrows(
|
||||||
ValidationException.class, () -> validator.validate(command));
|
ValidationException.class, () -> validator.validate(command));
|
||||||
assertEquals(String.format("The input must be greater than or equal to '%s'.", MIN), e.getMessage());
|
assertEquals(String.format("The input must be greater than or equal to '%f'.", MIN), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -305,7 +305,7 @@ public class DoublePropertyValidatorTests {
|
|||||||
|
|
||||||
ValidationException e = assertThrows(
|
ValidationException e = assertThrows(
|
||||||
ValidationException.class, () -> validator.validate(command));
|
ValidationException.class, () -> validator.validate(command));
|
||||||
assertEquals(String.format("The input must be less than '%s'.", MAX), e.getMessage());
|
assertEquals(String.format("The input must be less than '%f'.", MAX), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -414,7 +414,7 @@ public class DoublePropertyValidatorTests {
|
|||||||
|
|
||||||
ValidationException e = assertThrows(
|
ValidationException e = assertThrows(
|
||||||
ValidationException.class, () -> validator.validate(command));
|
ValidationException.class, () -> validator.validate(command));
|
||||||
assertEquals(String.format("The input must be less than or equal to '%s'.", MAX), e.getMessage());
|
assertEquals(String.format("The input must be less than or equal to '%f'.", MAX), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2025 the original author or authors.
|
* Copyright 2025-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2024-2025 the original author or authors.
|
* Copyright 2024-present ZhouXY
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025-present ZhouXY
|
||||||
|
*
|
||||||
|
* 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.validator;
|
package xyz.zhouxy.plusone.validator;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|||||||
134
pom.xml
134
pom.xml
@@ -6,10 +6,10 @@
|
|||||||
|
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-validator-parent</artifactId>
|
<artifactId>plusone-validator-parent</artifactId>
|
||||||
<version>1.0.0-RC2</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>plusone-validator-parent</name>
|
<name>plusone-validator-parent</name>
|
||||||
<url>http://gitea.zhouxy.xyz/plusone/plusone-validator</url>
|
<url>https://gitea.zhouxy.xyz/plusone/plusone-validator</url>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
@@ -21,12 +21,33 @@
|
|||||||
Plusone Validator 是一个校验库,使用 lambda 表达式(包括方法引用)和流式 API 构建校验规则,对对象进行校验。
|
Plusone Validator 是一个校验库,使用 lambda 表达式(包括方法引用)和流式 API 构建校验规则,对对象进行校验。
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<name>Zhou Xingyi (周兴毅)</name>
|
||||||
|
<url>https://gitea.zhouxy.xyz/plusone</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://gitea.zhouxy.xyz/plusone/plusone-validator.git</connection>
|
||||||
|
<developerConnection>scm:git:ssh://gitea.zhouxy.xyz/plusone/plusone-validator.git</developerConnection>
|
||||||
|
<url>https://gitea.zhouxy.xyz/plusone/plusone-validator</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
|
||||||
<plusone-commons.version>1.1.0-RC1</plusone-commons.version>
|
<plusone-commons.version>1.1.0-RC2</plusone-commons.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -47,49 +68,68 @@
|
|||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
<plugins>
|
||||||
<pluginManagement>
|
<!-- Flatten 插件:生成包含继承信息的完整 POM 用于发布 -->
|
||||||
<plugins>
|
<plugin>
|
||||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<plugin>
|
<artifactId>flatten-maven-plugin</artifactId>
|
||||||
<artifactId>maven-clean-plugin</artifactId>
|
<version>1.6.0</version>
|
||||||
<version>3.1.0</version>
|
<configuration>
|
||||||
</plugin>
|
<!-- 核心配置:oss 模式专为 Sonatype/Maven Central 设计 -->
|
||||||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
<!-- 它会保留 url, licenses, developers, scm, properties 等必要元素 -->
|
||||||
<plugin>
|
<flattenMode>oss</flattenMode>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
</configuration>
|
||||||
<version>3.0.2</version>
|
<executions>
|
||||||
</plugin>
|
<!-- 在 process-resources 阶段生成展平的 POM -->
|
||||||
<plugin>
|
<execution>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<id>flatten</id>
|
||||||
<version>3.8.0</version>
|
<phase>process-resources</phase>
|
||||||
</plugin>
|
<goals>
|
||||||
<plugin>
|
<goal>flatten</goal>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
</goals>
|
||||||
<version>2.22.1</version>
|
</execution>
|
||||||
</plugin>
|
<!-- 在 clean 阶段删除展平的 POM -->
|
||||||
<plugin>
|
<execution>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<id>flatten.clean</id>
|
||||||
<version>3.0.2</version>
|
<phase>clean</phase>
|
||||||
</plugin>
|
<goals>
|
||||||
<plugin>
|
<goal>clean</goal>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
</goals>
|
||||||
<version>2.5.2</version>
|
</execution>
|
||||||
</plugin>
|
</executions>
|
||||||
<plugin>
|
</plugin>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
</plugins>
|
||||||
<version>2.8.2</version>
|
|
||||||
</plugin>
|
|
||||||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
|
||||||
<version>3.7.1</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</pluginManagement>
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>release</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- GPG -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>sign-artifacts</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>sign</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonatype.central</groupId>
|
||||||
|
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<publishingServerId>central</publishingServerId>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
Reference in New Issue
Block a user