mirror of
https://github.com/tursom/TursomServer.git
synced 2025-03-13 19:30:10 +08:00
update JVM version to 17
This commit is contained in:
parent
3ae1044999
commit
9ed710458c
@ -1,41 +1,33 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.8.0"
|
||||
`maven-publish`
|
||||
kotlin("jvm") version "1.9.0"
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "maven-publish")
|
||||
|
||||
group = "cn.tursom"
|
||||
version = "1.0-SNAPSHOT"
|
||||
version = "1.1-SNAPSHOT"
|
||||
|
||||
useTursomRepositories()
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
|
||||
}
|
||||
|
||||
if (!isTestRunning) {
|
||||
tasks.withType<Test> {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
kotlinOptions.jvmTarget = "17"
|
||||
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
|
||||
//kotlinOptions.useIR = true
|
||||
}
|
||||
|
||||
autoConfigPublish()
|
||||
if (!isTestRunning) {
|
||||
tasks.withType<Test> {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
//autoConfigPublish()
|
||||
}
|
||||
|
||||
|
||||
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(kotlin("reflect"))
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
@ -8,11 +7,9 @@ dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(kotlin("reflect"))
|
||||
api(group = "org.slf4j", name = "slf4j-api", version = "1.7.32")
|
||||
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
|
||||
compileOnly(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)
|
||||
compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.9")
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = "4.1.72.Final")
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = nettyVersion)
|
||||
|
||||
testApi(group = "junit", name = "junit", version = "4.13.2")
|
||||
}
|
||||
|
||||
autoConfigPublish()
|
||||
|
@ -1,31 +0,0 @@
|
||||
package cn.tursom.core
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
open class NonLockLinkedList<T> {
|
||||
private val root = AtomicReference<TaskListNode<T>?>()
|
||||
|
||||
infix fun add(element: T) {
|
||||
val taskNode = TaskListNode(element, root.get())
|
||||
while (!root.compareAndSet(taskNode.next, taskNode)) {
|
||||
taskNode.next = root.get()
|
||||
}
|
||||
}
|
||||
|
||||
infix operator fun invoke(data: T) = add(data)
|
||||
|
||||
fun take(): T? {
|
||||
var node = root.get()
|
||||
while (!root.compareAndSet(node, node?.next)) {
|
||||
node = root.get()
|
||||
}
|
||||
return node?.data
|
||||
}
|
||||
|
||||
private class TaskListNode<T>(
|
||||
val data: T,
|
||||
@Volatile var next: TaskListNode<T>?,
|
||||
)
|
||||
|
||||
class NotSupportedException : Exception()
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package cn.tursom.core
|
||||
|
||||
import java.util.concurrent.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class ScheduledExecutorPool(
|
||||
private val threadCount: Int = Runtime.getRuntime().availableProcessors() * 2,
|
||||
private val threadFactory: ThreadFactory = Executors.defaultThreadFactory(),
|
||||
) {
|
||||
private val scheduledExecutorQueue = ConcurrentLinkedDeque<Pair<Thread, ScheduledExecutorService>>()
|
||||
private var initCount = AtomicInteger()
|
||||
|
||||
init {
|
||||
initOne()
|
||||
}
|
||||
|
||||
private fun initOne() {
|
||||
if (initCount.incrementAndGet() < threadCount) {
|
||||
val executor: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor {
|
||||
threadFactory.newThread(it)
|
||||
}
|
||||
val countDownLatch = CountDownLatch(1)
|
||||
executor.execute {
|
||||
scheduledExecutorQueue.addFirst(Thread.currentThread() to executor)
|
||||
countDownLatch.countDown()
|
||||
}
|
||||
countDownLatch.await(3, TimeUnit.SECONDS)
|
||||
} else {
|
||||
initCount.decrementAndGet()
|
||||
}
|
||||
}
|
||||
|
||||
fun get(): Pair<Thread, ScheduledExecutorService> {
|
||||
if (initCount.get() < threadCount) {
|
||||
initOne()
|
||||
}
|
||||
val pair = scheduledExecutorQueue.poll()
|
||||
scheduledExecutorQueue.add(pair)
|
||||
return pair
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package cn.tursom.core
|
||||
|
||||
open class SimpThreadLocal<T : Any>(
|
||||
private val threadLocal: ThreadLocal<T?>? = null,
|
||||
val new: () -> T,
|
||||
) : ThreadLocal<T>() {
|
||||
override fun get(): T {
|
||||
var value = if (threadLocal != null) threadLocal.get() else super.get()
|
||||
return if (value == null) {
|
||||
value = new()
|
||||
set(value)
|
||||
value
|
||||
} else {
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
override fun set(value: T) {
|
||||
if (threadLocal != null) threadLocal.set(value) else super.set(value)
|
||||
}
|
||||
|
||||
override fun remove() {
|
||||
if (threadLocal != null) threadLocal.remove() else super.remove()
|
||||
}
|
||||
}
|
||||
|
@ -1,268 +0,0 @@
|
||||
package cn.tursom.core
|
||||
|
||||
class Switch(
|
||||
val value: Any? = null,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
object BreakException : Exception()
|
||||
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Any?, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(block: Switch.() -> Unit) {
|
||||
val switch = Switch()
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T : Any?> switch(value: T, block: Switch.() -> Unit) {
|
||||
val switch = Switch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
class ByteSwitch(
|
||||
val value: Byte,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw Switch.BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Byte, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(value: Byte, block: ByteSwitch.() -> Unit) {
|
||||
val switch = ByteSwitch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
class ShortSwitch(
|
||||
val value: Short,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw Switch.BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Short, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(value: Short, block: ShortSwitch.() -> Unit) {
|
||||
val switch = ShortSwitch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
class IntSwitch(
|
||||
val value: Int,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw Switch.BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Int, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(value: Int, block: IntSwitch.() -> Unit) {
|
||||
val switch = IntSwitch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
class LongSwitch(
|
||||
val value: Long,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw Switch.BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Long, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(value: Long, block: LongSwitch.() -> Unit) {
|
||||
val switch = LongSwitch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
class FloatSwitch(
|
||||
val value: Float,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw Switch.BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Float, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(value: Float, block: FloatSwitch.() -> Unit) {
|
||||
val switch = FloatSwitch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
class DoubleSwitch(
|
||||
val value: Double,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw Switch.BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Double, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(value: Double, block: DoubleSwitch.() -> Unit) {
|
||||
val switch = DoubleSwitch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
||||
class CharSwitch(
|
||||
val value: Char,
|
||||
var consider: Boolean = false,
|
||||
) {
|
||||
inline val `break`: Unit
|
||||
inline get() {
|
||||
throw Switch.BreakException
|
||||
}
|
||||
|
||||
inline fun case(value: Char, block: () -> Unit = {}) {
|
||||
if (consider || value == value) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case(condition: Boolean = false, block: () -> Unit = {}) {
|
||||
if (consider || condition) {
|
||||
consider = true
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun switch(value: Char, block: CharSwitch.() -> Unit) {
|
||||
val switch = CharSwitch(value)
|
||||
try {
|
||||
switch.block()
|
||||
} catch (e: Switch.BreakException) {
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
package cn.tursom.core
|
||||
|
||||
import java.lang.ref.SoftReference
|
||||
|
||||
open class UpdatableThreadLocal<T>(
|
||||
@Volatile
|
||||
private var new: () -> T,
|
||||
) : ThreadLocal<T>() {
|
||||
@Suppress("LeakingThis")
|
||||
private val thisSoft: SoftReference<UpdatableThreadLocal<*>> = SoftReference(this)
|
||||
|
||||
@Volatile
|
||||
private var updateTime: Long = System.currentTimeMillis()
|
||||
|
||||
private fun update(): T {
|
||||
val value = new()
|
||||
set(value)
|
||||
updateTimeThreadLocal.get()[thisSoft] = System.currentTimeMillis()
|
||||
return value
|
||||
}
|
||||
|
||||
override fun get(): T = if (updateTimeThreadLocal.get()[thisSoft] ?: 0 < updateTime) {
|
||||
update()
|
||||
} else {
|
||||
super.get() ?: update()
|
||||
}
|
||||
|
||||
fun update(new: () -> T) {
|
||||
this.new = new
|
||||
updateTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val updateTimeThreadLocal = SimpThreadLocal {
|
||||
HashMap<SoftReference<UpdatableThreadLocal<*>>, Long>()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package cn.tursom.core
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class UpdatableThreadLocalSimpleDateFormat(
|
||||
format: String = "YYYY-MM-dd'T'HH:mm:ssZZ",
|
||||
) : UpdatableThreadLocal<SimpleDateFormat>({
|
||||
SimpleDateFormat(format)
|
||||
}) {
|
||||
@Volatile
|
||||
var format: String = format
|
||||
set(value) {
|
||||
update { SimpleDateFormat(value) }
|
||||
field = value
|
||||
}
|
||||
|
||||
fun format(date: Any) = get().format(date)
|
||||
fun format(date: Date) = get().format(date)
|
||||
fun parse(date: String) = get().parse(date)
|
||||
|
||||
companion object {
|
||||
val iso8601 = UpdatableThreadLocalSimpleDateFormat("YYYY-MM-dd'T'HH:mm:ssZZ")
|
||||
val standard = UpdatableThreadLocalSimpleDateFormat("YYYY-MM-dd HH:mm:ss")
|
||||
val simp = UpdatableThreadLocalSimpleDateFormat("YY-MM-dd HH:mm:ss")
|
||||
val cn = UpdatableThreadLocalSimpleDateFormat("YYYY'年'MM'月'dd'日' HH'时'mm'分'ss'秒'")
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.context
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class ArrayContextEnv : ContextEnv {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.context
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
|
||||
open class ContextKey<T>(
|
||||
val envId: Int,
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.context
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class HashMapContextEnv : ContextEnv {
|
||||
|
@ -1,4 +0,0 @@
|
||||
package cn.tursom.core
|
||||
|
||||
inline fun <T, R> with(v: T, crossinline action: (T) -> R): () -> R = { action(v) }
|
||||
inline fun <T1, T2, R> with(v1: T1, v2: T2, crossinline action: (T1, T2) -> R): () -> R = { action(v1, v2) }
|
@ -2,7 +2,7 @@
|
||||
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.lang.reflect.Method
|
||||
|
||||
inline fun <R> Class<*>.getStaticDeclaredMethod(
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.lang.reflect.Method
|
||||
|
||||
inline fun <This, reified R> Class<*>.getMethod(
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.allMethodsSequence
|
||||
import cn.tursom.core.companionObjectInstanceOrNull
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.allMethodsSequence
|
||||
import cn.tursom.core.util.companionObjectInstanceOrNull
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import com.ddbes.kotlin.isStatic
|
||||
import java.lang.reflect.Method
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.Unsafe
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.Unsafe
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.UncheckedCast
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.forAllMethods
|
||||
import cn.tursom.core.util.UncheckedCast
|
||||
import cn.tursom.core.util.cast
|
||||
import cn.tursom.core.util.forAllMethods
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.ParameterizedType
|
||||
|
@ -1,10 +1,10 @@
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.ThreadLocalSimpleDateFormat
|
||||
import cn.tursom.core.Unsafe.unsafe
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.getClazz
|
||||
import cn.tursom.core.isInheritanceFrom
|
||||
import cn.tursom.core.util.ThreadLocalSimpleDateFormat
|
||||
import cn.tursom.core.util.Unsafe.unsafe
|
||||
import cn.tursom.core.util.cast
|
||||
import cn.tursom.core.util.getClazz
|
||||
import cn.tursom.core.util.isInheritanceFrom
|
||||
import java.lang.reflect.Array
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Modifier
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.allMethodsSequence
|
||||
import cn.tursom.core.util.allMethodsSequence
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class ReturnTypeMethodFilter<R>(
|
||||
|
@ -1,9 +1,9 @@
|
||||
package cn.tursom.core.reflect
|
||||
|
||||
import cn.tursom.core.Unsafe.getField
|
||||
import cn.tursom.core.companionObjectInstanceOrNull
|
||||
import cn.tursom.core.isStatic
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.Unsafe.getField
|
||||
import cn.tursom.core.util.companionObjectInstanceOrNull
|
||||
import cn.tursom.core.util.isStatic
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import java.util.*
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.timer
|
||||
|
||||
import cn.tursom.core.CurrentTimeMillisClock
|
||||
import cn.tursom.core.util.CurrentTimeMillisClock
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
class NonLockTaskQueue : TaskQueue {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.timer
|
||||
|
||||
import cn.tursom.core.CurrentTimeMillisClock
|
||||
import cn.tursom.core.util.CurrentTimeMillisClock
|
||||
|
||||
class SynchronizedTaskQueue : TaskQueue {
|
||||
val root: TaskNode = TaskNode(0, {}, null, null)
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.timer
|
||||
|
||||
import cn.tursom.core.CurrentTimeMillisClock
|
||||
import cn.tursom.core.util.CurrentTimeMillisClock
|
||||
|
||||
interface TimerTask : () -> Unit {
|
||||
val canceled: Boolean
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.timer
|
||||
|
||||
import cn.tursom.core.CurrentTimeMillisClock
|
||||
import cn.tursom.core.util.CurrentTimeMillisClock
|
||||
import java.lang.Thread.sleep
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
@ -9,18 +9,15 @@ import java.util.jar.JarFile
|
||||
val ClassLoader.classes: List<Class<*>>
|
||||
get() = ClassLoaderUtil.classes.get(this) as List<Class<*>>
|
||||
|
||||
fun ClassLoader.getClassByPackage(
|
||||
fun ClassLoader.listClassByPackage(
|
||||
packageName: String,
|
||||
childPackage: Boolean = true,
|
||||
): List<String> = ClassLoaderUtil.getClassByPackage(packageName, childPackage, this)
|
||||
|
||||
inline fun <reified T> T.getClassByPackage(
|
||||
packageName: String,
|
||||
childPackage: Boolean = true,
|
||||
): List<String> = ClassLoaderUtil.getClassByPackage(packageName, childPackage, T::class.java.classLoader)
|
||||
|
||||
object ClassLoaderUtil {
|
||||
internal val classes = ClassLoader::class.java.getDeclaredField("classes").also { it.isAccessible = true }
|
||||
internal val classes = ClassLoader::class.java
|
||||
.getDeclaredField("classes")
|
||||
.also { it.isAccessible = true }
|
||||
|
||||
/**
|
||||
* 获取某包下所有类
|
||||
@ -115,7 +112,7 @@ object ClassLoaderUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
return myClassName
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
data class R2<R1, R2>(val r1: R1, val r2: R2)
|
||||
data class R3<R1, R2, R3>(val r1: R1, val r2: R2, val r3: R3)
|
||||
@ -240,36 +240,36 @@ operator fun <T> List<T>.component28() = this[27]
|
||||
operator fun <T> List<T>.component29() = this[28]
|
||||
operator fun <T> List<T>.component30() = this[29]
|
||||
|
||||
operator fun <T> Array<T>.component1() = this[0]
|
||||
operator fun <T> Array<T>.component2() = this[1]
|
||||
operator fun <T> Array<T>.component3() = this[2]
|
||||
operator fun <T> Array<T>.component4() = this[3]
|
||||
operator fun <T> Array<T>.component5() = this[4]
|
||||
operator fun <T> Array<T>.component6() = this[5]
|
||||
operator fun <T> Array<T>.component7() = this[6]
|
||||
operator fun <T> Array<T>.component8() = this[7]
|
||||
operator fun <T> Array<T>.component9() = this[8]
|
||||
operator fun <T> Array<T>.component10() = this[9]
|
||||
operator fun <T> Array<T>.component11() = this[10]
|
||||
operator fun <T> Array<T>.component12() = this[11]
|
||||
operator fun <T> Array<T>.component13() = this[12]
|
||||
operator fun <T> Array<T>.component14() = this[13]
|
||||
operator fun <T> Array<T>.component15() = this[14]
|
||||
operator fun <T> Array<T>.component16() = this[15]
|
||||
operator fun <T> Array<T>.component17() = this[16]
|
||||
operator fun <T> Array<T>.component18() = this[17]
|
||||
operator fun <T> Array<T>.component19() = this[18]
|
||||
operator fun <T> Array<T>.component20() = this[19]
|
||||
operator fun <T> Array<T>.component21() = this[20]
|
||||
operator fun <T> Array<T>.component22() = this[21]
|
||||
operator fun <T> Array<T>.component23() = this[22]
|
||||
operator fun <T> Array<T>.component24() = this[23]
|
||||
operator fun <T> Array<T>.component25() = this[24]
|
||||
operator fun <T> Array<T>.component26() = this[25]
|
||||
operator fun <T> Array<T>.component27() = this[26]
|
||||
operator fun <T> Array<T>.component28() = this[27]
|
||||
operator fun <T> Array<T>.component29() = this[28]
|
||||
operator fun <T> Array<T>.component30() = this[29]
|
||||
operator fun <T> Array<out T>.component1() = this[0]
|
||||
operator fun <T> Array<out T>.component2() = this[1]
|
||||
operator fun <T> Array<out T>.component3() = this[2]
|
||||
operator fun <T> Array<out T>.component4() = this[3]
|
||||
operator fun <T> Array<out T>.component5() = this[4]
|
||||
operator fun <T> Array<out T>.component6() = this[5]
|
||||
operator fun <T> Array<out T>.component7() = this[6]
|
||||
operator fun <T> Array<out T>.component8() = this[7]
|
||||
operator fun <T> Array<out T>.component9() = this[8]
|
||||
operator fun <T> Array<out T>.component10() = this[9]
|
||||
operator fun <T> Array<out T>.component11() = this[10]
|
||||
operator fun <T> Array<out T>.component12() = this[11]
|
||||
operator fun <T> Array<out T>.component13() = this[12]
|
||||
operator fun <T> Array<out T>.component14() = this[13]
|
||||
operator fun <T> Array<out T>.component15() = this[14]
|
||||
operator fun <T> Array<out T>.component16() = this[15]
|
||||
operator fun <T> Array<out T>.component17() = this[16]
|
||||
operator fun <T> Array<out T>.component18() = this[17]
|
||||
operator fun <T> Array<out T>.component19() = this[18]
|
||||
operator fun <T> Array<out T>.component20() = this[19]
|
||||
operator fun <T> Array<out T>.component21() = this[20]
|
||||
operator fun <T> Array<out T>.component22() = this[21]
|
||||
operator fun <T> Array<out T>.component23() = this[22]
|
||||
operator fun <T> Array<out T>.component24() = this[23]
|
||||
operator fun <T> Array<out T>.component25() = this[24]
|
||||
operator fun <T> Array<out T>.component26() = this[25]
|
||||
operator fun <T> Array<out T>.component27() = this[26]
|
||||
operator fun <T> Array<out T>.component28() = this[27]
|
||||
operator fun <T> Array<out T>.component29() = this[28]
|
||||
operator fun <T> Array<out T>.component30() = this[29]
|
||||
|
||||
operator fun CharArray.component1() = this[0]
|
||||
operator fun CharArray.component2() = this[1]
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
@ -17,6 +17,4 @@ object CurrentTimeMillisClock {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//val now get() = System.currentTimeMillis()
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
@file:Suppress("unused", "DuplicatedCode")
|
||||
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.io.*
|
||||
import java.nio.ByteOrder
|
||||
@ -16,44 +16,44 @@ fun Double.reverseBytes() = Double.fromBits(toBits().reverseBytes())
|
||||
|
||||
fun Char.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val array = ByteArray(2)
|
||||
array.put(this, 0, byteOrder)
|
||||
array[0, byteOrder] = this
|
||||
return array
|
||||
}
|
||||
|
||||
fun Short.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val array = ByteArray(2)
|
||||
array.put(this, 0, byteOrder)
|
||||
array[0, byteOrder] = this
|
||||
return array
|
||||
}
|
||||
|
||||
fun Int.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val array = ByteArray(4)
|
||||
array.put(this, 0, byteOrder)
|
||||
array[0, byteOrder] = this
|
||||
return array
|
||||
}
|
||||
|
||||
fun Long.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val array = ByteArray(8)
|
||||
array.put(this, 0, byteOrder)
|
||||
array[0, byteOrder] = this
|
||||
return array
|
||||
}
|
||||
|
||||
fun Float.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val array = ByteArray(4)
|
||||
array.put(this, 0, byteOrder)
|
||||
array[0, byteOrder] = this
|
||||
return array
|
||||
}
|
||||
|
||||
fun Double.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val array = ByteArray(8)
|
||||
array.put(this, 0, byteOrder)
|
||||
array[0, byteOrder] = this
|
||||
return array
|
||||
}
|
||||
|
||||
fun CharArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val newArray = ByteArray(size * 2)
|
||||
repeat(size) {
|
||||
newArray.put(this[it], it * 2, byteOrder)
|
||||
newArray[it * 2, byteOrder] = this[it]
|
||||
}
|
||||
return newArray
|
||||
}
|
||||
@ -61,7 +61,7 @@ fun CharArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArra
|
||||
fun ShortArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val newArray = ByteArray(size * 2)
|
||||
repeat(size) {
|
||||
newArray.put(this[it], it * 2, byteOrder)
|
||||
newArray[it * 2, byteOrder] = this[it]
|
||||
}
|
||||
return newArray
|
||||
}
|
||||
@ -69,7 +69,7 @@ fun ShortArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArr
|
||||
fun IntArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val newArray = ByteArray(size * 4)
|
||||
repeat(size) {
|
||||
newArray.put(this[it], it * 4, byteOrder)
|
||||
newArray[it * 4, byteOrder] = this[it]
|
||||
}
|
||||
return newArray
|
||||
}
|
||||
@ -77,7 +77,7 @@ fun IntArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray
|
||||
fun LongArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val newArray = ByteArray(size * 8)
|
||||
repeat(size) {
|
||||
newArray.put(this[it], it * 8, byteOrder)
|
||||
newArray[it * 8, byteOrder] = this[it]
|
||||
}
|
||||
return newArray
|
||||
}
|
||||
@ -85,7 +85,7 @@ fun LongArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArra
|
||||
fun FloatArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val newArray = ByteArray(size * 4)
|
||||
repeat(size) {
|
||||
newArray.put(this[it], it * 4, byteOrder)
|
||||
newArray[it * 4, byteOrder] = this[it]
|
||||
}
|
||||
return newArray
|
||||
}
|
||||
@ -93,7 +93,7 @@ fun FloatArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArr
|
||||
fun DoubleArray.toByteArray(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray {
|
||||
val newArray = ByteArray(size * 8)
|
||||
repeat(size) {
|
||||
newArray.put(this[it], it * 8, byteOrder)
|
||||
newArray[it * 8, byteOrder] = this[it]
|
||||
}
|
||||
return newArray
|
||||
}
|
||||
@ -226,37 +226,53 @@ fun Long.ntoh(): Long {
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(char: Char, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN) {
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
char: Char
|
||||
) {
|
||||
val value = char.code
|
||||
when (byteOrder) {
|
||||
ByteOrder.BIG_ENDIAN -> {
|
||||
this[offset + 1] = value.toByte()
|
||||
this[offset] = (value shr 8).toByte()
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
this[offset] = value.toByte()
|
||||
this[offset + 1] = (value shr 8).toByte()
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(short: Short, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN) {
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
short: Short
|
||||
) {
|
||||
val value = short.toInt()
|
||||
when (byteOrder) {
|
||||
ByteOrder.BIG_ENDIAN -> {
|
||||
this[offset + 1] = value.toByte()
|
||||
this[offset] = (value shr 8).toByte()
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
this[offset] = value.toByte()
|
||||
this[offset + 1] = (value shr 8).toByte()
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(int: Int, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN) {
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
int: Int,
|
||||
) {
|
||||
when (byteOrder) {
|
||||
ByteOrder.BIG_ENDIAN -> {
|
||||
this[offset + 3] = int.toByte()
|
||||
@ -264,17 +280,23 @@ fun ByteArray.put(int: Int, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BI
|
||||
this[offset + 1] = (int shr 16).toByte()
|
||||
this[offset] = (int shr 24).toByte()
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
this[offset] = int.toByte()
|
||||
this[offset + 1] = (int shr 8).toByte()
|
||||
this[offset + 2] = (int shr 16).toByte()
|
||||
this[offset + 3] = (int shr 24).toByte()
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(long: Long, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN) {
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
long: Long
|
||||
) {
|
||||
when (byteOrder) {
|
||||
ByteOrder.BIG_ENDIAN -> {
|
||||
this[offset + 7] = long.toByte()
|
||||
@ -286,6 +308,7 @@ fun ByteArray.put(long: Long, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.
|
||||
this[offset + 1] = (long shr 48).toByte()
|
||||
this[offset] = (long shr 56).toByte()
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
this[offset] = long.toByte()
|
||||
this[offset + 1] = (long shr 8).toByte()
|
||||
@ -296,129 +319,130 @@ fun ByteArray.put(long: Long, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.
|
||||
this[offset + 6] = (long shr 48).toByte()
|
||||
this[offset + 7] = (long shr 56).toByte()
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(float: Float, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN) {
|
||||
put(float.toBits(), offset, byteOrder)
|
||||
operator fun ByteArray.set(offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, float: Float) {
|
||||
set(offset, byteOrder, float.toBits())
|
||||
}
|
||||
|
||||
fun ByteArray.put(double: Double, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN) {
|
||||
put(double.toBits(), offset, byteOrder)
|
||||
operator fun ByteArray.set(offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, double: Double) {
|
||||
set(offset, byteOrder, double.toBits())
|
||||
}
|
||||
|
||||
fun ByteArray.put(
|
||||
charArray: CharArray,
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
addLength: Boolean = true,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
charArray: CharArray,
|
||||
) {
|
||||
var index = offset
|
||||
if (addLength) {
|
||||
put(charArray.size, index, byteOrder)
|
||||
set(index, byteOrder, charArray.size)
|
||||
index += 4
|
||||
}
|
||||
charArray.forEach {
|
||||
put(it, index, byteOrder)
|
||||
set(index, byteOrder, it)
|
||||
index += 2
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(
|
||||
shortArray: ShortArray,
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
addLength: Boolean = true,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
shortArray: ShortArray,
|
||||
) {
|
||||
var index = offset
|
||||
if (addLength) {
|
||||
put(shortArray.size, index, byteOrder)
|
||||
set(index, byteOrder, shortArray.size)
|
||||
index += 4
|
||||
}
|
||||
shortArray.forEach {
|
||||
put(it, index, byteOrder)
|
||||
set(index, byteOrder, it)
|
||||
index += 2
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(
|
||||
intArray: IntArray,
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
addLength: Boolean = true,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
intArray: IntArray,
|
||||
) {
|
||||
var index = offset
|
||||
if (addLength) {
|
||||
put(intArray.size, index, byteOrder)
|
||||
set(index, byteOrder, intArray.size)
|
||||
index += 4
|
||||
}
|
||||
intArray.forEach {
|
||||
put(it)
|
||||
set(index, byteOrder, it)
|
||||
index += 4
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(
|
||||
longArray: LongArray,
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
addLength: Boolean = true,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
longArray: LongArray,
|
||||
) {
|
||||
var index = offset
|
||||
if (addLength) {
|
||||
put(longArray.size, index, byteOrder)
|
||||
set(index, byteOrder, longArray.size)
|
||||
index += 4
|
||||
}
|
||||
longArray.forEach {
|
||||
put(it, index, byteOrder)
|
||||
set(index, byteOrder, it)
|
||||
index += 8
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(
|
||||
floatArray: FloatArray,
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
addLength: Boolean = true,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
floatArray: FloatArray,
|
||||
) {
|
||||
var index = offset
|
||||
if (addLength) {
|
||||
put(floatArray.size, index, byteOrder)
|
||||
set(index, byteOrder, floatArray.size)
|
||||
index += 4
|
||||
}
|
||||
floatArray.forEach {
|
||||
put(it, index, byteOrder)
|
||||
set(index, byteOrder, it)
|
||||
index += 4
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(
|
||||
doubleArray: DoubleArray,
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
addLength: Boolean = true,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
doubleArray: DoubleArray,
|
||||
) {
|
||||
var index = offset
|
||||
if (addLength) {
|
||||
put(doubleArray.size, index, byteOrder)
|
||||
set(index, byteOrder, doubleArray.size)
|
||||
index += 4
|
||||
}
|
||||
doubleArray.forEach {
|
||||
put(it, index, byteOrder)
|
||||
set(index, byteOrder, it)
|
||||
index += 8
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.put(
|
||||
str: String,
|
||||
operator fun ByteArray.set(
|
||||
offset: Int = 0,
|
||||
addLength: Boolean = false,
|
||||
byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
|
||||
str: String,
|
||||
): Int {
|
||||
val utf8Array = str.toByteArray()
|
||||
return if (addLength) {
|
||||
put(utf8Array.size, 0, byteOrder)
|
||||
set(0, byteOrder, utf8Array.size)
|
||||
utf8Array.copyInto(this, offset + 4)
|
||||
utf8Array.size + 4
|
||||
} else {
|
||||
@ -513,7 +537,7 @@ fun Int.asFloat(): Float = Float.fromBits(this)
|
||||
fun Long.asDouble(): Double = Double.fromBits(this)
|
||||
|
||||
|
||||
fun ByteArray.put(obj: Any, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN): Int {
|
||||
operator fun ByteArray.set(offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, obj: Any): Int {
|
||||
return when (obj) {
|
||||
is Byte -> if (offset < size) {
|
||||
this[offset] = obj
|
||||
@ -521,65 +545,77 @@ fun ByteArray.put(obj: Any, offset: Int = 0, byteOrder: ByteOrder = ByteOrder.BI
|
||||
} else {
|
||||
throw IndexOutOfBoundsException()
|
||||
}
|
||||
|
||||
is Char -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
2
|
||||
}
|
||||
|
||||
is Short -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
2
|
||||
}
|
||||
|
||||
is Int -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
4
|
||||
}
|
||||
|
||||
is Long -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
8
|
||||
}
|
||||
|
||||
is Float -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
4
|
||||
}
|
||||
|
||||
is Double -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
8
|
||||
}
|
||||
|
||||
is ByteArray -> if (size < offset + obj.size) {
|
||||
put(obj.size, offset, byteOrder)
|
||||
set(offset, byteOrder, obj.size)
|
||||
obj.copyInto(this, offset + 4)
|
||||
obj.size + 4
|
||||
} else {
|
||||
throw IndexOutOfBoundsException()
|
||||
}
|
||||
|
||||
is CharArray -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
obj.size * 2 + 4
|
||||
}
|
||||
|
||||
is ShortArray -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
obj.size * 2 + 4
|
||||
}
|
||||
|
||||
is IntArray -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
obj.size * 4 + 4
|
||||
}
|
||||
|
||||
is LongArray -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
obj.size * 8 + 4
|
||||
}
|
||||
|
||||
is FloatArray -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
obj.size * 4 + 4
|
||||
}
|
||||
|
||||
is DoubleArray -> {
|
||||
put(obj, offset, byteOrder)
|
||||
set(offset, byteOrder, obj)
|
||||
obj.size * 8 + 4
|
||||
}
|
||||
|
||||
is String -> {
|
||||
put(obj, offset, true, byteOrder)
|
||||
set(offset, true, byteOrder, obj)
|
||||
}
|
||||
|
||||
else -> throw WrongPushTypeException()
|
||||
@ -682,10 +718,12 @@ inline fun Char.toBytes(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, action: (By
|
||||
action((value shr 8).toByte())
|
||||
action(value.toByte())
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
action(value.toByte())
|
||||
action((value shr 8).toByte())
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@ -697,10 +735,12 @@ inline fun Short.toBytes(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, action: (B
|
||||
action((value shr 8).toByte())
|
||||
action(value.toByte())
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
action(value.toByte())
|
||||
action((value shr 8).toByte())
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@ -713,12 +753,14 @@ inline fun Int.toBytes(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, action: (Byt
|
||||
action((this shr 8).toByte())
|
||||
action(this.toByte())
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
action(this.toByte())
|
||||
action((this shr 8).toByte())
|
||||
action((this shr 16).toByte())
|
||||
action((this shr 24).toByte())
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@ -735,6 +777,7 @@ inline fun Long.toBytes(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, action: (By
|
||||
action((this shr 8).toByte())
|
||||
action(this.toByte())
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
action(this.toByte())
|
||||
action((this shr 8).toByte())
|
||||
@ -745,6 +788,7 @@ inline fun Long.toBytes(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, action: (By
|
||||
action((this shr 48).toByte())
|
||||
action((this shr 56).toByte())
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@ -763,9 +807,11 @@ inline fun toChar(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, get: () -> Byte):
|
||||
val late = get()
|
||||
get().toInt() or (late.toInt() shl 8)
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
get().toInt() or (get().toInt() shl 8)
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}.toChar()
|
||||
}
|
||||
@ -776,9 +822,11 @@ inline fun toShort(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, get: () -> Byte)
|
||||
val late = get()
|
||||
get().toInt() or (late.toInt() shl 8)
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
get().toInt() or (get().toInt() shl 8)
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}.toShort()
|
||||
}
|
||||
@ -792,10 +840,12 @@ inline fun toInt(byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN, get: () -> Byte):
|
||||
get().toInt() and 0xff or (i3.toInt() shl 8 and 0xff00) or
|
||||
(i2.toInt() shl 16 and 0xff0000) or (i1.toInt() shl 24 and 0xff000000.toInt())
|
||||
}
|
||||
|
||||
ByteOrder.LITTLE_ENDIAN -> {
|
||||
get().toInt() and 0xff or (get().toInt() shl 8 and 0xff00) or
|
||||
(get().toInt() shl 16 and 0xff0000) or (get().toInt() shl 24 and 0xff000000.toInt())
|
||||
}
|
||||
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.TypeAdapter
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.lang.ref.PhantomReference
|
||||
import java.lang.ref.Reference
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.TypeAdapter
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
@Suppress("unused")
|
||||
class ListClassLoader(
|
@ -1,6 +1,6 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Member
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.io.File
|
||||
import java.util.*
|
101
ts-core/src/main/kotlin/cn/tursom/core/util/ReflectUtil.kt
Normal file
101
ts-core/src/main/kotlin/cn/tursom/core/util/ReflectUtil.kt
Normal file
@ -0,0 +1,101 @@
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.jvm.internal.PropertyReference
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object ReflectUtil {
|
||||
val receiverField: Field by lazy {
|
||||
kotlin.jvm.internal.CallableReference::class.java.getDeclaredField("receiver").apply { isAccessible = true }
|
||||
}
|
||||
val ownerField: Field by lazy {
|
||||
kotlin.jvm.internal.CallableReference::class.java.getDeclaredField("owner").apply { isAccessible = true }
|
||||
}
|
||||
}
|
||||
|
||||
inline fun Class<*>.forAllFields(action: (Field) -> Unit) {
|
||||
allFieldsSequence.forEach(action)
|
||||
}
|
||||
|
||||
val Class<*>.allFields: List<Field>
|
||||
get() {
|
||||
val fieldList = ArrayList<Field>()
|
||||
forAllFields(fieldList::add)
|
||||
return fieldList
|
||||
}
|
||||
|
||||
val Class<*>.allFieldsSequence: Sequence<Field>
|
||||
get() = sequence {
|
||||
var clazz = this@allFieldsSequence
|
||||
while (clazz != Any::class.java) {
|
||||
clazz.declaredFields.forEach { field ->
|
||||
yield(field)
|
||||
}
|
||||
clazz = clazz.superclass
|
||||
}
|
||||
}
|
||||
|
||||
fun Class<*>.getFieldForAll(name: String): Field? {
|
||||
forAllFields {
|
||||
if (it.name == name) return it
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
inline fun Class<*>.forAllMethods(action: (Method) -> Unit) {
|
||||
allMethodsSequence.forEach(action)
|
||||
}
|
||||
|
||||
fun Class<*>.getMethodForAll(name: String, vararg parameterTypes: Class<*>?): Method? {
|
||||
forAllMethods {
|
||||
if (it.name == name && parameterTypes.contentEquals(it.parameterTypes)) return it
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
val Class<*>.allMethods: List<Method>
|
||||
get() {
|
||||
val fieldList = ArrayList<Method>()
|
||||
forAllMethods(fieldList::add)
|
||||
return fieldList
|
||||
}
|
||||
|
||||
val Class<*>.allMethodsSequence: Sequence<Method>
|
||||
get() = sequence {
|
||||
var clazz = this@allMethodsSequence
|
||||
while (clazz != Any::class.java) {
|
||||
clazz.declaredMethods.forEach {
|
||||
yield(it)
|
||||
}
|
||||
clazz = clazz.superclass
|
||||
}
|
||||
clazz.declaredMethods.forEach {
|
||||
yield(it)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个 KProperty<*> 对应的对象
|
||||
*/
|
||||
val KProperty<*>.receiver: Any?
|
||||
get() = if (this is PropertyReference) {
|
||||
boundReceiver
|
||||
} else try {
|
||||
ReflectUtil.receiverField.get(this)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
} ?: javaClass.getFieldForAll("receiver")?.let {
|
||||
it.isAccessible = true
|
||||
it.get(this)
|
||||
}
|
||||
|
||||
val KProperty<*>.owner: Class<*>?
|
||||
get() = try {
|
||||
ReflectUtil.ownerField.get(this)?.uncheckedCast<Class<*>>()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
} ?: javaClass.getFieldForAll("owner")?.let {
|
||||
it.isAccessible = true
|
||||
it.get(this)?.castOrNull()
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import cn.tursom.core.reference.FreeSoftReference
|
||||
import com.sun.org.slf4j.internal.LoggerFactory
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.concurrent.ConcurrentLinkedDeque
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
@ -53,12 +53,23 @@ object ShutdownHook {
|
||||
private val availableThreadCount = Runtime.getRuntime().availableProcessors() * 2
|
||||
private val activeThreadCount = AtomicInteger()
|
||||
|
||||
fun addHook(softReference: Boolean = false, hook: () -> Unit): Hook {
|
||||
fun addShutdownHook(hook: () -> Unit): Hook {
|
||||
if (activeThreadCount.incrementAndGet() <= availableThreadCount) {
|
||||
addWorkThread()
|
||||
}
|
||||
|
||||
val reference = if (softReference) SoftHookReference(hook) else HardHookReference(hook)
|
||||
val reference = HardHookReference(hook)
|
||||
|
||||
shutdownHooks.add(reference)
|
||||
return Hook(hook, reference)
|
||||
}
|
||||
|
||||
fun addSoftShutdownHook(hook: () -> Unit): Hook{
|
||||
if (activeThreadCount.incrementAndGet() <= availableThreadCount) {
|
||||
addWorkThread()
|
||||
}
|
||||
|
||||
val reference = SoftHookReference(hook)
|
||||
|
||||
shutdownHooks.add(reference)
|
||||
return Hook(hook, reference)
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService
|
||||
import java.util.concurrent.TimeUnit
|
35
ts-core/src/main/kotlin/cn/tursom/core/util/StackUtil.kt
Normal file
35
ts-core/src/main/kotlin/cn/tursom/core/util/StackUtil.kt
Normal file
@ -0,0 +1,35 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package cn.tursom.core.util
|
||||
|
||||
private object StackUtil {
|
||||
val stackWalker: StackWalker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE)
|
||||
}
|
||||
|
||||
fun getCallerClass(thisClassName: List<String>): Class<*>? {
|
||||
var clazz: Class<*>?
|
||||
var callStackDepth = 1
|
||||
do {
|
||||
clazz = getCallerClass(callStackDepth++)
|
||||
val clazzName = clazz?.name
|
||||
if (clazzName != "cn.tursom.core.UtilsKt" && clazzName !in thisClassName) {
|
||||
break
|
||||
}
|
||||
} while (clazz != null)
|
||||
return clazz
|
||||
}
|
||||
|
||||
fun getCallerClassName(thisClassName: List<String>): String? {
|
||||
return getCallerClass(thisClassName)?.name
|
||||
}
|
||||
|
||||
fun getCallerClass(callStackDepth: Int): Class<*>? {
|
||||
return StackUtil.stackWalker.walk { frameStream ->
|
||||
frameStream.skip((callStackDepth).toLong()).findFirst().orElse(null)?.declaringClass
|
||||
}
|
||||
}
|
||||
|
||||
fun getCallerClassName(callStackDepth: Int): String? {
|
||||
return getCallerClass(callStackDepth)?.name
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
object TextColor {
|
||||
const val reset = "\u001b[0m"
|
@ -1,19 +1,19 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class ThreadLocalSimpleDateFormat(
|
||||
val format: String = "YYYY-MM-dd'T'HH:mm:ssZZ",
|
||||
) : SimpThreadLocal<SimpleDateFormat>(null, {
|
||||
SimpleDateFormat(format)
|
||||
}) {
|
||||
) : ThreadLocal<SimpleDateFormat>() {
|
||||
fun format(date: Any) = get().format(date)
|
||||
fun format(date: Date) = get().format(date)
|
||||
fun parse(date: String) = get().parse(date)
|
||||
|
||||
fun now() = format(System.currentTimeMillis())
|
||||
|
||||
override fun initialValue() = SimpleDateFormat(format)
|
||||
|
||||
companion object {
|
||||
val iso8601 = ThreadLocalSimpleDateFormat("YYYY-MM-dd'T'HH:mm:ssZZ")
|
||||
val standard = ThreadLocalSimpleDateFormat("YYYY-MM-dd HH:mm:ss")
|
@ -1,11 +1,11 @@
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import sun.misc.Unsafe
|
||||
|
||||
object Unsafe {
|
||||
val unsafe: Unsafe = Unsafe::class.java.getStaticField("theUnsafe") as Unsafe
|
||||
|
||||
operator fun <T> invoke(action: cn.tursom.core.Unsafe.() -> T): T = this.action()
|
||||
operator fun <T> invoke(action: cn.tursom.core.util.Unsafe.() -> T): T = this.action()
|
||||
|
||||
fun Any.getField(name: String): Any? {
|
||||
val clazz = this::class.java
|
||||
@ -38,4 +38,4 @@ object Unsafe {
|
||||
field.isAccessible = true
|
||||
return field.get(null)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package cn.tursom.core.util
|
||||
|
||||
fun <T, R> with(v: T, action: (T) -> R): () -> R = { action(v) }
|
||||
fun <T1, T2, R> with(v1: T1, v2: T2, action: (T1, T2) -> R): () -> R = { action(v1, v2) }
|
@ -1,6 +1,6 @@
|
||||
@file:Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -1,19 +1,15 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package cn.tursom.core
|
||||
package cn.tursom.core.util
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import sun.reflect.Reflection
|
||||
import java.io.*
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.Proxy
|
||||
import java.net.URLDecoder
|
||||
import java.net.URLEncoder
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.util.*
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.zip.Deflater
|
||||
@ -26,10 +22,8 @@ import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.resumeWithException
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
import kotlin.experimental.and
|
||||
import kotlin.jvm.internal.PropertyReference
|
||||
import kotlin.random.Random
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.full.companionObjectInstance
|
||||
import kotlin.reflect.full.memberProperties
|
||||
@ -40,7 +34,7 @@ object Utils {
|
||||
const val dollar = '$'
|
||||
val random = Random(System.currentTimeMillis())
|
||||
|
||||
val bufferThreadLocal = SimpThreadLocal { ByteArray(1024) }
|
||||
val bufferThreadLocal = ThreadLocal { ByteArray(1024) }
|
||||
|
||||
@Suppress("unused", "SpellCheckingInspection")
|
||||
val gson: Gson by lazy {
|
||||
@ -75,13 +69,6 @@ object Utils {
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal val DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray()
|
||||
|
||||
val receiverField: Field by lazy {
|
||||
kotlin.jvm.internal.CallableReference::class.java.getDeclaredField("receiver").apply { isAccessible = true }
|
||||
}
|
||||
val ownerField: Field by lazy {
|
||||
kotlin.jvm.internal.CallableReference::class.java.getDeclaredField("owner").apply { isAccessible = true }
|
||||
}
|
||||
|
||||
val strValue = String::class.java.declaredFields.firstOrNull {
|
||||
it.type == CharArray::class.java
|
||||
}?.also {
|
||||
@ -90,6 +77,8 @@ object Utils {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Any> ThreadLocal(new: () -> T) = ThreadLocal.withInitial(new)
|
||||
|
||||
fun CharArray.packageToString(): String {
|
||||
return if (size < 64 * 1024 || Utils.strValue == null) {
|
||||
String(this)
|
||||
@ -267,14 +256,11 @@ fun ByteArray.base64UrlDecode(): ByteArray = Base64.getUrlDecoder().decode(this)
|
||||
fun String.base64MimeDecode(): String = Base64.getMimeDecoder().decode(this).toUTF8String()
|
||||
fun ByteArray.base64MimeDecode(): ByteArray = Base64.getMimeDecoder().decode(this)
|
||||
|
||||
fun String.digest(type: String) = toByteArray().digest(type)?.toHexString()
|
||||
fun String.digest(type: String) = toByteArray().digest(type).toHexString()
|
||||
|
||||
fun ByteArray.digest(type: String) = try {
|
||||
fun ByteArray.digest(type: String): ByteArray {
|
||||
val instance = MessageDigest.getInstance(type)
|
||||
instance.digest(this)
|
||||
} catch (e: NoSuchAlgorithmException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
return instance.digest(this)
|
||||
}
|
||||
|
||||
fun <A : Annotation, V : Any> A.changeAnnotationValue(field: KProperty1<A, V>, value: V): Boolean {
|
||||
@ -320,92 +306,6 @@ inline fun usingNanoTime(action: () -> Unit): Long {
|
||||
return t2 - t1
|
||||
}
|
||||
|
||||
inline fun Class<*>.forAllFields(action: (Field) -> Unit) {
|
||||
allFieldsSequence.forEach(action)
|
||||
}
|
||||
|
||||
val Class<*>.allFields: List<Field>
|
||||
get() {
|
||||
val fieldList = ArrayList<Field>()
|
||||
forAllFields(fieldList::add)
|
||||
return fieldList
|
||||
}
|
||||
|
||||
val Class<*>.allFieldsSequence: Sequence<Field>
|
||||
get() = sequence {
|
||||
var clazz = this@allFieldsSequence
|
||||
while (clazz != Any::class.java) {
|
||||
clazz.declaredFields.forEach { field ->
|
||||
yield(field)
|
||||
}
|
||||
clazz = clazz.superclass
|
||||
}
|
||||
}
|
||||
|
||||
fun Class<*>.getFieldForAll(name: String): Field? {
|
||||
forAllFields {
|
||||
if (it.name == name) return it
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
inline fun Class<*>.forAllMethods(action: (Method) -> Unit) {
|
||||
allMethodsSequence.forEach(action)
|
||||
}
|
||||
|
||||
fun Class<*>.getMethodForAll(name: String, vararg parameterTypes: Class<*>?): Method? {
|
||||
forAllMethods {
|
||||
if (it.name == name && parameterTypes.contentEquals(it.parameterTypes)) return it
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
val Class<*>.allMethods: List<Method>
|
||||
get() {
|
||||
val fieldList = ArrayList<Method>()
|
||||
forAllMethods(fieldList::add)
|
||||
return fieldList
|
||||
}
|
||||
|
||||
val Class<*>.allMethodsSequence: Sequence<Method>
|
||||
get() = sequence {
|
||||
var clazz = this@allMethodsSequence
|
||||
while (clazz != Any::class.java) {
|
||||
clazz.declaredMethods.forEach {
|
||||
yield(it)
|
||||
}
|
||||
clazz = clazz.superclass
|
||||
}
|
||||
clazz.declaredMethods.forEach {
|
||||
yield(it)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个 KProperty<*> 对应的对象
|
||||
*/
|
||||
val KProperty<*>.receiver: Any?
|
||||
get() = if (this is PropertyReference) {
|
||||
boundReceiver
|
||||
} else try {
|
||||
Utils.receiverField.get(this)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
} ?: javaClass.getFieldForAll("receiver")?.let {
|
||||
it.isAccessible = true
|
||||
it.get(this)
|
||||
}
|
||||
|
||||
val KProperty<*>.owner: Class<*>?
|
||||
get() = try {
|
||||
Utils.ownerField.get(this)?.uncheckedCast<Class<*>>()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
} ?: javaClass.getFieldForAll("owner")?.let {
|
||||
it.isAccessible = true
|
||||
it.get(this)?.castOrNull()
|
||||
}
|
||||
|
||||
tailrec fun Long.base62(sBuilder: StringBuilder = StringBuilder()): String {
|
||||
return if (this == 0L) {
|
||||
sBuilder.reverse().toString()
|
||||
@ -529,32 +429,6 @@ fun mongoLegal(value: Any?) = when {
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun getCallerClass(thisClassName: List<String>): Class<*>? {
|
||||
var clazz: Class<*>?
|
||||
var callStackDepth = 1
|
||||
do {
|
||||
clazz = getCallerClass(callStackDepth++)
|
||||
val clazzName = clazz?.name
|
||||
if (clazzName != "cn.tursom.core.UtilsKt" && clazzName !in thisClassName) {
|
||||
break
|
||||
}
|
||||
} while (clazz != null)
|
||||
return clazz
|
||||
}
|
||||
|
||||
fun getCallerClassName(thisClassName: List<String>): String? {
|
||||
return getCallerClass(thisClassName)?.name
|
||||
}
|
||||
|
||||
fun getCallerClass(callStackDepth: Int): Class<*>? {
|
||||
@Suppress("DEPRECATION")
|
||||
return Reflection.getCallerClass(callStackDepth)
|
||||
}
|
||||
|
||||
fun getCallerClassName(callStackDepth: Int): String? {
|
||||
return getCallerClass(callStackDepth)?.name
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
fun CharSequence?.isNotNullOrEmpty(): Boolean {
|
||||
contract {
|
||||
@ -722,3 +596,8 @@ fun StringBuilder(vararg strings: String): StringBuilder {
|
||||
inline fun Throwable.throws(): Nothing {
|
||||
throw this
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline operator fun Throwable.unaryMinus(): Nothing {
|
||||
throw this
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import cn.tursom.core.usingNanoTime
|
||||
import cn.tursom.core.util.usingNanoTime
|
||||
import org.junit.Test
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
@ -9,9 +8,9 @@ dependencies {
|
||||
api(project(":ts-core"))
|
||||
api(project(":ts-core:ts-buffer"))
|
||||
implementation(project(":ts-core:ts-xml"))
|
||||
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.6.0")
|
||||
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)
|
||||
api(group = "com.squareup.okhttp3", name = "okhttp", version = "4.9.3")
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = "4.1.72.Final")
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = nettyVersion)
|
||||
//api(group = "com.squareup.retrofit2", name = "converter-gson", version = "2.9.0")
|
||||
//api(group = "com.squareup.retrofit2", name = "retrofit", version = "2.9.0")
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.tursom.http
|
||||
|
||||
import cn.tursom.core.Utils.gson
|
||||
import cn.tursom.core.coroutine.GlobalScope
|
||||
import cn.tursom.core.coroutine.MainDispatcher
|
||||
import cn.tursom.core.util.Utils.gson
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jsoup.nodes.Document
|
||||
|
@ -1,13 +1,12 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":ts-core:ts-log"))
|
||||
implementation(project(":ts-core"))
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = "4.1.72.Final")
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = nettyVersion)
|
||||
|
||||
testApi(group = "junit", name = "junit", version = "4.13.2")
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
package cn.tursom.core.buffer
|
||||
|
||||
import cn.tursom.core.buffer.impl.ArrayByteBuffer
|
||||
import cn.tursom.core.toBytes
|
||||
import cn.tursom.core.toInt
|
||||
import cn.tursom.core.util.toBytes
|
||||
import cn.tursom.core.util.toInt
|
||||
import java.nio.ByteOrder
|
||||
import java.nio.channels.GatheringByteChannel
|
||||
import java.nio.channels.ReadableByteChannel
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.tursom.core.buffer
|
||||
|
||||
import cn.tursom.core.*
|
||||
import cn.tursom.core.buffer.NioBuffers.readNioBuffers
|
||||
import cn.tursom.core.buffer.NioBuffers.writeNioBuffers
|
||||
import cn.tursom.core.util.*
|
||||
import java.io.Closeable
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.core.buffer
|
||||
|
||||
import cn.tursom.core.Utils
|
||||
import cn.tursom.core.reverseBytes
|
||||
import cn.tursom.core.util.Utils
|
||||
import cn.tursom.core.util.reverseBytes
|
||||
import java.io.OutputStream
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.min
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.core.buffer
|
||||
|
||||
import cn.tursom.core.Utils
|
||||
import cn.tursom.core.forEachIndex
|
||||
import cn.tursom.core.util.Utils
|
||||
import cn.tursom.core.util.forEachIndex
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.nio.ByteOrder
|
||||
|
@ -6,7 +6,7 @@ import cn.tursom.core.buffer.NioBuffers.finishRead
|
||||
import cn.tursom.core.buffer.NioBuffers.finishWrite
|
||||
import cn.tursom.core.buffer.NioBuffers.getReadNioBufferList
|
||||
import cn.tursom.core.buffer.NioBuffers.getWriteNioBufferList
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
|
||||
class ArrayByteBuffer(
|
||||
vararg buffers: ByteBuffer,
|
||||
|
@ -5,7 +5,7 @@ import cn.tursom.core.buffer.ByteBuffer
|
||||
import cn.tursom.core.buffer.ByteBufferExtensionKey
|
||||
import cn.tursom.core.buffer.NioBuffers
|
||||
import cn.tursom.core.reference.FreeReference
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import cn.tursom.log.impl.Slf4jImpl
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.buffer.Unpooled
|
||||
|
@ -9,8 +9,8 @@ package cn.tursom.core.buffer
|
||||
* will support
|
||||
*/
|
||||
|
||||
import cn.tursom.core.Unsafe.unsafe
|
||||
import cn.tursom.core.isStatic
|
||||
import cn.tursom.core.util.Unsafe.unsafe
|
||||
import cn.tursom.core.util.isStatic
|
||||
|
||||
class UnsupportedException : Exception()
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.tursom.core.clone
|
||||
|
||||
import cn.tursom.core.*
|
||||
import cn.tursom.core.datastruct.ArrayMap
|
||||
import cn.tursom.core.reflect.InstantAllocator
|
||||
import cn.tursom.core.util.*
|
||||
import cn.tursom.log.impl.Slf4jImpl
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty1
|
||||
@ -73,7 +73,7 @@ fun <T : Any> List<Any?>.clone(
|
||||
|
||||
/**
|
||||
* 新建并拷贝
|
||||
* @author 王景阔
|
||||
* @author tursom
|
||||
* 创建类型 T 的实例
|
||||
* 并将对象两个的所有同名字段拷贝进新建的实例中
|
||||
* @return 新建的实例
|
||||
|
@ -1,12 +1,12 @@
|
||||
package cn.tursom.core.clone
|
||||
|
||||
import cn.tursom.core.Unsafe
|
||||
import cn.tursom.core.allMemberProperties
|
||||
import cn.tursom.core.datastruct.KPropertyValueMap
|
||||
import cn.tursom.core.datastruct.SoftArrayMap
|
||||
import cn.tursom.core.reflect.InstantAllocator
|
||||
import cn.tursom.core.unaryPlus
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.Unsafe
|
||||
import cn.tursom.core.util.allMemberProperties
|
||||
import cn.tursom.core.util.unaryPlus
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import cn.tursom.log.impl.Slf4jImpl
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.collections.component1
|
||||
|
@ -1,12 +1,11 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":ts-core"))
|
||||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
|
||||
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.core.coroutine
|
||||
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.toHexString
|
||||
import cn.tursom.core.util.cast
|
||||
import cn.tursom.core.util.toHexString
|
||||
import kotlinx.coroutines.Job
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.coroutine
|
||||
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.util.cast
|
||||
import kotlinx.coroutines.ThreadContextElement
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.coroutine
|
||||
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.util.cast
|
||||
import kotlin.coroutines.Continuation
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.coroutine
|
||||
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.util.cast
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
@ -1,13 +1,13 @@
|
||||
package cn.tursom.core.coroutine
|
||||
|
||||
import cn.tursom.core.SimpThreadLocal
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.util.ThreadLocal
|
||||
import cn.tursom.core.util.cast
|
||||
import kotlinx.coroutines.*
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
object CurrentThreadCoroutineScope {
|
||||
private val eventLoopThreadLocal: SimpThreadLocal<CoroutineDispatcher> = SimpThreadLocal {
|
||||
private val eventLoopThreadLocal: ThreadLocal<CoroutineDispatcher> = ThreadLocal {
|
||||
newBlockingEventLoop()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.coroutine
|
||||
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.util.cast
|
||||
import kotlinx.coroutines.ExecutorCoroutineDispatcher
|
||||
import kotlinx.coroutines.MainCoroutineDispatcher
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
package cn.tursom.core.coroutine
|
||||
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.forAllFields
|
||||
import cn.tursom.core.isInheritanceFrom
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.cast
|
||||
import cn.tursom.core.util.forAllFields
|
||||
import cn.tursom.core.util.isInheritanceFrom
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.ReceiveChannel
|
||||
import kotlinx.coroutines.channels.produce
|
||||
|
@ -1,12 +1,11 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":ts-core"))
|
||||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
|
||||
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.coroutine.lock
|
||||
|
||||
import cn.tursom.core.Unsafe.unsafe
|
||||
import cn.tursom.core.util.Unsafe.unsafe
|
||||
import java.io.Closeable
|
||||
import kotlin.coroutines.Continuation
|
||||
import kotlin.coroutines.resume
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
package cn.tursom.core.curry
|
||||
|
||||
import cn.tursom.core.allMethods
|
||||
import cn.tursom.core.plus
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.allMethods
|
||||
import cn.tursom.core.util.plus
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
|
||||
|
||||
class VarargCurrying<A, R>(
|
||||
|
@ -1,8 +1,5 @@
|
||||
package cn.tursom.core.curry
|
||||
|
||||
import cn.tursom.core.allMemberPropertiesSequence
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
fun example(f: (Int) -> (Int) -> (Int) -> Int) {
|
||||
f(1)(2)(3)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.curry
|
||||
|
||||
import cn.tursom.core.removeLastChars
|
||||
import cn.tursom.core.util.removeLastChars
|
||||
import org.junit.Test
|
||||
|
||||
class CurryBuilder {
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.datastruct
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
open class ArrayMap<K, V>(initialCapacity: Int = 16) : SimpMap<K, V> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.core.datastruct
|
||||
|
||||
import cn.tursom.core.hash.MurmurHash3
|
||||
import cn.tursom.core.toByteArray
|
||||
import cn.tursom.core.util.toByteArray
|
||||
import kotlin.math.pow
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.datastruct
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
|
||||
class DefaultValueMap<K, V>(
|
||||
private val map: Map<K, V?>,
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.datastruct
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
|
||||
class DefaultValueMutableMap<K, V>(
|
||||
private val map: MutableMap<K, V?>,
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.datastruct
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.full.memberProperties
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.datastruct
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
open class ParallelArrayMap<K, V>(initialCapacity: Int = 16) : SimpMap<K, V> {
|
||||
|
@ -1,12 +1,11 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":ts-core"))
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = "4.1.72.Final")
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = nettyVersion)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class FilterDelegatedField<in T, V>(
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class NotNullDelegatedField<in T, out V : Any>(
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class NotNullMutableDelegatedField<in T, V : Any>(
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.final
|
||||
import cn.tursom.core.getFieldForAll
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.final
|
||||
import cn.tursom.core.util.getFieldForAll
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class ReflectionDelegatedField<in T, V>(
|
||||
|
@ -1,29 +0,0 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.SimpThreadLocal
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import kotlin.reflect.KProperty0
|
||||
|
||||
class SimpThreadLocalMutableDelegatedField<in T, V : Any>(
|
||||
private val threadLocal: SimpThreadLocal<V>,
|
||||
) : MutableDelegatedField<T, V> {
|
||||
constructor(new: () -> V) : this(SimpThreadLocal(new = new))
|
||||
|
||||
|
||||
override fun <K> get(key: DelegatedFieldAttachmentKey<K>): K? {
|
||||
return if (key == Companion || key == ThreadLocalMutableDelegatedField) {
|
||||
threadLocal.uncheckedCast()
|
||||
} else {
|
||||
super.get(key)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setValue(value: V) = threadLocal.set(value)
|
||||
override fun getValue(): V = threadLocal.get()
|
||||
|
||||
companion object : DelegatedFieldAttachmentKey<SimpThreadLocal<*>> {
|
||||
fun <T : Any> getKey() = this.uncheckedCast<DelegatedFieldAttachmentKey<SimpThreadLocal<T>>>()
|
||||
fun <T : Any> getKey(property: KProperty0<T>) =
|
||||
this.uncheckedCast<DelegatedFieldAttachmentKey<SimpThreadLocal<T>>>()
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import kotlin.reflect.KProperty0
|
||||
|
||||
class ThreadLocalMutableDelegatedField<in T, V>(
|
||||
private val threadLocal: ThreadLocal<V?> = ThreadLocal(),
|
||||
private val threadLocal: ThreadLocal<V> = ThreadLocal(),
|
||||
) : MutableDelegatedField<T, V?> {
|
||||
|
||||
override fun <K> get(key: DelegatedFieldAttachmentKey<K>): K? {
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
package cn.tursom.core.delegation
|
||||
|
||||
import cn.tursom.core.SimpThreadLocal
|
||||
import cn.tursom.core.castOrNull
|
||||
import cn.tursom.core.receiver
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.castOrNull
|
||||
import cn.tursom.core.util.receiver
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.locks.Lock
|
||||
import java.util.concurrent.locks.ReadWriteLock
|
||||
@ -91,7 +90,7 @@ fun <T, V> MutableDelegatedField<T, V>.readWriteLocked(readWriteLock: ReadWriteL
|
||||
ReadWriteLockMutableDelegatedField(this, readWriteLock)
|
||||
|
||||
|
||||
fun <T, V> ThreadLocal<V?>.delegated(): MutableDelegatedField<T, V?> = ThreadLocalMutableDelegatedField(this)
|
||||
fun <T, V> ThreadLocal<V>.delegated(): MutableDelegatedField<T, V?> = ThreadLocalMutableDelegatedField(this)
|
||||
fun <T, V> T.delegated(
|
||||
threadLocal: ThreadLocal<V?>,
|
||||
): MutableDelegatedField<T, V?> = ThreadLocalMutableDelegatedField(threadLocal)
|
||||
@ -109,16 +108,6 @@ fun <T, V> T.threadLocalDelegated(type: Class<out V?>): MutableDelegatedField<T,
|
||||
fun <T, V : Any> T.threadLocalDelegated(type: KClass<V>): MutableDelegatedField<T, V?> =
|
||||
ThreadLocalMutableDelegatedField()
|
||||
|
||||
fun <T, V : Any> SimpThreadLocal<V>.delegated(): MutableDelegatedField<T, V> =
|
||||
SimpThreadLocalMutableDelegatedField(this)
|
||||
|
||||
fun <T, V : Any> T.threadLocalDelegated(
|
||||
threadLocal: ThreadLocal<V?> = ThreadLocal(),
|
||||
new: () -> V,
|
||||
): MutableDelegatedField<T, V> = SimpThreadLocalMutableDelegatedField(SimpThreadLocal(threadLocal, new))
|
||||
//fun <T, V> T.threadLocalDelegated(simpThreadLocal: SimpThreadLocal<V>): MutableDelegatedField<T, V> =
|
||||
// SimpThreadLocalMutableDelegatedField(simpThreadLocal)
|
||||
|
||||
fun <T, V> MutableDelegatedField<T, V>.filter(
|
||||
filter: T.(old: V, new: V) -> Boolean,
|
||||
): MutableDelegatedField<T, V> = FilterDelegatedField(this, filter)
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package cn.tursom.core.delegation.observer
|
||||
import cn.tursom.core.delegation.DecoratorMutableDelegatedField
|
||||
import cn.tursom.core.delegation.DelegatedFieldAttachmentKey
|
||||
import cn.tursom.core.delegation.MutableDelegatedField
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.util.concurrent.ConcurrentLinkedDeque
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
package cn.tursom.core.delegation.observer
|
||||
|
||||
import cn.tursom.core.UncheckedCast
|
||||
import cn.tursom.core.cast
|
||||
import cn.tursom.core.delegation.*
|
||||
import cn.tursom.core.receiver
|
||||
import cn.tursom.core.util.UncheckedCast
|
||||
import cn.tursom.core.util.cast
|
||||
import cn.tursom.core.util.receiver
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
import kotlin.reflect.KProperty0
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.core.encrypt
|
||||
|
||||
import cn.tursom.core.Unsafe
|
||||
import cn.tursom.core.uncheckedCast
|
||||
import cn.tursom.core.util.Unsafe
|
||||
import cn.tursom.core.util.uncheckedCast
|
||||
import java.security.KeyFactory
|
||||
import java.security.KeyPair
|
||||
import java.security.KeyPairGenerator
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.tursom.core.encrypt
|
||||
|
||||
import cn.tursom.core.Utils
|
||||
import cn.tursom.core.datastruct.concurrent.BlockingArrayList
|
||||
import cn.tursom.core.pool.Pool
|
||||
import cn.tursom.core.util.Utils
|
||||
|
||||
open class EncryptPool<T : Encrypt>(
|
||||
initSize: Int = 0,
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":"))
|
||||
compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.9")
|
||||
compileOnly(group = "com.fasterxml.jackson.core", name = "jackson-core", version = "2.13.1")
|
||||
compileOnly(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = "2.13.1")
|
||||
compileOnly(group = "com.fasterxml.jackson.core", name = "jackson-core", version = "2.15.3")
|
||||
compileOnly(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = "2.15.3")
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.tursom.core.json
|
||||
|
||||
import com.sun.org.apache.xalan.internal.lib.ExsltMath.power
|
||||
import kotlin.math.pow
|
||||
|
||||
object Json {
|
||||
class JsonFormatException(message: String? = null) : RuntimeException(message) {
|
||||
@ -41,10 +41,12 @@ object Json {
|
||||
content.index += 4
|
||||
true
|
||||
}
|
||||
|
||||
content.json.startsWith("false", content.index) -> {
|
||||
content.index += 5
|
||||
false
|
||||
}
|
||||
|
||||
else -> throw JsonFormatException(content)
|
||||
}
|
||||
|
||||
@ -100,7 +102,7 @@ object Json {
|
||||
}
|
||||
}
|
||||
content.index++
|
||||
number = number.toDouble() * power(10.0, parseInt(content).toLong() * if (powerNegative) -1.0 else 1.0)
|
||||
number = number.toDouble() * 10.0.pow(parseInt(content).toLong() * if (powerNegative) -1.0 else 1.0)
|
||||
}
|
||||
return if (negative) when (number) {
|
||||
is Int -> -number
|
||||
@ -129,14 +131,17 @@ object Json {
|
||||
}
|
||||
builder.append(char.toChar())
|
||||
}
|
||||
|
||||
else -> builder.append(content.json[content.index])
|
||||
}
|
||||
content.index++
|
||||
}
|
||||
|
||||
'"' -> {
|
||||
content.index++
|
||||
return builder.toString()
|
||||
}
|
||||
|
||||
else -> builder.append(content.json[content.index++])
|
||||
}
|
||||
throw JsonFormatException(content)
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
id("ts-gradle")
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user