generated from mingliqiye/lib-tem
Compare commits
No commits in common. "3f666d652dd07f1bda8301dafc22912fc1452854" and "2063d86097b7d8b4d2199fcda81b3bc24c2572d8" have entirely different histories.
3f666d652d
...
2063d86097
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2026 mingliqiye
|
* Copyright 2025 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 2026-01-09 08:12:01
|
* LastUpdate 2025-09-15 09:56:54
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -85,11 +85,6 @@ 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
|
||||||
|
|||||||
@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user