Compare commits

...

14 Commits

Author SHA1 Message Date
3f666d652d
feat(utils): 添加函数式接口和条件验证工具类
- 添加 RFunction 函数式接口用于无参数函数调用
- 更新文件头版权年份从 2025 到 2026
- 更新文件最后修改时间戳
- 新增 Require 类提供条件验证功能
- 支持多种构造方式包括布尔值、函数式参数等
- 提供多种异常抛出机制包括自定义异常类型
- 添加扩展函数和静态工厂方法简化使用
- 支持 Java 互操作性的 JvmStatic 注解
2026-01-10 08:54:17 +08:00
00c1be6387
Merge branch 'master' of git.mingliqiye.com:minglipro/mingli-utils 2026-01-08 13:21:38 +08:00
1509597032
Merge pull request 'dev' (#12) from dev into master
Reviewed-on: #12
2025-09-21 15:41:49 +08:00
9002f41c63
Merge pull request 'dev' (#11) from dev into master
Reviewed-on: #11
2025-09-17 21:20:20 +08:00
8f8ffc72db
Merge pull request 'feat(build): 重构项目并添加 Maven 发布支持' (#10) from dev into master
Some checks failed
Gitea Actions Build / Build (push) Failing after 2s
Reviewed-on: #10
2025-09-17 11:12:41 +08:00
0450e87c13
Merge pull request 'dev' (#9) from dev into master
All checks were successful
Gitea Actions Build / Build (push) Successful in 3m11s
Reviewed-on: #9
2025-09-15 22:33:56 +08:00
e4bb9884c1
Merge pull request 'refactor(stream): 重构流处理相关代码' (#8) from dev into master
All checks were successful
Gitea Actions Build / Build (push) Successful in 2m21s
Reviewed-on: #8
2025-09-15 17:27:10 +08:00
0b1aac8ecc
Merge pull request 'refactor(mybatis): 更新类型处理器以支持 JDBC 类型参数为 null' (#7) from dev into master
All checks were successful
Gitea Actions Build / Build (push) Successful in 2m25s
Reviewed-on: #7
2025-09-15 13:55:22 +08:00
3d1f249970
Merge pull request 'dev' (#6) from dev into master
Some checks failed
Gitea Actions Build / Build (push) Failing after 2m14s
Reviewed-on: #6
2025-09-15 12:46:12 +08:00
d6517287d1
Merge pull request 'feat(utils): 添加 foreach 扩展函数并更新项目版本' (#5) from dev into master
All checks were successful
Gitea Actions Build / Build (push) Successful in 2m4s
Reviewed-on: #5
2025-09-15 12:01:58 +08:00
533ba9bed7
Merge pull request 'refactor(time): 重构 DateTime 类并添加新功能' (#4) from dev into master
Some checks failed
Gitea Actions Build / Build (push) Failing after 1m54s
Reviewed-on: #4
2025-09-15 11:33:46 +08:00
092947d81a
Merge pull request 'refactor(time): 重构 DateTime 类并添加新功能' (#3) from dev into master
Some checks failed
Gitea Actions Build / Build (push) Failing after 2m30s
Reviewed-on: #3
2025-09-15 11:20:38 +08:00
6a7d73091e
Merge pull request 'refactor(mingli-utils):重构集合工具类并添加新功能' (#2) from dev into master
All checks were successful
Gitea Actions Build / Build (push) Successful in 2m4s
Reviewed-on: #2
2025-09-15 09:32:42 +08:00
67a1256682
Merge pull request 'refactor(kotlin): 重构 AES 工具类并优化 Base64 编解码方法' (#1) from dev into master
All checks were successful
Gitea Actions Build / Build (push) Successful in 4m11s
Reviewed-on: #1
2025-09-14 22:13:10 +08:00
2 changed files with 133 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2025 mingliqiye * Copyright 2026 mingliqiye
* *
* 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.
@ -16,7 +16,7 @@
* ProjectName mingli-utils * ProjectName mingli-utils
* ModuleName mingli-utils.main * ModuleName mingli-utils.main
* CurrentFile Functions.kt * CurrentFile Functions.kt
* LastUpdate 2025-09-15 09:56:54 * LastUpdate 2026-01-09 08:12:01
* UpdateUser MingLiPro * UpdateUser MingLiPro
*/ */
@ -85,6 +85,11 @@ fun interface P1Function<P> {
fun call(p: P) fun call(p: P)
} }
@FunctionalInterface
fun interface RFunction<R> {
fun call(): R
}
@FunctionalInterface @FunctionalInterface
fun interface P1RFunction<P, R> { fun interface P1RFunction<P, R> {
fun call(p: P): R fun call(p: P): R

View File

@ -0,0 +1,126 @@
/*
* Copyright 2026 mingliqiye
*
* 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
*
* http://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.
*
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile Require.kt
* LastUpdate 2026-01-10 08:53:26
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.request
import com.mingliqiye.utils.functions.P1RFunction
import com.mingliqiye.utils.functions.RFunction
class Require(private val must: Boolean) {
constructor(funs: RFunction<Boolean>) : this(funs.call())
constructor(must: RFunction<Boolean>, message: String) : this(must) {
throws(message)
}
constructor(
must: RFunction<Boolean>,
message: String,
exception: Class<out Exception> = IllegalArgumentException::class.java
) : this(must) {
throws(message, exception)
}
constructor(must: Boolean, message: String) : this(must) {
throws(message)
}
constructor(
must: Boolean, message: String, exception: Class<out Exception> = IllegalArgumentException::class.java
) : this(must) {
throws(message, exception)
}
constructor(
must: Boolean, message: String, exception: P1RFunction<String, out Exception>
) : this(must) {
throws(message, exception)
}
companion object {
fun Boolean.require(message: String, exception: P1RFunction<String, out Exception>): Require {
return Require(this, message, exception)
}
fun Boolean.require(
message: String,
exception: Class<out Exception> = IllegalArgumentException::class.java
): Require {
return Require(this, message, exception)
}
@JvmStatic
fun require(
must: Boolean, message: String, exception: Class<out Exception> = IllegalArgumentException::class.java
): Require {
return Require(must, message, exception)
}
@JvmStatic
fun require(must: Boolean, message: String): Require {
return Require(must, message)
}
@JvmStatic
fun require(must: Boolean): Require {
return Require(must)
}
@JvmStatic
fun require(
must: RFunction<Boolean>,
message: String,
exception: Class<out Exception> = IllegalArgumentException::class.java
): Require {
return Require(must, message, exception)
}
@JvmStatic
fun require(must: RFunction<Boolean>, message: String): Require {
return Require(must, message)
}
@JvmStatic
fun require(must: RFunction<Boolean>): Require {
return Require(must)
}
}
fun throws(message: String) {
if (!must) {
throw IllegalArgumentException(message)
}
}
fun throws(string: String, exception: Class<out Exception>) {
if (!must) {
throw exception.getConstructor(String::class.java).newInstance(string)
}
}
fun throws(string: String, exception: P1RFunction<String, out Exception>) {
if (!must) {
throw exception.call(string)
}
}
}