style: 全项目统一 Tab 缩进并补全尾随逗号
This commit is contained in:
@@ -37,5 +37,5 @@ import kotlin.reflect.KClass
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class AutoService(
|
||||
val value: Array<KClass<*>> = []
|
||||
val value: Array<KClass<*>> = [],
|
||||
)
|
||||
|
||||
@@ -34,5 +34,5 @@ import com.mingliqiye.utils.uuid.UUIDFormatType
|
||||
@Target(AnnotationTarget.FIELD)
|
||||
annotation class UUIDJsonFormat(
|
||||
val value: UUIDFormatType = UUIDFormatType.NO_UPPER_SPACE,
|
||||
val base: BaseType = BaseType.BASE16
|
||||
val base: BaseType = BaseType.BASE16,
|
||||
)
|
||||
|
||||
@@ -158,7 +158,7 @@ inline fun <reified T> Array<T>.getLast(): T? {
|
||||
* @return 指定索引处的元素或默认值
|
||||
*/
|
||||
inline fun <reified T> Collection<T>.getOrDefault(
|
||||
index: Int, defaultValue: T
|
||||
index: Int, defaultValue: T,
|
||||
): T {
|
||||
if (!(!this.isEmpty() && index < this.size)) {
|
||||
return defaultValue
|
||||
|
||||
@@ -143,4 +143,3 @@ private fun getAllFields(clazz: Class<*>): List<Field> {
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.mingliqiye.utils.functions.*
|
||||
* @param <T> 可迭代对象中元素的类型
|
||||
*/
|
||||
fun <T> forEach(
|
||||
iterable: Iterable<T>, action: P2Function<in T, in Int>
|
||||
iterable: Iterable<T>, action: P2Function<in T, in Int>,
|
||||
) {
|
||||
when (iterable) {
|
||||
is RandomAccess if iterable is MutableList<*> -> {
|
||||
@@ -74,7 +74,7 @@ fun <T> forEach(
|
||||
* @param <T> 可迭代对象中元素的类型
|
||||
*/
|
||||
fun <T> forEach(
|
||||
iterable: Iterable<T>, action: P1Function<in T>
|
||||
iterable: Iterable<T>, action: P1Function<in T>,
|
||||
) {
|
||||
if (iterable is RandomAccess) {
|
||||
// 如果是支持随机访问的列表,则使用索引遍历以提高性能
|
||||
@@ -100,7 +100,7 @@ fun <T> forEach(
|
||||
* @param <T> 可迭代对象中元素的类型
|
||||
*/
|
||||
fun <T> forEachB(
|
||||
iterable: Iterable<T>, action: P2RFunction<in T, in Int, out Boolean>
|
||||
iterable: Iterable<T>, action: P2RFunction<in T, in Int, out Boolean>,
|
||||
) {
|
||||
when (iterable) {
|
||||
is RandomAccess if iterable is MutableList<*> -> {
|
||||
@@ -142,7 +142,7 @@ fun <T> forEachB(
|
||||
* @param <T> 可迭代对象中元素的类型
|
||||
*/
|
||||
fun <T> forEachB(
|
||||
iterable: Iterable<T>, action: P1RFunction<in T, out Boolean>
|
||||
iterable: Iterable<T>, action: P1RFunction<in T, out Boolean>,
|
||||
) {
|
||||
if (iterable is RandomAccess) {
|
||||
// 如果是支持随机访问的列表,则使用索引遍历以提高性能
|
||||
@@ -166,7 +166,7 @@ fun <T> forEachB(
|
||||
* @param <T> 数组中元素的类型
|
||||
*/
|
||||
fun <T> forEach(
|
||||
array: Array<T>, action: P2Function<in T, in Int>
|
||||
array: Array<T>, action: P2Function<in T, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -179,7 +179,7 @@ fun <T> forEach(
|
||||
* @param <T> 数组中元素的类型
|
||||
*/
|
||||
fun <T> forEach(
|
||||
array: Array<T>, action: P1Function<in T>
|
||||
array: Array<T>, action: P1Function<in T>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -193,7 +193,7 @@ fun <T> forEach(
|
||||
* @param <T> 数组中元素的类型
|
||||
*/
|
||||
fun <T> forEachB(
|
||||
array: Array<T>, action: P2RFunction<in T, in Int, out Boolean>
|
||||
array: Array<T>, action: P2RFunction<in T, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -207,7 +207,7 @@ fun <T> forEachB(
|
||||
* @param <T> 数组中元素的类型
|
||||
*/
|
||||
fun <T> forEachB(
|
||||
array: Array<T>, action: P1RFunction<in T, out Boolean>
|
||||
array: Array<T>, action: P1RFunction<in T, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -219,7 +219,7 @@ fun <T> forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: ByteArray, action: P2Function<in Byte, in Int>
|
||||
array: ByteArray, action: P2Function<in Byte, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -231,7 +231,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: ByteArray, action: P1Function<in Byte>
|
||||
array: ByteArray, action: P1Function<in Byte>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -244,7 +244,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: ByteArray, action: P2RFunction<in Byte, in Int, out Boolean>
|
||||
array: ByteArray, action: P2RFunction<in Byte, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -257,7 +257,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: ByteArray, action: P1RFunction<in Byte, out Boolean>
|
||||
array: ByteArray, action: P1RFunction<in Byte, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -269,7 +269,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: CharArray, action: P2Function<in Char, in Int>
|
||||
array: CharArray, action: P2Function<in Char, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -281,7 +281,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: CharArray, action: P1Function<in Char>
|
||||
array: CharArray, action: P1Function<in Char>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -294,7 +294,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: CharArray, action: P2RFunction<in Char, in Int, out Boolean>
|
||||
array: CharArray, action: P2RFunction<in Char, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -307,7 +307,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: CharArray, action: P1RFunction<in Char, out Boolean>
|
||||
array: CharArray, action: P1RFunction<in Char, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -319,7 +319,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: IntArray, action: P2Function<in Int, in Int>
|
||||
array: IntArray, action: P2Function<in Int, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -331,7 +331,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: IntArray, action: P1Function<in Int>
|
||||
array: IntArray, action: P1Function<in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -344,7 +344,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: IntArray, action: P2RFunction<in Int, in Int, out Boolean>
|
||||
array: IntArray, action: P2RFunction<in Int, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -357,7 +357,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: IntArray, action: P1RFunction<in Int, out Boolean>
|
||||
array: IntArray, action: P1RFunction<in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -369,7 +369,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: LongArray, action: P2Function<in Long, in Int>
|
||||
array: LongArray, action: P2Function<in Long, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -381,7 +381,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: LongArray, action: P1Function<in Long>
|
||||
array: LongArray, action: P1Function<in Long>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -394,7 +394,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: LongArray, action: P2RFunction<in Long, in Int, out Boolean>
|
||||
array: LongArray, action: P2RFunction<in Long, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -407,7 +407,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: LongArray, action: P1RFunction<in Long, out Boolean>
|
||||
array: LongArray, action: P1RFunction<in Long, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -419,7 +419,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: ShortArray, action: P2Function<in Short, in Int>
|
||||
array: ShortArray, action: P2Function<in Short, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -431,7 +431,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: ShortArray, action: P1Function<in Short>
|
||||
array: ShortArray, action: P1Function<in Short>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -444,7 +444,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: ShortArray, action: P2RFunction<in Short, in Int, out Boolean>
|
||||
array: ShortArray, action: P2RFunction<in Short, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -457,7 +457,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: ShortArray, action: P1RFunction<in Short, out Boolean>
|
||||
array: ShortArray, action: P1RFunction<in Short, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -469,7 +469,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: FloatArray, action: P2Function<in Float, in Int>
|
||||
array: FloatArray, action: P2Function<in Float, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -481,7 +481,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: FloatArray, action: P1Function<in Float>
|
||||
array: FloatArray, action: P1Function<in Float>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -494,7 +494,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: FloatArray, action: P2RFunction<in Float, in Int, out Boolean>
|
||||
array: FloatArray, action: P2RFunction<in Float, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -507,7 +507,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: FloatArray, action: P1RFunction<in Float, out Boolean>
|
||||
array: FloatArray, action: P1RFunction<in Float, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -519,7 +519,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: DoubleArray, action: P2Function<in Double, in Int>
|
||||
array: DoubleArray, action: P2Function<in Double, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -531,7 +531,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: DoubleArray, action: P1Function<in Double>
|
||||
array: DoubleArray, action: P1Function<in Double>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -544,7 +544,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: DoubleArray, action: P2RFunction<in Double, in Int, out Boolean>
|
||||
array: DoubleArray, action: P2RFunction<in Double, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -557,7 +557,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: DoubleArray, action: P1RFunction<in Double, out Boolean>
|
||||
array: DoubleArray, action: P1RFunction<in Double, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -569,7 +569,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: BooleanArray, action: P2Function<in Boolean, in Int>
|
||||
array: BooleanArray, action: P2Function<in Boolean, in Int>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -581,7 +581,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数
|
||||
*/
|
||||
fun forEach(
|
||||
array: BooleanArray, action: P1Function<in Boolean>
|
||||
array: BooleanArray, action: P1Function<in Boolean>,
|
||||
) {
|
||||
forEach(array.toList(), action)
|
||||
}
|
||||
@@ -594,7 +594,7 @@ fun forEach(
|
||||
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: BooleanArray, action: P2RFunction<in Boolean, in Int, out Boolean>
|
||||
array: BooleanArray, action: P2RFunction<in Boolean, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -607,7 +607,7 @@ fun forEachB(
|
||||
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
|
||||
*/
|
||||
fun forEachB(
|
||||
array: BooleanArray, action: P1RFunction<in Boolean, out Boolean>
|
||||
array: BooleanArray, action: P1RFunction<in Boolean, out Boolean>,
|
||||
) {
|
||||
forEachB(array.toList(), action)
|
||||
}
|
||||
@@ -623,7 +623,7 @@ fun forEachB(
|
||||
* @param <A> 集合的具体类型
|
||||
*/
|
||||
fun <K, V, A : Collection<Map.Entry<K, V>>> forEachB(
|
||||
array: A, action: P3RFunction<in K, in V, in Int, out Boolean>
|
||||
array: A, action: P3RFunction<in K, in V, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(array, P2RFunction<Map.Entry<K, V>, Int, Boolean> { p1, p2 -> action.call(p1.key, p1.value, p2) })
|
||||
}
|
||||
@@ -639,7 +639,7 @@ fun <K, V, A : Collection<Map.Entry<K, V>>> forEachB(
|
||||
* @param <A> 映射的具体类型
|
||||
*/
|
||||
fun <K, V, A : Map<K, V>> forEachB(
|
||||
map: A, action: P3RFunction<in K, in V, in Int, out Boolean>
|
||||
map: A, action: P3RFunction<in K, in V, in Int, out Boolean>,
|
||||
) {
|
||||
forEachB(map.entries, P2RFunction<Map.Entry<K, V>, Int, Boolean> { p1, p2 -> action.call(p1.key, p1.value, p2) })
|
||||
}
|
||||
@@ -654,7 +654,7 @@ fun <K, V, A : Map<K, V>> forEachB(
|
||||
* @param <A> 集合的具体类型
|
||||
*/
|
||||
fun <K, V, A : Collection<Map.Entry<K, V>>> forEachMap(
|
||||
array: A, action: P2Function<in K, in V>
|
||||
array: A, action: P2Function<in K, in V>,
|
||||
) {
|
||||
forEach(array, P1Function<Map.Entry<K, V>> { p1 -> action.call(p1.key, p1.value) })
|
||||
}
|
||||
@@ -669,7 +669,7 @@ fun <K, V, A : Collection<Map.Entry<K, V>>> forEachMap(
|
||||
* @param <A> 映射的具体类型
|
||||
*/
|
||||
fun <K, V, A : Map<K, V>> forEachMap(
|
||||
map: A, action: P2Function<in K, in V>
|
||||
map: A, action: P2Function<in K, in V>,
|
||||
) {
|
||||
forEach(map.entries, P1Function<Map.Entry<K, V>> { p1 -> action.call(p1.key, p1.value) })
|
||||
}
|
||||
@@ -685,7 +685,7 @@ fun <K, V, A : Map<K, V>> forEachMap(
|
||||
* @param <A> 集合的具体类型
|
||||
*/
|
||||
fun <K, V, A : Collection<Map.Entry<K, V>>> forEachMapB(
|
||||
array: A, action: P2RFunction<in K, in V, out Boolean>
|
||||
array: A, action: P2RFunction<in K, in V, out Boolean>,
|
||||
) {
|
||||
forEachB(array, P1RFunction<Map.Entry<K, V>, Boolean> { p1 -> action.call(p1.key, p1.value) })
|
||||
}
|
||||
@@ -701,7 +701,7 @@ fun <K, V, A : Collection<Map.Entry<K, V>>> forEachMapB(
|
||||
* @param <A> 映射的具体类型
|
||||
*/
|
||||
fun <K, V, A : Map<K, V>> forEachMapB(
|
||||
map: A, action: P2RFunction<in K, in V, out Boolean>
|
||||
map: A, action: P2RFunction<in K, in V, out Boolean>,
|
||||
) {
|
||||
forEachB(map.entries, P1RFunction<Map.Entry<K, V>, Boolean> { p1 -> action.call(p1.key, p1.value) })
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ fun interface P13RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p9: P9,
|
||||
p10: P10,
|
||||
p11: P11,
|
||||
p12: P12
|
||||
p12: P12,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ fun interface P14Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p10: P10,
|
||||
p11: P11,
|
||||
p12: P12,
|
||||
p13: P13
|
||||
p13: P13,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ fun interface P14RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p10: P10,
|
||||
p11: P11,
|
||||
p12: P12,
|
||||
p13: P13
|
||||
p13: P13,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ fun interface P15Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p11: P11,
|
||||
p12: P12,
|
||||
p13: P13,
|
||||
p14: P14
|
||||
p14: P14,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ fun interface P15RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p11: P11,
|
||||
p12: P12,
|
||||
p13: P13,
|
||||
p14: P14
|
||||
p14: P14,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ fun interface P16Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p12: P12,
|
||||
p13: P13,
|
||||
p14: P14,
|
||||
p15: P15
|
||||
p15: P15,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ fun interface P16RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p12: P12,
|
||||
p13: P13,
|
||||
p14: P14,
|
||||
p15: P15
|
||||
p15: P15,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ fun interface P17Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p13: P13,
|
||||
p14: P14,
|
||||
p15: P15,
|
||||
p16: P16
|
||||
p16: P16,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ fun interface P17RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p13: P13,
|
||||
p14: P14,
|
||||
p15: P15,
|
||||
p16: P16
|
||||
p16: P16,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ fun interface P18Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p14: P14,
|
||||
p15: P15,
|
||||
p16: P16,
|
||||
p17: P17
|
||||
p17: P17,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ fun interface P18RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p14: P14,
|
||||
p15: P15,
|
||||
p16: P16,
|
||||
p17: P17
|
||||
p17: P17,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -427,7 +427,7 @@ fun interface P19Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p15: P15,
|
||||
p16: P16,
|
||||
p17: P17,
|
||||
p18: P18
|
||||
p18: P18,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ fun interface P19RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p15: P15,
|
||||
p16: P16,
|
||||
p17: P17,
|
||||
p18: P18
|
||||
p18: P18,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -478,7 +478,7 @@ fun interface P20Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p16: P16,
|
||||
p17: P17,
|
||||
p18: P18,
|
||||
p19: P19
|
||||
p19: P19,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ fun interface P20RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p16: P16,
|
||||
p17: P17,
|
||||
p18: P18,
|
||||
p19: P19
|
||||
p19: P19,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -531,7 +531,7 @@ fun interface P21Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p17: P17,
|
||||
p18: P18,
|
||||
p19: P19,
|
||||
p20: P20
|
||||
p20: P20,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ fun interface P21RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p17: P17,
|
||||
p18: P18,
|
||||
p19: P19,
|
||||
p20: P20
|
||||
p20: P20,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -586,7 +586,7 @@ fun interface P22Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p18: P18,
|
||||
p19: P19,
|
||||
p20: P20,
|
||||
p21: P21
|
||||
p21: P21,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -614,7 +614,7 @@ fun interface P22RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p18: P18,
|
||||
p19: P19,
|
||||
p20: P20,
|
||||
p21: P21
|
||||
p21: P21,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -643,7 +643,7 @@ fun interface P23Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p19: P19,
|
||||
p20: P20,
|
||||
p21: P21,
|
||||
p22: P22
|
||||
p22: P22,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -672,7 +672,7 @@ fun interface P23RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p19: P19,
|
||||
p20: P20,
|
||||
p21: P21,
|
||||
p22: P22
|
||||
p22: P22,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -702,7 +702,7 @@ fun interface P24Function<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p20: P20,
|
||||
p21: P21,
|
||||
p22: P22,
|
||||
p23: P23
|
||||
p23: P23,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -732,6 +732,6 @@ fun interface P24RFunction<P, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12,
|
||||
p20: P20,
|
||||
p21: P21,
|
||||
p22: P22,
|
||||
p23: P23
|
||||
p23: P23,
|
||||
): R
|
||||
}
|
||||
|
||||
@@ -16,45 +16,285 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile OkHttpUtils.kt
|
||||
* LastUpdate 2026-10-22 20:20:42
|
||||
* LastUpdate 2026-11-07 13:44:21
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
@file:JvmName("OkHttpUtils")
|
||||
|
||||
package com.mingliqiye.utils.http.okhttp
|
||||
|
||||
import com.mingliqiye.utils.http.MediaType
|
||||
import com.mingliqiye.utils.http.okhttp
|
||||
import com.mingliqiye.utils.json.api.JSONA
|
||||
import com.mingliqiye.utils.json.api.base.JsonApi
|
||||
import com.mingliqiye.utils.json.api.base.JsonApi.Companion.parse
|
||||
import okhttp3.Call
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
|
||||
import okhttp3.*
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
|
||||
/**
|
||||
* 将 OkHttp 的 [Response] 响应体解析为指定泛型类型的对象。
|
||||
*
|
||||
* 会读取并关闭响应体。未显式传入 [jsonApi] 时使用 [JSONA.jsonApi]。
|
||||
*
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 解析后的对象实例
|
||||
* @throws NullPointerException 未传入 [jsonApi] 且 [JSONA] 尚未注入实例时抛出
|
||||
*/
|
||||
inline fun <reified T> Response.json(jsonApi: JsonApi? = null): T = body.use {
|
||||
if (jsonApi != null) {
|
||||
return jsonApi.parse<T>(it.bytes())
|
||||
} else {
|
||||
JSONA.parse<T>(it.bytes())
|
||||
}
|
||||
(jsonApi ?: JSONA.jsonApi).parse<T>(it.bytes())
|
||||
}
|
||||
|
||||
fun Response.text() = body.use {
|
||||
String(it.bytes())
|
||||
}
|
||||
/**
|
||||
* 读取 [Response] 响应体为字符串,并关闭响应体。
|
||||
*
|
||||
* 按响应 `Content-Type` 的 `charset` 解码,缺省 UTF-8;读取后响应体被关闭。
|
||||
*
|
||||
* @return 响应体内容字符串
|
||||
*/
|
||||
fun Response.text() = this.body.string()
|
||||
|
||||
/**
|
||||
* 创建一个 [Request],通过 [calld] 配置 [Request.Builder]。
|
||||
*
|
||||
* @param calld 在 [Request.Builder] 上执行的配置块
|
||||
* @return 构建完成的 [Request]
|
||||
*/
|
||||
fun newRequest(calld: Request.Builder.() -> Unit): Request =
|
||||
Request.Builder().apply(calld).build()
|
||||
|
||||
fun newRequest(calld: Request.Builder.() -> Unit): Request {
|
||||
val request = Request.Builder()
|
||||
calld(request)
|
||||
return request.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用当前 [OkHttpClient] 创建一个 [Call],请求通过 [calld] 配置。
|
||||
*
|
||||
* 调用返回的 [Call] 的 `execute()` 或 `enqueue()` 才会真正发起请求。
|
||||
*
|
||||
* @param calld 在 [Request.Builder] 上执行的配置块
|
||||
* @return 未执行的 [Call]
|
||||
*/
|
||||
fun OkHttpClient.newCall(calld: Request.Builder.() -> Unit): Call {
|
||||
return this.newCall(newRequest(calld))
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用当前 [OkHttpClient] 同步执行一次请求,请求通过 [calld] 配置。
|
||||
*
|
||||
* 注意:在 Android 主线程调用会抛出 `NetworkOnMainThreadException`。
|
||||
*
|
||||
* @param calld 在 [Request.Builder] 上执行的配置块
|
||||
* @return 同步执行得到的 [Response]
|
||||
* @throws java.io.IOException 网络或 I/O 失败时抛出
|
||||
*/
|
||||
fun OkHttpClient.newExecute(calld: Request.Builder.() -> Unit): Response {
|
||||
return this.newCall(newRequest(calld)).execute()
|
||||
}
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 URL,并通过 [calld] 配置查询参数。
|
||||
*
|
||||
* 示例:
|
||||
* ```
|
||||
* Request.Builder().url("https://example.com/api") {
|
||||
* addQueryParameter("page", "1")
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @param url 基础 URL 字符串
|
||||
* @param calld 可选的 [HttpUrl.Builder] 配置块(如添加查询参数);为 `null` 时直接使用 [url]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.url(
|
||||
url: String,
|
||||
calld: (HttpUrl.Builder.() -> Unit)? = null,
|
||||
): Request.Builder {
|
||||
return if (calld != null) {
|
||||
this.url(url.toHttpUrl().newBuilder().apply { calld() }.build())
|
||||
} else {
|
||||
this.url(url.toHttpUrl())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置请求方法和字节数组请求体。
|
||||
*
|
||||
* @param method 请求方法
|
||||
* @param body 请求体字节数组
|
||||
* @param mediaType 可选的媒体类型;为 `null` 时不设置 Content-Type
|
||||
* @param offset 起始偏移量,默认 0
|
||||
* @param length 读取长度,默认从 [offset] 到 [body] 末尾
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.methodBody(
|
||||
method: Method,
|
||||
body: ByteArray,
|
||||
mediaType: MediaType? = null,
|
||||
offset: Int = 0,
|
||||
length: Int = body.size - offset,
|
||||
): Request.Builder {
|
||||
require(offset >= 0 && length >= 0 && offset + length <= body.size) {
|
||||
"offset/length 越界: offset=$offset, length=$length, size=${body.size}"
|
||||
}
|
||||
return method(method.name, body.toRequestBody(mediaType?.okhttp(), offset, length))
|
||||
}
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置请求方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* @param method 请求方法
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.methodJsonBody(
|
||||
method: Method,
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
): Request.Builder = methodBody(
|
||||
method,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 GET 方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* 注意:GET 请求携带请求体在 HTTP 语义中不常见,部分服务端可能忽略或拒绝。
|
||||
*
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.getJsonBody(
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
) = methodBody(
|
||||
Method.GET,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 POST 方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.postJsonBody(
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
) = methodBody(
|
||||
Method.POST,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 PUT 方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.putJsonBody(
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
) = methodBody(
|
||||
Method.PUT,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 DELETE 方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.deleteJsonBody(
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
) = methodBody(
|
||||
Method.DELETE,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 HEAD 方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* 注意:HEAD 请求通常不应携带请求体,部分服务端可能忽略或拒绝。
|
||||
*
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.headJsonBody(
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
) = methodBody(
|
||||
Method.HEAD,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 OPTIONS 方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.optionsJsonBody(
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
) = methodBody(
|
||||
Method.OPTIONS,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* 在 [Request.Builder] 上设置 QUERY 方法,并将对象序列化为 JSON 作为请求体。
|
||||
*
|
||||
* QUERY 是 HTTP 扩展方法,需服务端支持。
|
||||
*
|
||||
* @param body 待序列化的对象
|
||||
* @param jsonApi 可选的 [JsonApi] 实例;为 `null` 时使用 [JSONA.jsonApi]
|
||||
* @return 当前 [Request.Builder],便于链式调用
|
||||
*/
|
||||
fun Request.Builder.queryJsonBody(
|
||||
body: Any,
|
||||
jsonApi: JsonApi? = null,
|
||||
) = methodBody(
|
||||
Method.QUERY,
|
||||
(jsonApi ?: JSONA.jsonApi).formatBytes(body),
|
||||
MediaType.APPLICATION_JSON,
|
||||
)
|
||||
|
||||
/**
|
||||
* HTTP 请求方法枚举,供 [Request.Builder.methodBody] 等扩展使用。
|
||||
*/
|
||||
enum class Method {
|
||||
/** GET 方法。 */
|
||||
GET,
|
||||
|
||||
/** POST 方法。 */
|
||||
POST,
|
||||
|
||||
/** PUT 方法。 */
|
||||
PUT,
|
||||
|
||||
/** DELETE 方法。 */
|
||||
DELETE,
|
||||
|
||||
/** HEAD 方法。 */
|
||||
HEAD,
|
||||
|
||||
/** OPTIONS 方法。 */
|
||||
OPTIONS,
|
||||
|
||||
/** QUERY 方法(HTTP 扩展方法,需服务端支持)。 */
|
||||
QUERY,
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile FieldStructure.kt
|
||||
* LastUpdate 2026-07-02 10:22:42
|
||||
* LastUpdate 2026-11-04 11:53:07
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.lang.reflect.Modifier
|
||||
* 该类继承自JNA的Structure类,通过反射自动获取子类的公共非静态字段,
|
||||
* 并按声明顺序返回字段名列表,用于JNA结构体的字段映射。
|
||||
*/
|
||||
open class FieldStructure : Structure() {
|
||||
abstract class FieldStructure : Structure() {
|
||||
/**
|
||||
* 获取结构体字段顺序列表
|
||||
* 通过反射遍历当前类及其父类的所有声明字段,过滤出公共非静态字段,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile JSONA.kt
|
||||
* LastUpdate 2026-03-18 09:14:06
|
||||
* LastUpdate 2026-11-07 13:29:54
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,8 @@ package com.mingliqiye.utils.json.api
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.kotlinModule
|
||||
import com.mingliqiye.utils.json.api.JSONA.jsonApi
|
||||
import com.mingliqiye.utils.json.api.JSONA.setJsonApi
|
||||
import com.mingliqiye.utils.json.api.base.JsonApi
|
||||
import com.mingliqiye.utils.json.api.type.JsonTypeReference
|
||||
import com.mingliqiye.utils.json.api.type.listType
|
||||
@@ -38,523 +40,582 @@ import java.nio.file.Path
|
||||
import kotlin.io.path.readBytes
|
||||
|
||||
/**
|
||||
* JSON工具类,提供静态方法访问JSON API功能
|
||||
* JSON 工具门面,提供静态方法访问 JSON API 功能。
|
||||
*
|
||||
* [JSONA] 本身不实现 JSON 逻辑,而是持有一个可替换的 [JsonApi] 实例,
|
||||
* 所有方法都转发到当前实例。使用前必须先通过 [setJsonApi] 注入实现,
|
||||
* 未注入时访问 [jsonApi] 或调用任何转发方法都会抛出 [NullPointerException]。
|
||||
*
|
||||
* @see JsonApi
|
||||
* @see setJsonApi
|
||||
*/
|
||||
object JSONA {
|
||||
@JvmStatic
|
||||
private var jsonApi: JsonApi? = null
|
||||
|
||||
/**
|
||||
* 获取JSON API实例
|
||||
* 当前 JSON API 实例,未注入时为 `null`。
|
||||
*
|
||||
* @return JSON API实例
|
||||
* @throws NullPointerException 当JSON API未初始化时抛出异常
|
||||
* 使用 `@Volatile` 保证多线程下的可见性;仅在启动时注入一次的场景下无副作用。
|
||||
*/
|
||||
@Throws(NullPointerException::class)
|
||||
@Volatile
|
||||
@JvmStatic
|
||||
fun getJsonApi(): JsonApi {
|
||||
if (jsonApi == null) {
|
||||
throw NullPointerException("jsonApi is null plase setJsonApi first")
|
||||
}
|
||||
return jsonApi!!
|
||||
}
|
||||
private var privateJsonApi: JsonApi? = null
|
||||
|
||||
/**
|
||||
* 设置JSON API实例
|
||||
* 获取当前 JSON API 实例。
|
||||
*
|
||||
* @param jsa JSON API实例
|
||||
* @return 已注入的 [JsonApi] 实例
|
||||
* @throws NullPointerException 尚未调用 [setJsonApi] 时抛出
|
||||
*/
|
||||
@JvmStatic
|
||||
val jsonApi: JsonApi
|
||||
get() = privateJsonApi ?: throw NullPointerException("jsonApi is null plase setJsonApi first")
|
||||
|
||||
/**
|
||||
* 设置或替换 JSON API 实例。
|
||||
*
|
||||
* 设置后,[JSONA] 上所有转发方法立即使用新实例。
|
||||
*
|
||||
* @param jsa JSON API 实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun setJsonApi(jsa: JsonApi) {
|
||||
jsonApi = jsa
|
||||
privateJsonApi = jsa
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用反射创建并设置指定类型的JSON API实例
|
||||
* 通过反射创建 [T] 的无参实例并设置为当前 JSON API。
|
||||
*
|
||||
* @param T 继承自JsonApi的具体实现类
|
||||
* @param T 继承自 [JsonApi] 的具体实现类,必须提供公开无参构造
|
||||
* @throws NoSuchMethodException 实现类没有无参构造时抛出
|
||||
* @throws ReflectiveOperationException 反射实例化失败时抛出
|
||||
*/
|
||||
inline fun <reified T : JsonApi> setJsonApi() {
|
||||
setJsonApi(T::class.java.getConstructor().newInstance() as JsonApi)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定类型的对象
|
||||
* 将 JSON 字符串解析为指定类型的对象。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param clazz 目标对象的Class类型
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @param clazz 目标对象的 [Class] 类型
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parse(json: String, clazz: Class<T>): T = getJsonApi().parse(json, clazz)
|
||||
fun <T> parse(json: String, clazz: Class<T>): T = jsonApi.parse(json, clazz)
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定泛型类型对象
|
||||
* 将 JSON 字符串解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
inline fun <reified T> parse(json: String): T {
|
||||
return getJsonApi().parse(json, (object : JsonTypeReference<T>() {}))
|
||||
return jsonApi.parse(json, (object : JsonTypeReference<T>() {}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节数组形式的JSON解析为指定泛型类型对象
|
||||
* 将字节数组形式的 JSON 解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param json 待解析的JSON字节数组
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @param json 待解析的 JSON 字节数组
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
inline fun <reified T> parse(json: ByteArray): T = getJsonApi().parse(json, object : JsonTypeReference<T>() {})
|
||||
inline fun <reified T> parse(json: ByteArray): T = jsonApi.parse(json, object : JsonTypeReference<T>() {})
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定泛型类型对象
|
||||
* 将 JSON 字符串解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param type 目标对象的Type类型(支持泛型)
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @param type 目标对象的 [JsonTypeReference] 类型引用(支持泛型)
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parse(json: String, type: JsonTypeReference<T>): T = getJsonApi().parse(json, type)
|
||||
fun <T> parse(json: String, type: JsonTypeReference<T>): T = jsonApi.parse(json, type)
|
||||
|
||||
/**
|
||||
* 将对象格式化为JSON字符串
|
||||
* 将对象格式化为 JSON 字符串。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @return 格式化后的JSON字符串
|
||||
* @return 格式化后的 JSON 字符串
|
||||
*/
|
||||
@JvmStatic
|
||||
fun format(obj: Any): String = getJsonApi().format(obj)
|
||||
|
||||
fun format(obj: Any): String = jsonApi.format(obj)
|
||||
|
||||
/**
|
||||
* 从文件路径解析JSON为指定类型的对象
|
||||
* 从文件路径解析 JSON 为指定类型的对象。
|
||||
*
|
||||
* @param T 目标对象类型
|
||||
* @param path 文件路径
|
||||
* @param clazz 目标对象的Class类型
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param clazz 目标对象的 [Class] 类型
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(path: String, clazz: Class<T>): T = getJsonApi().parseFrom(path, clazz)
|
||||
fun <T> parseFrom(path: String, clazz: Class<T>): T = jsonApi.parseFrom(path, clazz)
|
||||
|
||||
/**
|
||||
* 从Path对象解析JSON为指定类型的对象
|
||||
* 从 [Path] 对象解析 JSON 为指定类型的对象。
|
||||
*
|
||||
* @param path Path对象
|
||||
* @param clazz 目标对象的Class类型
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param path [Path] 对象
|
||||
* @param clazz 目标对象的 [Class] 类型
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(path: Path, clazz: Class<T>): T = getJsonApi().parseFrom(path, clazz)
|
||||
fun <T> parseFrom(path: Path, clazz: Class<T>): T = jsonApi.parseFrom(path, clazz)
|
||||
|
||||
/**
|
||||
* 从File对象解析JSON为指定类型的对象
|
||||
* 从 [File] 对象解析 JSON 为指定类型的对象。
|
||||
*
|
||||
* @param file File对象
|
||||
* @param clazz 目标对象的Class类型
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param file [File] 对象
|
||||
* @param clazz 目标对象的 [Class] 类型
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(file: File, clazz: Class<T>): T = getJsonApi().parseFrom(file, clazz)
|
||||
fun <T> parseFrom(file: File, clazz: Class<T>): T = jsonApi.parseFrom(file, clazz)
|
||||
|
||||
/**
|
||||
* 从InputStream解析JSON为指定类型的对象
|
||||
* 从 [InputStream] 解析 JSON 为指定类型的对象。
|
||||
*
|
||||
* @param inputStream InputStream对象
|
||||
* @param clazz 目标对象的Class类型
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param inputStream [InputStream] 对象
|
||||
* @param clazz 目标对象的 [Class] 类型
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(inputStream: InputStream, clazz: Class<T>): T = getJsonApi().parseFrom(inputStream, clazz)
|
||||
fun <T> parseFrom(inputStream: InputStream, clazz: Class<T>): T = jsonApi.parseFrom(inputStream, clazz)
|
||||
|
||||
/**
|
||||
* 从文件路径解析JSON为指定泛型类型对象
|
||||
* 从文件路径解析 JSON 为指定泛型类型的对象。
|
||||
*
|
||||
* @param T 目标对象类型
|
||||
* @param path 文件路径
|
||||
* @param type 目标对象的Type类型(支持泛型)
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param type 目标对象的 [JsonTypeReference] 类型引用(支持泛型)
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(path: String, type: JsonTypeReference<T>): T = getJsonApi().parseFrom(path, type)
|
||||
fun <T> parseFrom(path: String, type: JsonTypeReference<T>): T = jsonApi.parseFrom(path, type)
|
||||
|
||||
/**
|
||||
* 从Path对象解析JSON为指定泛型类型对象
|
||||
* 从 [Path] 对象解析 JSON 为指定泛型类型的对象。
|
||||
*
|
||||
* @param path Path对象
|
||||
* @param type 目标对象的Type类型(支持泛型)
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param path [Path] 对象
|
||||
* @param type 目标对象的 [JsonTypeReference] 类型引用(支持泛型)
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(path: Path, type: JsonTypeReference<T>): T = getJsonApi().parseFrom(path, type)
|
||||
fun <T> parseFrom(path: Path, type: JsonTypeReference<T>): T = jsonApi.parseFrom(path, type)
|
||||
|
||||
/**
|
||||
* 从File对象解析JSON为指定泛型类型对象
|
||||
* 从 [File] 对象解析 JSON 为指定泛型类型的对象。
|
||||
*
|
||||
* @param file File对象
|
||||
* @param type 目标对象的Type类型(支持泛型)
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param file [File] 对象
|
||||
* @param type 目标对象的 [JsonTypeReference] 类型引用(支持泛型)
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(file: File, type: JsonTypeReference<T>): T = getJsonApi().parseFrom(file, type)
|
||||
fun <T> parseFrom(file: File, type: JsonTypeReference<T>): T = jsonApi.parseFrom(file, type)
|
||||
|
||||
/**
|
||||
* 从InputStream解析JSON为指定泛型类型对象
|
||||
* 从 [InputStream] 解析 JSON 为指定泛型类型的对象。
|
||||
*
|
||||
* @param inputStream InputStream对象
|
||||
* @param type 目标对象的Type类型(支持泛型)
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param inputStream [InputStream] 对象
|
||||
* @param type 目标对象的 [JsonTypeReference] 类型引用(支持泛型)
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseFrom(inputStream: InputStream, type: JsonTypeReference<T>): T =
|
||||
getJsonApi().parseFrom(inputStream, type)
|
||||
jsonApi.parseFrom(inputStream, type)
|
||||
|
||||
/**
|
||||
* 将字节数组形式的JSON解析为指定类型的对象
|
||||
* 将字节数组形式的 JSON 解析为指定类型的对象。
|
||||
*
|
||||
* @param json 待解析的JSON字节数组
|
||||
* @param clazz 目标对象的Class类型
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param json 待解析的 JSON 字节数组
|
||||
* @param clazz 目标对象的 [Class] 类型
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parse(json: ByteArray, clazz: Class<T>): T = getJsonApi().parse(json, clazz)
|
||||
fun <T> parse(json: ByteArray, clazz: Class<T>): T = jsonApi.parse(json, clazz)
|
||||
|
||||
/**
|
||||
* 将字节数组形式的JSON解析为指定泛型类型对象
|
||||
* 将字节数组形式的 JSON 解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param json 待解析的JSON字节数组
|
||||
* @param type 目标对象的Type类型(支持泛型)
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @param T 目标对象类型
|
||||
* @param json 待解析的 JSON 字节数组
|
||||
* @param type 目标对象的 [JsonTypeReference] 类型引用(支持泛型)
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parse(json: ByteArray, type: JsonTypeReference<T>): T = getJsonApi().parse(json, type)
|
||||
fun <T> parse(json: ByteArray, type: JsonTypeReference<T>): T = jsonApi.parse(json, type)
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定类型的对象,解析失败时返回默认值
|
||||
* 将 JSON 字符串解析为指定类型的对象,解析失败时返回默认值。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param clazz 目标对象的Class类型
|
||||
* @param T 目标对象类型
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @param clazz 目标对象的 [Class] 类型
|
||||
* @param defaultValue 解析失败时返回的默认值
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @return 解析后的对象实例或默认值
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parse(json: String, clazz: Class<T>, defaultValue: T): T = getJsonApi().parse(json, clazz, defaultValue)
|
||||
fun <T> parse(json: String, clazz: Class<T>, defaultValue: T): T = jsonApi.parse(json, clazz, defaultValue)
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定泛型类型对象,解析失败时返回默认值
|
||||
* 将 JSON 字符串解析为指定泛型类型的对象,解析失败时返回默认值。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param type 目标对象的Type类型(支持泛型)
|
||||
* @param T 目标对象类型
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @param type 目标对象的 [JsonTypeReference] 类型引用(支持泛型)
|
||||
* @param defaultValue 解析失败时返回的默认值
|
||||
* @param <T> 泛型参数,表示目标对象的类型
|
||||
* @return 解析后的对象实例或默认值
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parse(
|
||||
json: String, type: JsonTypeReference<T>, defaultValue: T,
|
||||
): T = getJsonApi().parse(json, type, defaultValue)
|
||||
): T = jsonApi.parse(json, type, defaultValue)
|
||||
|
||||
/**
|
||||
* 将对象格式化为美化格式的JSON字符串(带缩进和换行)
|
||||
* 将对象格式化为美化格式的 JSON 字符串(带缩进和换行)。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @return 格式化后的美化JSON字符串
|
||||
* @return 格式化后的美化 JSON 字符串
|
||||
*/
|
||||
@JvmStatic
|
||||
fun formatPretty(obj: Any): String = getJsonApi().formatPretty(obj)
|
||||
fun formatPretty(obj: Any): String = jsonApi.formatPretty(obj)
|
||||
|
||||
/**
|
||||
* 将对象格式化为美化格式的JSON字节数组
|
||||
* 将对象格式化为美化格式的 JSON 字节数组。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @return 格式化后的美化JSON字节数组
|
||||
* @return 格式化后的美化 JSON 字节数组
|
||||
*/
|
||||
@JvmStatic
|
||||
fun formatPrettyBytes(obj: Any): ByteArray = getJsonApi().formatPrettyBytes(obj)
|
||||
fun formatPrettyBytes(obj: Any): ByteArray = jsonApi.formatPrettyBytes(obj)
|
||||
|
||||
/**
|
||||
* 将对象格式化为美化格式的JSON字符串并写入文件
|
||||
* 将对象格式化为美化格式的 JSON 字符串并写入文件。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param file 文件路径
|
||||
*/
|
||||
@JvmStatic
|
||||
fun formatPretty(obj: Any, file: String) = getJsonApi().formatPretty(obj, file)
|
||||
fun formatPretty(obj: Any, file: String) = jsonApi.formatPretty(obj, file)
|
||||
|
||||
/**
|
||||
* 将对象格式化为美化格式的JSON字符串并写入文件
|
||||
* 将对象格式化为美化格式的 JSON 字符串并写入文件。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param file Path对象
|
||||
* @param file [Path] 对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun formatPretty(obj: Any, file: Path) = getJsonApi().formatPretty(obj, file)
|
||||
fun formatPretty(obj: Any, file: Path) = jsonApi.formatPretty(obj, file)
|
||||
|
||||
/**
|
||||
* 将对象格式化为美化格式的JSON字符串并写入文件
|
||||
* 将对象格式化为美化格式的 JSON 字符串并写入文件。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param file File对象
|
||||
* @param file [File] 对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun formatPretty(obj: Any, file: File) = getJsonApi().formatPretty(obj, file)
|
||||
fun formatPretty(obj: Any, file: File) = jsonApi.formatPretty(obj, file)
|
||||
|
||||
/**
|
||||
* 将对象格式化为美化格式的JSON字符串并写入输出流
|
||||
* 将对象格式化为美化格式的 JSON 字符串并写入输出流。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param stream OutputStream对象
|
||||
* @param stream [OutputStream] 对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun formatPretty(obj: Any, stream: OutputStream) = getJsonApi().formatPretty(obj, stream)
|
||||
|
||||
fun formatPretty(obj: Any, stream: OutputStream) = jsonApi.formatPretty(obj, stream)
|
||||
|
||||
/**
|
||||
* 将对象格式化为JSON字节数组
|
||||
* 将对象格式化为 JSON 字节数组。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @return 格式化后的JSON字节数组
|
||||
* @return 格式化后的 JSON 字节数组
|
||||
*/
|
||||
@JvmStatic
|
||||
fun formatBytes(obj: Any): ByteArray = getJsonApi().formatBytes(obj)
|
||||
|
||||
fun formatBytes(obj: Any): ByteArray = jsonApi.formatBytes(obj)
|
||||
|
||||
/**
|
||||
* 将对象格式化为JSON字符串并写入文件
|
||||
* 将对象格式化为 JSON 字符串并写入文件。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param file 文件路径
|
||||
*/
|
||||
@JvmStatic
|
||||
fun format(obj: Any, file: String) = getJsonApi().format(obj, file)
|
||||
fun format(obj: Any, file: String) = jsonApi.format(obj, file)
|
||||
|
||||
/**
|
||||
* 将对象格式化为JSON字符串并写入文件
|
||||
* 将对象格式化为 JSON 字符串并写入文件。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param file Path对象
|
||||
* @param file [Path] 对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun format(obj: Any, file: Path) = getJsonApi().format(obj, file)
|
||||
fun format(obj: Any, file: Path) = jsonApi.format(obj, file)
|
||||
|
||||
/**
|
||||
* 将对象格式化为JSON字符串并写入文件
|
||||
* 将对象格式化为 JSON 字符串并写入文件。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param file File对象
|
||||
* @param file [File] 对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun format(obj: Any, file: File) = getJsonApi().format(obj, file)
|
||||
fun format(obj: Any, file: File) = jsonApi.format(obj, file)
|
||||
|
||||
/**
|
||||
* 将对象格式化为JSON字符串并写入输出流
|
||||
* 将对象格式化为 JSON 字符串并写入输出流。
|
||||
*
|
||||
* @param obj 待格式化的对象
|
||||
* @param stream OutputStream对象
|
||||
* @param stream [OutputStream] 对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun format(obj: Any, stream: OutputStream) = getJsonApi().format(obj, stream)
|
||||
|
||||
fun format(obj: Any, stream: OutputStream) = jsonApi.format(obj, stream)
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定元素类型的List集合
|
||||
* 将 JSON 字符串解析为指定元素类型的 [List] 集合。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param elementType List中元素的类型
|
||||
* @param <T> 泛型参数,表示List中元素的类型
|
||||
* @return 解析后的List集合
|
||||
* @param T [List] 中元素的类型
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @param elementType [List] 中元素的 [Class] 类型
|
||||
* @return 解析后的 [List] 集合
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <T> parseList(json: String, elementType: Class<T>): List<T> = parse(json, listType(elementType))
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定元素类型的List集合
|
||||
* 将 JSON 字符串解析为指定元素类型的 [List] 集合。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param <T> 泛型参数,表示List中元素的类型
|
||||
* @return 解析后的List集合
|
||||
* @param T [List] 中元素的类型,由调用方通过 reified 推断
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @return 解析后的 [List] 集合
|
||||
*/
|
||||
@JvmStatic
|
||||
inline fun <reified T> parseList(json: String): List<T> = parse(json, listType(T::class.java))
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定键值类型的Map集合
|
||||
* 将 JSON 字符串解析为指定键值类型的 [MutableMap] 集合。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param keyType Map中键的类型
|
||||
* @param valueType Map中值的类型
|
||||
* @param <K> 泛型参数,表示Map中键的类型
|
||||
* @param <V> 泛型参数,表示Map中值的类型
|
||||
* @return 解析后的Map集合
|
||||
* @param K [Map] 中键的类型
|
||||
* @param V [Map] 中值的类型
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @param keyType [Map] 中键的 [Class] 类型
|
||||
* @param valueType [Map] 中值的 [Class] 类型
|
||||
* @return 解析后的 [MutableMap] 集合
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <K, V> parseMap(
|
||||
json: String, keyType: Class<K>, valueType: Class<V>,
|
||||
): MutableMap<K, V> = getJsonApi().parseMap(json, keyType, valueType)
|
||||
): MutableMap<K, V> = jsonApi.parseMap(json, keyType, valueType)
|
||||
|
||||
/**
|
||||
* 将JSON字符串解析为指定键值类型的Map集合
|
||||
* 将 JSON 字符串解析为指定键值类型的 [MutableMap] 集合。
|
||||
*
|
||||
* @param json 待解析的JSON字符串
|
||||
* @param <K> 泛型参数,表示Map中键的类型
|
||||
* @param <V> 泛型参数,表示Map中值的类型
|
||||
* @return 解析后的Map集合
|
||||
* @param K [Map] 中键的类型,由调用方通过 reified 推断
|
||||
* @param V [Map] 中值的类型,由调用方通过 reified 推断
|
||||
* @param json 待解析的 JSON 字符串
|
||||
* @return 解析后的 [MutableMap] 集合
|
||||
*/
|
||||
@JvmStatic
|
||||
inline fun <reified K, reified V> parseMap(
|
||||
json: String,
|
||||
): MutableMap<K, V> = getJsonApi().parseMap(json, K::class.java, V::class.java)
|
||||
): MutableMap<K, V> = jsonApi.parseMap(json, K::class.java, V::class.java)
|
||||
|
||||
/**
|
||||
* 验证字符串是否为有效的JSON格式
|
||||
* 验证字符串是否为有效的 JSON 格式。
|
||||
*
|
||||
* @param json 待验证的字符串
|
||||
* @return 如果是有效的JSON格式返回true,否则返回false
|
||||
* @return 如果是有效的 JSON 格式返回 `true`,否则返回 `false`
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isValidJson(json: String): Boolean = getJsonApi().isValidJson(json)
|
||||
fun isValidJson(json: String): Boolean = jsonApi.isValidJson(json)
|
||||
|
||||
/**
|
||||
* 将对象转换为JSON字节数组
|
||||
* 将对象转换为 JSON 字节数组。
|
||||
*
|
||||
* @return 转换后的JSON字节数组
|
||||
* @param obj 待转换的对象
|
||||
* @return 转换后的 JSON 字节数组
|
||||
*/
|
||||
@JvmStatic
|
||||
fun toBytes(obj: Any): ByteArray = getJsonApi().toBytes(obj)
|
||||
fun toBytes(obj: Any): ByteArray = jsonApi.toBytes(obj)
|
||||
|
||||
/**
|
||||
* 将对象转换为美化格式的JSON字节数组
|
||||
* 将对象转换为美化格式的 JSON 字节数组。
|
||||
*
|
||||
* @return 转换后的美化格式JSON字节数组
|
||||
* @param obj 待转换的对象
|
||||
* @return 转换后的美化格式 JSON 字节数组
|
||||
*/
|
||||
@JvmStatic
|
||||
fun toBytesPretty(obj: Any): ByteArray = getJsonApi().toBytesPretty(obj)
|
||||
fun toBytesPretty(obj: Any): ByteArray = jsonApi.toBytesPretty(obj)
|
||||
|
||||
/**
|
||||
* 合并多个JSON字符串为一个JSON对象
|
||||
* 合并多个 JSON 字符串为一个 JSON 对象。
|
||||
*
|
||||
* @param jsons 待合并的JSON字符串数组
|
||||
* @return 合并后的JSON字符串
|
||||
* @param jsons 待合并的 JSON 字符串数组
|
||||
* @return 合并后的 JSON 字符串
|
||||
*/
|
||||
@JvmStatic
|
||||
fun merge(vararg jsons: String): String = getJsonApi().merge(*jsons)
|
||||
fun merge(vararg jsons: String): String = jsonApi.merge(*jsons)
|
||||
|
||||
/**
|
||||
* 获取JSON字符串中指定路径节点的值
|
||||
* 获取 JSON 字符串中指定路径节点的值。
|
||||
*
|
||||
* @param json JSON字符串
|
||||
* @param path 节点路径(如:"user.name")
|
||||
* @return 节点值的字符串表示
|
||||
* @param json JSON 字符串
|
||||
* @param path 节点路径(如 `"user.name"`)
|
||||
* @return 节点值的字符串表示;节点不存在时返回 `null`
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getNodeValue(json: String, path: String): String? = getJsonApi().getNodeValue(json, path)
|
||||
fun getNodeValue(json: String, path: String): String? = jsonApi.getNodeValue(json, path)
|
||||
|
||||
/**
|
||||
* 更新JSON字符串中指定路径节点的值
|
||||
* 更新 JSON 字符串中指定路径节点的值。
|
||||
*
|
||||
* @param json 原始JSON字符串
|
||||
* @param path 节点路径(如:"user.name")
|
||||
* @param json 原始 JSON 字符串
|
||||
* @param path 节点路径(如 `"user.name"`)
|
||||
* @param newValue 新的节点值
|
||||
* @return 更新后的JSON字符串
|
||||
* @return 更新后的 JSON 字符串
|
||||
*/
|
||||
@JvmStatic
|
||||
fun updateNodeValue(json: String, path: String, newValue: Any): String =
|
||||
getJsonApi().updateNodeValue(json, path, newValue)
|
||||
jsonApi.updateNodeValue(json, path, newValue)
|
||||
|
||||
/**
|
||||
* 将源对象转换为目标类型的对象
|
||||
* 将源对象转换为目标类型的对象。
|
||||
*
|
||||
* @param D 目标对象的类型
|
||||
* @param D 目标对象类型
|
||||
* @param source 需要转换的源对象
|
||||
* @param destinationClass 目标对象的Class类型
|
||||
* @param destinationClass 目标对象的 [Class] 类型
|
||||
* @return 转换后的目标类型对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <D> convert(source: Any, destinationClass: Class<D>): D = getJsonApi().convert(source, destinationClass)
|
||||
fun <D> convert(source: Any, destinationClass: Class<D>): D = jsonApi.convert(source, destinationClass)
|
||||
|
||||
/**
|
||||
* 使用内联函数和reified类型参数将源对象转换为目标类型的对象
|
||||
* 将源对象转换为目标类型的对象,目标类型通过 reified 推断。
|
||||
*
|
||||
* @param D 目标对象的类型(通过reified类型参数推断)
|
||||
* @param D 目标对象类型,由调用方通过 reified 推断
|
||||
* @param source 需要转换的源对象
|
||||
* @return 转换后的目标类型对象
|
||||
*/
|
||||
@JvmStatic
|
||||
inline fun <reified D> convert(source: Any): D = getJsonApi().convert(source, object : JsonTypeReference<D>() {})
|
||||
inline fun <reified D> convert(source: Any): D = jsonApi.convert(source, object : JsonTypeReference<D>() {})
|
||||
|
||||
/**
|
||||
* 将源对象转换为目标类型的对象,使用JsonTypeReference指定目标类型
|
||||
* 将源对象转换为目标类型的对象,使用 [JsonTypeReference] 指定目标类型。
|
||||
*
|
||||
* @param D 目标对象的类型
|
||||
* @param D 目标对象类型
|
||||
* @param source 需要转换的源对象
|
||||
* @param destinationType 目标对象的JsonTypeReference类型引用
|
||||
* @param destinationType 目标对象的 [JsonTypeReference] 类型引用
|
||||
* @return 转换后的目标类型对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun <D> convert(source: Any, destinationType: JsonTypeReference<D>): D =
|
||||
getJsonApi().convert(source, destinationType)
|
||||
jsonApi.convert(source, destinationType)
|
||||
|
||||
/**
|
||||
* 添加JSON转换器到API中
|
||||
* 添加 JSON 转换器到 API 中。
|
||||
*
|
||||
* @param c 需要添加的JSON转换器实例
|
||||
* @param c 需要添加的 [BaseJsonConverter] 实例
|
||||
*/
|
||||
@JvmStatic
|
||||
fun addJsonConverter(c: BaseJsonConverter<*, *>) = getJsonApi().addJsonConverter(c)
|
||||
fun addJsonConverter(c: BaseJsonConverter<*, *>) = jsonApi.addJsonConverter(c)
|
||||
|
||||
/**
|
||||
* 使用反射创建并添加指定类型的JSON转换器到API中
|
||||
* 使用反射创建并添加指定类型的 JSON 转换器到 API 中。
|
||||
*
|
||||
* @param T 继承自BaseJsonConverter的具体实现类
|
||||
* @param T 继承自 [BaseJsonConverter] 的具体实现类
|
||||
*/
|
||||
inline fun <reified T : BaseJsonConverter<*, *>> addJsonConverter() = addJsonConverter(getJsonConverter<T>())
|
||||
|
||||
|
||||
/**
|
||||
* 将当前字符串解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
inline fun <reified T> String.parseJson() = parse<T>(this)
|
||||
|
||||
/**
|
||||
* 将当前字节数组解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
inline fun <reified T> ByteArray.parseJson() = parse<T>(this)
|
||||
|
||||
/**
|
||||
* 将当前 [InputStream] 的内容解析为指定泛型类型的对象,并自动关闭流。
|
||||
*
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
inline fun <reified T> InputStream.parseJson() = this.use { parse<T>(readBytes()) }
|
||||
|
||||
/**
|
||||
* 将当前 [File] 的内容解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
inline fun <reified T> File.parseJson() = this.inputStream().parseJson<T>()
|
||||
|
||||
/**
|
||||
* 将当前 [Path] 的内容解析为指定泛型类型的对象。
|
||||
*
|
||||
* @param T 目标对象类型,由调用方通过 reified 推断
|
||||
* @return 解析后的对象实例
|
||||
*/
|
||||
inline fun <reified T> Path.parseJson() = this.toFile().inputStream().parseJson<T>()
|
||||
|
||||
/**
|
||||
* 将当前对象格式化为 JSON 字符串。
|
||||
*
|
||||
* @return 格式化后的 JSON 字符串
|
||||
*/
|
||||
fun Any.toJson() = format(this)
|
||||
|
||||
/**
|
||||
* 创建并返回一个注册了 Kotlin 模块的 Jackson [ObjectMapper]。
|
||||
*
|
||||
* @return 注册了 Kotlin 模块的 [ObjectMapper]
|
||||
*/
|
||||
@JvmStatic
|
||||
fun jacksonKotlinObjectMapper(): ObjectMapper = ObjectMapper().jacksonKotlinObjectMapper()
|
||||
|
||||
/**
|
||||
* 为当前 [ObjectMapper] 注册 Kotlin 模块并返回自身。
|
||||
*
|
||||
* @return 注册了 Kotlin 模块的 [ObjectMapper](即当前实例)
|
||||
*/
|
||||
@JvmStatic
|
||||
fun ObjectMapper.jacksonKotlinObjectMapper(): ObjectMapper = this.registerModule(kotlinModule())
|
||||
|
||||
|
||||
/**
|
||||
* 将 JSON 字符串解析为 JsonItem 对象
|
||||
* 将 JSON 字符串解析为 [JsonItem] 对象。
|
||||
*
|
||||
* @param json JSON 格式的字符串
|
||||
* @return 解析后的 JsonItem 对象,可以是 JsonObject、JsonArray 或 JsonValue
|
||||
* @return 解析后的 [JsonItem] 对象,可能是 `JsonObject`、`JsonArray` 或 `JsonValue`
|
||||
*/
|
||||
@JvmStatic
|
||||
fun parseJsonItem(json: String): JsonItem = getJsonApi().parseJsonItem(json)
|
||||
fun parseJsonItem(json: String): JsonItem = jsonApi.parseJsonItem(json)
|
||||
|
||||
/**
|
||||
* 将字节数组解析为 JsonItem 对象
|
||||
* 字节数组会被转换为字符串后再解析
|
||||
* 将字节数组解析为 [JsonItem] 对象。
|
||||
*
|
||||
* 字节数组会被转换为字符串后再解析。
|
||||
*
|
||||
* @param byte JSON 格式的字节数组(通常是 UTF-8 编码)
|
||||
* @return 解析后的 JsonItem 对象
|
||||
* @return 解析后的 [JsonItem] 对象
|
||||
*/
|
||||
@JvmStatic
|
||||
fun parseJsonItem(byte: ByteArray): JsonItem {
|
||||
@@ -562,17 +623,16 @@ object JSONA {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将输入流解析为 JsonItem 对象
|
||||
* 会自动关闭输入流
|
||||
* 将输入流解析为 [JsonItem] 对象,并自动关闭输入流。
|
||||
*
|
||||
* @param inputStream JSON 数据的输入流
|
||||
* @return 解析后的 JsonItem 对象
|
||||
* @return 解析后的 [JsonItem] 对象
|
||||
* @throws IOException 当读取输入流失败时抛出
|
||||
*
|
||||
* 使用示例:
|
||||
* ```
|
||||
* val inputStream = FileInputStream("data.json")
|
||||
* val jsonItem = converter.parseJsonItem(inputStream)
|
||||
* val jsonItem = JSONA.parseJsonItem(inputStream)
|
||||
* ```
|
||||
*/
|
||||
@JvmStatic
|
||||
@@ -584,16 +644,16 @@ object JSONA {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件解析为 JsonItem 对象
|
||||
* 将文件解析为 [JsonItem] 对象。
|
||||
*
|
||||
* @param file 包含 JSON 数据的文件
|
||||
* @return 解析后的 JsonItem 对象
|
||||
* @return 解析后的 [JsonItem] 对象
|
||||
* @throws IOException 当读取文件失败时抛出
|
||||
*
|
||||
* 使用示例:
|
||||
* ```
|
||||
* val file = File("config.json")
|
||||
* val jsonItem = converter.parseJsonItem(file)
|
||||
* val jsonItem = JSONA.parseJsonItem(file)
|
||||
* ```
|
||||
*/
|
||||
@JvmStatic
|
||||
@@ -603,16 +663,16 @@ object JSONA {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件路径解析为 JsonItem 对象
|
||||
* 将文件路径解析为 [JsonItem] 对象。
|
||||
*
|
||||
* @param path 包含 JSON 数据的文件路径
|
||||
* @return 解析后的 JsonItem 对象
|
||||
* @return 解析后的 [JsonItem] 对象
|
||||
* @throws IOException 当读取文件失败时抛出
|
||||
*
|
||||
* 使用示例:
|
||||
* ```
|
||||
* val path = Paths.get("data/user.json")
|
||||
* val jsonItem = converter.parseJsonItem(path)
|
||||
* val jsonItem = JSONA.parseJsonItem(path)
|
||||
* ```
|
||||
*/
|
||||
@JvmStatic
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.lang.reflect.WildcardType
|
||||
|
||||
class TypeReference(
|
||||
val rawClass: Type,
|
||||
vararg paramType: Type
|
||||
vararg paramType: Type,
|
||||
) : ParameterizedType {
|
||||
|
||||
private val typeArguments: Array<out Type> = paramType
|
||||
|
||||
@@ -58,7 +58,7 @@ class UUIDJsonConverter private constructor() : BaseJsonStringConverter<UUID> {
|
||||
*/
|
||||
override fun convert(
|
||||
obj: UUID?,
|
||||
annotationGetter: AnnotationGetter
|
||||
annotationGetter: AnnotationGetter,
|
||||
): String? {
|
||||
// 如果输入对象为 null,直接返回 null
|
||||
if (obj.isNull()) return null
|
||||
@@ -85,7 +85,7 @@ class UUIDJsonConverter private constructor() : BaseJsonStringConverter<UUID> {
|
||||
*/
|
||||
override fun deConvert(
|
||||
obj: String?,
|
||||
annotationGetter: AnnotationGetter
|
||||
annotationGetter: AnnotationGetter,
|
||||
): UUID? {
|
||||
// 如果输入字符串为 null 或空,直接返回 null
|
||||
if (obj.isNullish()) return null
|
||||
|
||||
@@ -31,12 +31,12 @@ import tools.jackson.databind.ValueDeserializer
|
||||
|
||||
class JackJson3Deserializer<F, T>(
|
||||
val property: BeanProperty? = null,
|
||||
val jsonConverter: JsonConverter<F, T>
|
||||
val jsonConverter: JsonConverter<F, T>,
|
||||
) : ValueDeserializer<F>() {
|
||||
|
||||
override fun deserialize(
|
||||
p: JsonParser,
|
||||
ctxt: DeserializationContext?
|
||||
ctxt: DeserializationContext?,
|
||||
): F? {
|
||||
if (p.currentToken() == JsonToken.VALUE_NULL) return null
|
||||
return jsonConverter.deConvert(p.readValueAs(jsonConverter.getToClass()), object : AnnotationGetter {
|
||||
@@ -53,7 +53,7 @@ class JackJson3Deserializer<F, T>(
|
||||
*/
|
||||
override fun createContextual(
|
||||
ctxt: DeserializationContext?,
|
||||
property: BeanProperty?
|
||||
property: BeanProperty?,
|
||||
): JackJson3Deserializer<F, T> {
|
||||
return JackJson3Deserializer(property, jsonConverter)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.math.BigInteger
|
||||
|
||||
class JackJson3Serializer<F, T>(
|
||||
val property: BeanProperty? = null,
|
||||
val jsonConverter: JsonConverter<F, T>
|
||||
val jsonConverter: JsonConverter<F, T>,
|
||||
) : ValueSerializer<F>() {
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,11 +31,11 @@ import com.fasterxml.jackson.databind.deser.ContextualDeserializer
|
||||
|
||||
class JackJsonDeserializer<F, T>(
|
||||
val property: BeanProperty? = null,
|
||||
val jsonConverter: JsonConverter<F, T>
|
||||
val jsonConverter: JsonConverter<F, T>,
|
||||
) : JsonDeserializer<F>(), ContextualDeserializer {
|
||||
override fun deserialize(
|
||||
p: JsonParser,
|
||||
ctxt: DeserializationContext?
|
||||
ctxt: DeserializationContext?,
|
||||
): F? {
|
||||
if (p.currentToken == JsonToken.VALUE_NULL) return null
|
||||
return jsonConverter.deConvert(p.readValueAs(jsonConverter.getToClass()), object : AnnotationGetter {
|
||||
@@ -52,7 +52,7 @@ class JackJsonDeserializer<F, T>(
|
||||
*/
|
||||
override fun createContextual(
|
||||
ctxt: DeserializationContext?,
|
||||
property: BeanProperty?
|
||||
property: BeanProperty?,
|
||||
): JackJsonDeserializer<F, T> {
|
||||
return JackJsonDeserializer(property, jsonConverter)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.math.BigInteger
|
||||
|
||||
class JackJsonSerializer<F, T>(
|
||||
val property: BeanProperty?,
|
||||
val jsonConverter: JsonConverter<F, T>
|
||||
val jsonConverter: JsonConverter<F, T>,
|
||||
) : JsonSerializer<F>(), ContextualSerializer {
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ class JackJsonSerializer<F, T>(
|
||||
override fun serialize(
|
||||
value: F?,
|
||||
gen: JsonGenerator,
|
||||
provider: SerializerProvider?
|
||||
provider: SerializerProvider?,
|
||||
) {
|
||||
// 执行转换逻辑
|
||||
val data: T? = jsonConverter.convert(value, object : AnnotationGetter {
|
||||
@@ -78,7 +78,7 @@ class JackJsonSerializer<F, T>(
|
||||
*/
|
||||
override fun createContextual(
|
||||
prov: SerializerProvider?,
|
||||
property: BeanProperty?
|
||||
property: BeanProperty?,
|
||||
): JsonSerializer<F> {
|
||||
return JackJsonSerializer(property, jsonConverter)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
vg: QuickBaseTypeHandlerValueGetter,
|
||||
ct: CallType,
|
||||
ci: Int?,
|
||||
cn: String?
|
||||
cn: String?,
|
||||
): T?
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ class DateTimeTypeHandler : QuickBaseTypeHandler<DateTime>() {
|
||||
vg: QuickBaseTypeHandlerValueGetter,
|
||||
ct: CallType,
|
||||
ci: Int?,
|
||||
cn: String?
|
||||
cn: String?,
|
||||
): DateTime? {
|
||||
val data = (when (ct) {
|
||||
CallType.RESULTSET_INDEX -> vg.resultSet!!.getTimestamp(ci!!)
|
||||
@@ -61,7 +61,7 @@ class DateTimeTypeHandler : QuickBaseTypeHandler<DateTime>() {
|
||||
ps: PreparedStatement,
|
||||
index: Int,
|
||||
parameter: DateTime?,
|
||||
jdbcType: JdbcType?
|
||||
jdbcType: JdbcType?,
|
||||
) {
|
||||
if (parameter == null) {
|
||||
ps.setNull(index, TIMESTAMP)
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ class MysqlUUIDBinaryTypeHandler : QuickBaseTypeHandler<UUID>() {
|
||||
}
|
||||
|
||||
override fun getValue(
|
||||
vg: QuickBaseTypeHandlerValueGetter, ct: CallType, ci: Int?, cn: String?
|
||||
vg: QuickBaseTypeHandlerValueGetter, ct: CallType, ci: Int?, cn: String?,
|
||||
): UUID? {
|
||||
|
||||
val data: ByteArray? = when (ct) {
|
||||
@@ -76,7 +76,7 @@ class MysqlUUIDBinaryTypeHandler : QuickBaseTypeHandler<UUID>() {
|
||||
}
|
||||
|
||||
override fun setValue(
|
||||
ps: PreparedStatement, index: Int, parameter: UUID?, jdbcType: JdbcType?
|
||||
ps: PreparedStatement, index: Int, parameter: UUID?, jdbcType: JdbcType?,
|
||||
) {
|
||||
if (parameter == null) {
|
||||
ps.setNull(index, java.sql.Types.BINARY)
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ import java.sql.PreparedStatement
|
||||
@MappedTypes(UUID::class)
|
||||
class PgsqlUUIDTypeHandler : QuickBaseTypeHandler<UUID>() {
|
||||
override fun getValue(
|
||||
vg: QuickBaseTypeHandlerValueGetter, ct: CallType, ci: Int?, cn: String?
|
||||
vg: QuickBaseTypeHandlerValueGetter, ct: CallType, ci: Int?, cn: String?,
|
||||
): UUID? {
|
||||
val data: String? = when (ct) {
|
||||
CallType.RESULTSET_INDEX ->
|
||||
@@ -52,7 +52,7 @@ class PgsqlUUIDTypeHandler : QuickBaseTypeHandler<UUID>() {
|
||||
}
|
||||
|
||||
override fun setValue(
|
||||
ps: PreparedStatement, index: Int, parameter: UUID?, jdbcType: JdbcType?
|
||||
ps: PreparedStatement, index: Int, parameter: UUID?, jdbcType: JdbcType?,
|
||||
) {
|
||||
if (parameter == null) {
|
||||
ps.setNull(index, jdbcType?.TYPE_CODE ?: JdbcType.JAVA_OBJECT.TYPE_CODE)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile FastBaseIService.kt
|
||||
* LastUpdate 2026-10-28 23:26:17
|
||||
* LastUpdate 2026-10-31 09:51:52
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -70,57 +70,57 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* 当前服务绑定的基础映射器实例,等价于[com.baomidou.mybatisplus.extension.repository.CrudRepository.getBaseMapper]
|
||||
* @return D 继承自[FastBaseMapper]的映射器实例
|
||||
*/
|
||||
val mapper: D
|
||||
open val mapper: D
|
||||
get() = getBaseMapper()
|
||||
|
||||
/**
|
||||
* 创建[com.baomidou.mybatisplus.core.conditions.query.QueryWrapper]实例
|
||||
* @return QueryWrapper<T> 查询包装器实例
|
||||
*/
|
||||
fun queryWrapper() = mapper.queryWrapper()
|
||||
open fun queryWrapper() = mapper.queryWrapper()
|
||||
|
||||
/**
|
||||
* 创建[com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper]实例
|
||||
* @return UpdateWrapper<T> 更新包装器实例
|
||||
*/
|
||||
fun updateWrapper() = mapper.updateWrapper()
|
||||
open fun updateWrapper() = mapper.updateWrapper()
|
||||
|
||||
/**
|
||||
* 创建[com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper]实例
|
||||
* @return LambdaQueryWrapper<T> Lambda查询包装器实例
|
||||
*/
|
||||
fun lambdaQueryWrapper() = mapper.lambdaQueryWrapper()
|
||||
open fun lambdaQueryWrapper() = mapper.lambdaQueryWrapper()
|
||||
|
||||
/**
|
||||
* 创建[com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper]实例
|
||||
* @return LambdaUpdateWrapper<T> Lambda更新包装器实例
|
||||
*/
|
||||
fun lambdaUpdateWrapper() = mapper.lambdaUpdateWrapper()
|
||||
open fun lambdaUpdateWrapper() = mapper.lambdaUpdateWrapper()
|
||||
|
||||
|
||||
/**
|
||||
* [queryWrapper]的简写形式
|
||||
* @return QueryWrapper<T> 查询包装器实例
|
||||
*/
|
||||
fun qw() = queryWrapper()
|
||||
open fun qw() = queryWrapper()
|
||||
|
||||
/**
|
||||
* [updateWrapper]的简写形式
|
||||
* @return UpdateWrapper<T> 更新包装器实例
|
||||
*/
|
||||
fun uw() = updateWrapper()
|
||||
open fun uw() = updateWrapper()
|
||||
|
||||
/**
|
||||
* [lambdaQueryWrapper]的简写形式
|
||||
* @return LambdaQueryWrapper<T> Lambda查询包装器实例
|
||||
*/
|
||||
fun lqw() = lambdaQueryWrapper()
|
||||
open fun lqw() = lambdaQueryWrapper()
|
||||
|
||||
/**
|
||||
* [lambdaUpdateWrapper]的简写形式
|
||||
* @return LambdaUpdateWrapper<T> Lambda更新包装器实例
|
||||
*/
|
||||
fun luw() = lambdaUpdateWrapper()
|
||||
open fun luw() = lambdaUpdateWrapper()
|
||||
|
||||
|
||||
/**
|
||||
@@ -130,7 +130,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值,执行等值匹配
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: String,
|
||||
value: R,
|
||||
) = mapper.selectListByColumn(column, value, qw())
|
||||
@@ -143,7 +143,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的查询包装器
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: String,
|
||||
value: R,
|
||||
wrapper: QueryWrapper<T>,
|
||||
@@ -157,7 +157,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值,执行等值匹配
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: R,
|
||||
) = mapper.selectListByColumn(column, value, lqw())
|
||||
@@ -170,7 +170,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: R,
|
||||
wrapper: LambdaQueryWrapper<T>,
|
||||
@@ -183,7 +183,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值集合,执行IN匹配
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: Collection<R>,
|
||||
) = mapper.selectListByColumn(column, value, lqw())
|
||||
@@ -196,7 +196,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: Collection<R>,
|
||||
wrapper: LambdaQueryWrapper<T> = lqw(),
|
||||
@@ -209,7 +209,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值集合,执行IN匹配
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: String,
|
||||
value: Collection<R>,
|
||||
) = mapper.selectListByColumn(column, value, qw())
|
||||
@@ -222,7 +222,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的查询包装器
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun <R> selectListByColumn(
|
||||
open fun <R> selectListByColumn(
|
||||
column: String,
|
||||
value: Collection<R>,
|
||||
wrapper: QueryWrapper<T> = qw(),
|
||||
@@ -233,7 +233,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param columns 列名与列值构成的二元组,逐项执行等值匹配
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun selectListByColumns(
|
||||
open fun selectListByColumns(
|
||||
vararg columns: FastBaseMapper.StringAnyTuple2,
|
||||
) = mapper.selectListByColumns(columns = columns)
|
||||
|
||||
@@ -242,7 +242,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param columns 方法引用列与列值构成的二元组,逐项执行等值匹配
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun selectListByColumns(
|
||||
open fun selectListByColumns(
|
||||
vararg columns: FastBaseMapper.SFunctionAnyTuple2<T, *>,
|
||||
) = mapper.selectListByColumns(lqw(), columns = columns)
|
||||
|
||||
@@ -252,7 +252,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param columns 方法引用列与列值构成的二元组,逐项执行等值匹配
|
||||
* @return List<T> 查询结果列表
|
||||
*/
|
||||
fun selectListByColumns(
|
||||
open fun selectListByColumns(
|
||||
wrapper: LambdaQueryWrapper<T>,
|
||||
vararg columns: FastBaseMapper.SFunctionAnyTuple2<T, *>,
|
||||
) = mapper.selectListByColumns(wrapper = wrapper, columns = columns)
|
||||
@@ -264,7 +264,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值,执行等值匹配
|
||||
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||
*/
|
||||
fun <R> selectOneByColumn(
|
||||
open fun <R> selectOneByColumn(
|
||||
column: String,
|
||||
value: R,
|
||||
) = mapper.selectOneByColumn(column, value, qw())
|
||||
@@ -277,7 +277,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的查询包装器
|
||||
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||
*/
|
||||
fun <R> selectOneByColumn(
|
||||
open fun <R> selectOneByColumn(
|
||||
column: String,
|
||||
value: R,
|
||||
wrapper: QueryWrapper<T> = qw(),
|
||||
@@ -293,7 +293,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值,执行等值匹配
|
||||
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||
*/
|
||||
fun <R> selectOneByColumn(
|
||||
open fun <R> selectOneByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: R,
|
||||
) = selectOneByColumn(
|
||||
@@ -308,7 +308,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||
*/
|
||||
fun <R> selectOneByColumn(
|
||||
open fun <R> selectOneByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: R,
|
||||
wrapper: LambdaQueryWrapper<T>,
|
||||
@@ -323,7 +323,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值,执行等值匹配
|
||||
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||
*/
|
||||
fun <R> existsByColumn(
|
||||
open fun <R> existsByColumn(
|
||||
column: String,
|
||||
value: R,
|
||||
) = mapper.existsByColumn(column, value, qw())
|
||||
@@ -336,7 +336,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的查询包装器
|
||||
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||
*/
|
||||
fun <R> existsByColumn(
|
||||
open fun <R> existsByColumn(
|
||||
column: String,
|
||||
value: R,
|
||||
wrapper: QueryWrapper<T> = qw(),
|
||||
@@ -351,7 +351,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值,执行等值匹配
|
||||
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||
*/
|
||||
fun <R> existsByColumn(
|
||||
open fun <R> existsByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: R,
|
||||
) = mapper.existsByColumn(column, value, lqw())
|
||||
@@ -364,7 +364,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||
*/
|
||||
fun <R> existsByColumn(
|
||||
open fun <R> existsByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: R,
|
||||
wrapper: LambdaQueryWrapper<T> = lqw(),
|
||||
@@ -380,7 +380,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值集合,执行IN匹配
|
||||
* @return LinkedHashMap<R, T?> 以列值为键、实体为值的有序映射
|
||||
*/
|
||||
fun <R> selectMapByColumn(
|
||||
open fun <R> selectMapByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: Collection<R>,
|
||||
) = mapper.selectMapByColumn(column, value, lqw())
|
||||
@@ -395,7 +395,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||
* @return LinkedHashMap<R, T?> 以列值为键、实体为值的有序映射
|
||||
*/
|
||||
fun <R> selectMapByColumn(
|
||||
open fun <R> selectMapByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: Collection<R>,
|
||||
wrapper: LambdaQueryWrapper<T> = lqw(),
|
||||
@@ -408,7 +408,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值集合,执行IN匹配
|
||||
* @return Int 被删除的行数
|
||||
*/
|
||||
fun <R> deleteByColumn(
|
||||
open fun <R> deleteByColumn(
|
||||
column: String,
|
||||
value: Collection<R>,
|
||||
) = mapper.deleteByColumn(column, value, qw())
|
||||
@@ -422,7 +422,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的查询包装器
|
||||
* @return Int 被删除的行数
|
||||
*/
|
||||
fun <R> deleteByColumn(
|
||||
open fun <R> deleteByColumn(
|
||||
column: String,
|
||||
value: Collection<R>,
|
||||
wrapper: QueryWrapper<T> = qw(),
|
||||
@@ -435,7 +435,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param value 列值集合,执行IN匹配
|
||||
* @return Int 被删除的行数
|
||||
*/
|
||||
fun <R> deleteByColumn(
|
||||
open fun <R> deleteByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: Collection<R>,
|
||||
) = mapper.deleteByColumn(column, value, lqw())
|
||||
@@ -449,7 +449,7 @@ open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), ISe
|
||||
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||
* @return Int 被删除的行数
|
||||
*/
|
||||
fun <R> deleteByColumn(
|
||||
open fun <R> deleteByColumn(
|
||||
column: SFunction<T, R>,
|
||||
value: Collection<R>,
|
||||
wrapper: LambdaQueryWrapper<T>,
|
||||
|
||||
@@ -50,5 +50,3 @@ fun encryptAesGcmNoPadding(src: ByteArray, key: String, iv: ByteArray): ByteArra
|
||||
fun encryptAesGcmNoPadding(src: String, key: String, iv: ByteArray): ByteArray {
|
||||
return encryptAesGcmNoPadding(src.toByteArray(), key.toByteArray(), iv)
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -24,5 +24,5 @@ package com.mingliqiye.utils.springboot.annotation
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
annotation class ApplicationDestroyedRunner(
|
||||
val order: Int = Int.MIN_VALUE
|
||||
val order: Int = Int.MIN_VALUE,
|
||||
)
|
||||
|
||||
@@ -28,5 +28,5 @@ import org.springframework.stereotype.Component
|
||||
@Component
|
||||
annotation class Listener(
|
||||
@get:AliasFor(annotation = Component::class)
|
||||
val value: String = ""
|
||||
val value: String = "",
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ package com.mingliqiye.utils.springboot.listener
|
||||
import java.lang.reflect.Method
|
||||
|
||||
data class ApplicationRunnerData(
|
||||
val beanName: String, val order: Int, val bean: Any, val method: Method
|
||||
val beanName: String, val order: Int, val bean: Any, val method: Method,
|
||||
) {
|
||||
fun run() {
|
||||
method.invoke(bean)
|
||||
|
||||
@@ -22,11 +22,7 @@
|
||||
|
||||
package com.mingliqiye.utils.thread
|
||||
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Future
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.*
|
||||
|
||||
// ---- 并行执行 ----
|
||||
|
||||
|
||||
@@ -24,15 +24,7 @@ package com.mingliqiye.utils.thread
|
||||
|
||||
import com.mingliqiye.utils.netty.NamedThreadFactory
|
||||
import com.mingliqiye.utils.system.availableProcessors
|
||||
import java.util.concurrent.ArrayBlockingQueue
|
||||
import java.util.concurrent.BlockingQueue
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.RejectedExecutionHandler
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor
|
||||
import java.util.concurrent.SynchronousQueue
|
||||
import java.util.concurrent.ThreadFactory
|
||||
import java.util.concurrent.ThreadPoolExecutor
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.*
|
||||
|
||||
/**
|
||||
* 线程池构建器,采用链式 + DSL 风格配置 [ThreadPoolExecutor]。
|
||||
|
||||
@@ -22,13 +22,7 @@
|
||||
|
||||
package com.mingliqiye.utils.thread
|
||||
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Future
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeoutException
|
||||
import java.util.concurrent.*
|
||||
import java.util.function.Supplier
|
||||
|
||||
// ---- ExecutorService 扩展 ----
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit
|
||||
*/
|
||||
class DateTimeOffset private constructor(
|
||||
val offsetType: ChronoUnit,
|
||||
val offset: Long
|
||||
val offset: Long,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -96,4 +96,3 @@ fun isOther(now: String, other: String): Boolean? {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user