From 1080a32e73de073a3e3f598f38ee066ee284e539 Mon Sep 17 00:00:00 2001 From: tursom Date: Sun, 11 Apr 2021 18:15:58 +0800 Subject: [PATCH] update --- build.gradle | 80 ----- build.gradle.kts | 58 ++++ settings.gradle | 22 -- settings.gradle.kts | 25 ++ .../cn/tursom/core/HeapByteBufferUtil.kt | 26 -- src/main/kotlin/cn/tursom/core/RandomCode.kt | 24 -- .../cn/tursom/core/datastruct/ContainMap.kt | 30 -- .../datastruct/KPropertyEntriesIterator.kt | 15 - .../cn/tursom/core/datastruct/ReadWriteMap.kt | 22 -- .../cn/tursom/core/datastruct/ReversedList.kt | 48 --- .../cn/tursom/core/datastruct/SetMap.kt | 66 ----- .../cn/tursom/core/datastruct/SimpMap.kt | 34 --- .../cn/tursom/core/datastruct/SoftArrayMap.kt | 21 -- .../async/interfaces/AsyncCollection.kt | 10 - .../datastruct/async/interfaces/AsyncMap.kt | 24 -- .../async/interfaces/AsyncPotableMap.kt | 9 - .../async/interfaces/AsyncPotableSet.kt | 9 - .../tursom/core/regex/ControlCharRegexUnit.kt | 7 - .../cn/tursom/core/regex/GetMatchingUnit.kt | 8 - .../kotlin/cn/tursom/core/regex/RegexMaker.kt | 278 ------------------ .../kotlin/cn/tursom/core/regex/RegexUnit.kt | 7 - .../cn/tursom/core/regex/RepeatRegexUnit.kt | 46 --- .../cn/tursom/core/regex/StringRegexUnit.kt | 13 - .../cn/tursom/core/regex/UnitListRegexUnit.kt | 20 -- ts-core/build.gradle.kts | 12 + .../kotlin/cn/tursom/core/ClassLoaderUtil.kt | 13 +- .../main/kotlin/cn/tursom/core/Collections.kt | 0 .../cn/tursom/core/CurrentTimeMillisClock.kt | 2 - .../main/kotlin/cn/tursom/core/Disposable.kt | 0 .../cn/tursom/core/EnumTypeAdapterFactory.kt | 0 .../main/kotlin/cn/tursom/core/Finalized.kt | 0 .../cn/tursom/core/GsonDataTypeAdaptor.kt | 0 .../kotlin/cn/tursom/core/ListClassLoader.kt | 0 .../main/kotlin/cn/tursom/core/Members.kt | 0 .../cn/tursom/core/NonLockLinkedList.kt | 4 +- .../src}/main/kotlin/cn/tursom/core/Parser.kt | 3 - .../main/kotlin/cn/tursom/core/RandomCode.kt | 24 ++ .../kotlin/cn/tursom/core/SimpThreadLocal.kt | 0 .../core/ThreadLocalSimpleDateFormat.kt | 0 .../src}/main/kotlin/cn/tursom/core/Tools.kt | 33 --- .../src}/main/kotlin/cn/tursom/core/Unsafe.kt | 0 .../cn/tursom/core/UpdatableThreadLocal.kt | 0 .../UpdatableThreadLocalSimpleDateFormat.kt | 0 .../main/kotlin/cn/tursom/core/functional.kt | 0 .../tursom/core/regex/ControlCharRegexUnit.kt | 7 + .../cn/tursom/core/regex/GetMatchingUnit.kt | 8 + .../core/regex/LookAheadNegativeAssertUnit.kt | 2 +- .../core/regex/LookAheadPositiveAssertUnit.kt | 2 +- .../regex/LookBehindNegativeAssertUnit.kt | 2 +- .../regex/LookBehindPositiveAssertUnit.kt | 2 +- .../tursom/core/regex/NonGetMatchingUnit.kt | 2 +- .../kotlin/cn/tursom/core/regex/RegexMaker.kt | 278 ++++++++++++++++++ .../kotlin/cn/tursom/core/regex/RegexUnit.kt | 7 + .../cn/tursom/core/regex/RepeatRegexUnit.kt | 46 +++ .../cn/tursom/core/regex/StringRegexUnit.kt | 13 + .../cn/tursom/core/regex/UnitListRegexUnit.kt | 20 ++ .../cn/tursom/core/regex/UnitRegexUnit.kt | 6 +- .../core/storage/BufferedStorageHandler.kt | 1 + .../core/storage/InstantStorageHandler.kt | 0 .../cn/tursom/core/storage/StorageHandler.kt | 0 .../core/storage/ThreadPoolStorageHandler.kt | 0 .../cn/tursom/core/timer/NonLockTaskQueue.kt | 8 +- .../core/timer/SynchronizedTaskQueue.kt | 10 +- .../kotlin/cn/tursom/core/timer/TaskQueue.kt | 0 .../main/kotlin/cn/tursom/core/timer/Timer.kt | 0 .../kotlin/cn/tursom/core/timer/TimerTask.kt | 0 .../kotlin/cn/tursom/core/timer/WheelTimer.kt | 0 {src => ts-core/src}/test/kotlin/main.kt | 0 ts-core/ts-buffer/build.gradle.kts | 11 + .../main/kotlin/cn/tursom/core/AsyncFile.kt | 0 .../main/kotlin/cn/tursom/core/DataOperate.kt | 0 .../main/kotlin/cn/tursom/core/FlvChecker.kt | 0 .../cn/tursom/core/HeapByteBufferUtil.kt | 26 ++ .../main/kotlin/cn/tursom/core/HttpRequest.kt | 0 .../main/kotlin/cn/tursom/core/Snowflake.kt | 6 +- .../cn/tursom/core/buffer/ByteBuffer.kt | 0 .../tursom/core/buffer/ByteBufferExtension.kt | 0 .../core/buffer/ClosedBufferException.kt | 7 +- .../tursom/core/buffer/MarkableByteBuffer.kt | 0 .../tursom/core/buffer/MultipleByteBuffer.kt | 2 - .../cn/tursom/core/buffer/ProxyByteBuffer.kt | 0 .../core/buffer/impl/ArrayByteBuffer.kt | 1 - .../core/buffer/impl/CloseSafeByteBuffer.kt | 0 .../core/buffer/impl/DirectByteBuffer.kt | 0 .../tursom/core/buffer/impl/HeapByteBuffer.kt | 2 +- .../tursom/core/buffer/impl/ListByteBuffer.kt | 1 + .../core/buffer/impl/MarkedByteBuffer.kt | 2 +- .../core/buffer/impl/SplitByteBuffer.kt | 0 .../kotlin/cn/tursom/core/stream/IOStream.kt | 0 .../cn/tursom/core/stream/InputStream.kt | 0 .../cn/tursom/core/stream/OutputStream.kt | 0 .../kotlin/cn/tursom/core/stream/Stream.kt | 0 .../tursom/core/stream/SuspendInputStream.kt | 0 .../core/stream/impl/ByteBufferIOStream.kt | 0 .../core/stream/impl/ByteBufferInputStream.kt | 0 .../stream/impl/ByteBufferOutputStream.kt | 0 .../tursom/core/stream/impl/BytesIOStream.kt | 0 .../core/stream/impl/BytesInputStream.kt | 0 .../core/stream/impl/BytesOutputStream.kt | 0 .../core/stream/impl/JavaInputStream.kt | 0 .../core/stream/impl/JavaInputStreamProxy.kt | 0 .../core/stream/impl/JavaOutputStream.kt | 0 .../tursom/core/stream/impl/PairIOStream.kt | 0 ts-core/ts-datastruct/build.gradle.kts | 13 + .../cn/tursom/core/datastruct/AbstractList.kt | 0 .../core/datastruct/AbstractListIterator.kt | 0 .../core/datastruct/AbstractMutableList.kt | 0 .../cn/tursom/core/datastruct/ArrayBitSet.kt | 0 .../cn/tursom/core/datastruct/ArrayMap.kt | 4 +- .../cn/tursom/core/datastruct/AtomicBitSet.kt | 7 +- .../cn/tursom/core/datastruct/BloomFilter.kt | 7 +- .../core/datastruct/ComparableArrayMap.kt | 0 .../cn/tursom/core/datastruct/ContainMap.kt | 30 ++ .../tursom/core/datastruct/DefaultValueMap.kt | 1 - .../core/datastruct/DefaultValueMutableMap.kt | 1 - .../datastruct/KPropertyEntriesIterator.kt | 16 + .../KPropertyValueCollectionIterator.kt | 6 +- .../cn/tursom/core/datastruct/LongBitSet.kt | 6 +- .../tursom/core/datastruct/MutableSubList.kt | 0 .../core/datastruct/ParallelArrayMap.kt | 0 .../cn/tursom/core/datastruct/ReadWriteMap.kt | 22 ++ .../cn/tursom/core/datastruct/ReversedList.kt | 48 +++ .../cn/tursom/core/datastruct/SetMap.kt | 66 +++++ .../cn/tursom/core/datastruct/SimpHashMap.kt | 18 +- .../cn/tursom/core/datastruct/SimpMap.kt | 34 +++ .../cn/tursom/core/datastruct/SoftArrayMap.kt | 21 ++ .../cn/tursom/core/datastruct/StepList.kt | 0 .../tursom/core/datastruct/StringRadixTree.kt | 7 +- .../async/interfaces/AsyncCollection.kt | 10 + .../datastruct/async/interfaces/AsyncMap.kt | 24 ++ .../async/interfaces/AsyncPotableMap.kt | 9 + .../async/interfaces/AsyncPotableSet.kt | 9 + .../datastruct/async/interfaces/AsyncSet.kt | 0 .../concurrent/BlockingArrayList.kt | 0 .../concurrent/BlockingLinkedList.kt | 0 .../datastruct/concurrent/BlockingList.kt | 0 .../concurrent/ConcurrentLinkedList.kt | 0 .../kotlin/cn/tursom/core/datastruct/tools.kt | 31 ++ ts-core/ts-encrypt/build.gradle.kts | 12 + .../src}/kotlin/cn/tursom/core/encrypt/AES.kt | 9 +- .../kotlin/cn/tursom/core/encrypt/AESPool.kt | 0 .../core/encrypt/AbstractPublicKeyEncrypt.kt | 7 +- .../encrypt/BlockCipherModeOfOperation.kt | 0 .../src}/kotlin/cn/tursom/core/encrypt/DSA.kt | 4 +- .../src}/kotlin/cn/tursom/core/encrypt/ECC.kt | 0 .../kotlin/cn/tursom/core/encrypt/Encrypt.kt | 17 +- .../cn/tursom/core/encrypt/EncryptPool.kt | 0 .../tursom/core/encrypt/PublicKeyEncrypt.kt | 0 .../src}/kotlin/cn/tursom/core/encrypt/RSA.kt | 0 .../kotlin/cn/tursom/core/encrypt/RSAPool.kt | 0 ts-core/ts-hash/build.gradle.kts | 13 + .../kotlin/cn/tursom/core/hash/MurmurHash3.kt | 19 +- ts-core/ts-pool/build.gradle.kts | 12 + .../cn/tursom/core/RewriteFlvChecker.kt | 19 +- .../tursom/core/buffer}/InstantByteBuffer.kt | 4 +- .../tursom/core/buffer}/PooledByteBuffer.kt | 2 +- .../cn/tursom/core/pool/AbstractMemoryPool.kt | 0 .../cn/tursom/core/pool/DirectMemoryPool.kt | 0 .../tursom/core/pool/ExpandableMemoryPool.kt | 0 .../cn/tursom/core/pool/HeapMemoryPool.kt | 0 .../cn/tursom/core/pool/InstantMemoryPool.kt | 0 .../kotlin/cn/tursom/core/pool/LinkedPool.kt | 0 .../core/pool/LongBitSetAbstractMemoryPool.kt | 2 +- .../core/pool/LongBitSetDirectMemoryPool.kt | 0 .../core/pool/LongBitSetHeapMemoryPool.kt | 2 +- .../cn/tursom/core/pool/MarkedMemoryPool.kt | 0 .../kotlin/cn/tursom/core/pool/MemoryPool.kt | 0 .../main/kotlin/cn/tursom/core/pool/Pool.kt | 0 .../tursom/core/pool/ScalabilityMemoryPool.kt | 1 + .../tursom/core/pool/ThreadLocalMemoryPool.kt | 0 .../pool/ThreadUnsafeAbstractMemoryPool.kt | 2 +- .../core/pool/ThreadUnsafeDirectMemoryPool.kt | 0 .../core/pool/ThreadUnsafeHeapMemoryPool.kt | 0 173 files changed, 1051 insertions(+), 929 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt delete mode 100644 src/main/kotlin/cn/tursom/core/RandomCode.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt delete mode 100644 src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt delete mode 100644 src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt delete mode 100644 src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt delete mode 100644 src/main/kotlin/cn/tursom/core/regex/RegexMaker.kt delete mode 100644 src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt delete mode 100644 src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt delete mode 100644 src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt delete mode 100644 src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt create mode 100644 ts-core/build.gradle.kts rename {src => ts-core/src}/main/kotlin/cn/tursom/core/ClassLoaderUtil.kt (95%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/Collections.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/CurrentTimeMillisClock.kt (81%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/Disposable.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/EnumTypeAdapterFactory.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/Finalized.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/GsonDataTypeAdaptor.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/ListClassLoader.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/Members.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/NonLockLinkedList.kt (91%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/Parser.kt (98%) create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/RandomCode.kt rename {src => ts-core/src}/main/kotlin/cn/tursom/core/SimpThreadLocal.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/ThreadLocalSimpleDateFormat.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/Tools.kt (92%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/Unsafe.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/UpdatableThreadLocal.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/UpdatableThreadLocalSimpleDateFormat.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/functional.kt (100%) create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt rename {src => ts-core/src}/main/kotlin/cn/tursom/core/regex/LookAheadNegativeAssertUnit.kt (65%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/regex/LookAheadPositiveAssertUnit.kt (66%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/regex/LookBehindNegativeAssertUnit.kt (65%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/regex/LookBehindPositiveAssertUnit.kt (65%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/regex/NonGetMatchingUnit.kt (63%) create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/regex/RegexMaker.kt create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt create mode 100644 ts-core/src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt rename {src => ts-core/src}/main/kotlin/cn/tursom/core/regex/UnitRegexUnit.kt (51%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/storage/BufferedStorageHandler.kt (99%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/storage/InstantStorageHandler.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/storage/StorageHandler.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/storage/ThreadPoolStorageHandler.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/timer/NonLockTaskQueue.kt (89%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/timer/SynchronizedTaskQueue.kt (87%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/timer/TaskQueue.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/timer/Timer.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/timer/TimerTask.kt (100%) rename {src => ts-core/src}/main/kotlin/cn/tursom/core/timer/WheelTimer.kt (100%) rename {src => ts-core/src}/test/kotlin/main.kt (100%) create mode 100644 ts-core/ts-buffer/build.gradle.kts rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/AsyncFile.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/DataOperate.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/FlvChecker.kt (100%) create mode 100644 ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/HttpRequest.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/Snowflake.kt (96%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/ByteBufferExtension.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/ClosedBufferException.kt (72%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/MarkableByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/MultipleByteBuffer.kt (99%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/ProxyByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/impl/ArrayByteBuffer.kt (80%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/impl/CloseSafeByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/impl/DirectByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/impl/HeapByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/impl/ListByteBuffer.kt (99%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/impl/MarkedByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/buffer/impl/SplitByteBuffer.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/IOStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/InputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/OutputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/Stream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/SuspendInputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/ByteBufferIOStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/ByteBufferInputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/ByteBufferOutputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/BytesIOStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/BytesInputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/BytesOutputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/JavaInputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/JavaInputStreamProxy.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/JavaOutputStream.kt (100%) rename {src => ts-core/ts-buffer/src}/main/kotlin/cn/tursom/core/stream/impl/PairIOStream.kt (100%) create mode 100644 ts-core/ts-datastruct/build.gradle.kts rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/AbstractList.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/AbstractListIterator.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/AbstractMutableList.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/ArrayBitSet.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/ArrayMap.kt (98%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/AtomicBitSet.kt (97%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/BloomFilter.kt (94%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/ComparableArrayMap.kt (100%) create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/DefaultValueMap.kt (99%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/DefaultValueMutableMap.kt (98%) create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/KPropertyValueCollectionIterator.kt (52%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/LongBitSet.kt (91%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/MutableSubList.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/ParallelArrayMap.kt (100%) create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/SimpHashMap.kt (68%) create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/StepList.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/StringRadixTree.kt (98%) create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncSet.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingArrayList.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingLinkedList.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingList.kt (100%) rename {src => ts-core/ts-datastruct/src}/main/kotlin/cn/tursom/core/datastruct/concurrent/ConcurrentLinkedList.kt (100%) create mode 100644 ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/tools.kt create mode 100644 ts-core/ts-encrypt/build.gradle.kts rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/AES.kt (95%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/AESPool.kt (100%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/AbstractPublicKeyEncrypt.kt (97%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/BlockCipherModeOfOperation.kt (100%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/DSA.kt (86%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/ECC.kt (100%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/Encrypt.kt (72%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/EncryptPool.kt (100%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/PublicKeyEncrypt.kt (100%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/RSA.kt (100%) rename {src/main => ts-core/ts-encrypt/src}/kotlin/cn/tursom/core/encrypt/RSAPool.kt (100%) create mode 100644 ts-core/ts-hash/build.gradle.kts rename {src => ts-core/ts-hash/src}/main/kotlin/cn/tursom/core/hash/MurmurHash3.kt (94%) create mode 100644 ts-core/ts-pool/build.gradle.kts rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/RewriteFlvChecker.kt (91%) rename {src/main/kotlin/cn/tursom/core/buffer/impl => ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer}/InstantByteBuffer.kt (86%) rename {src/main/kotlin/cn/tursom/core/buffer/impl => ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer}/PooledByteBuffer.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/AbstractMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/DirectMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/ExpandableMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/HeapMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/InstantMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/LinkedPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/LongBitSetAbstractMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/LongBitSetDirectMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/LongBitSetHeapMemoryPool.kt (93%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/MarkedMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/MemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/Pool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/ScalabilityMemoryPool.kt (99%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/ThreadLocalMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/ThreadUnsafeAbstractMemoryPool.kt (97%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/ThreadUnsafeDirectMemoryPool.kt (100%) rename {src => ts-core/ts-pool/src}/main/kotlin/cn/tursom/core/pool/ThreadUnsafeHeapMemoryPool.kt (100%) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index a3d5487..0000000 --- a/build.gradle +++ /dev/null @@ -1,80 +0,0 @@ -buildscript { - ext.kotlinVersion = '1.4.31' - - repositories { - mavenLocal() - jcenter() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - } -} - -allprojects { - apply plugin: "maven-publish" - apply plugin: 'java' - apply plugin: 'kotlin' - apply plugin: 'maven' - - group 'cn.tursom' - version '0.1' - - sourceCompatibility = 1.8 - - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" - api "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" - api "com.google.code.gson:gson:2.8.2" - testImplementation group: 'junit', name: 'junit', version: '4.12' - } - - compileKotlin { - kotlinOptions.jvmTarget = "1.8" - kotlinOptions.useIR = true - } - compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" - kotlinOptions.useIR = true - } - - //打包源代码 - task sourcesJar(type: Jar, dependsOn: classes) { - //classifier = 'sources' - archiveClassifier.set('sources') - from sourceSets.main.allSource - } - - artifacts { - archives sourcesJar - } - publishing { - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/tursom/TursomServer") - credentials { - //username = project.findProperty("gpr.user") ?: System.getenv("USERNAME") - username = "tursom" - password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD") - } - } - } - publications { - gpr(MavenPublication) { - from(components.java) - } - } - } - sourceSets { - all { - languageSettings { - useExperimentalAnnotation('-Xopt-in=kotlin.RequiresOptIn') - } - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..4e91253 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,58 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +ext["netty.version"] = "4.1.59.Final" +ext["excludeTest"] = { project: Project, tasks: TaskContainer -> + if (project.gradle.startParameter.taskNames.firstOrNull { taskName -> + taskName.endsWith(":test") + } == null) { + tasks { + test { enabled = false } + testClasses { enabled = false } + compileTestJava { enabled = false } + compileTestKotlin { enabled = false } + processTestResources { enabled = false } + } + } +} + + +plugins { + kotlin("jvm") version "1.4.31" +} + +allprojects { + group = "cn.tursom" + version = "0.2" + + repositories { + mavenLocal() + mavenCentral() + } + + tasks.withType { + tasks.withType().configureEach { + kotlinOptions.jvmTarget = "1.8" + kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" + } + + if (project.gradle.startParameter.taskNames.firstOrNull { taskName -> + taskName.endsWith(":test") + } == null) { + tasks.withType { + enabled = false + } + } + } +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + +dependencies { + api(kotlin("stdlib-jdk8")) + api(kotlin("reflect")) + testImplementation(group = "junit", name = "junit", version = "4.12") + + val commonVersion = "1.0.RELEASE" + api("com.ddbes", "common-kotlin", commonVersion) +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index b8462db..0000000 --- a/settings.gradle +++ /dev/null @@ -1,22 +0,0 @@ -rootProject.name = 'TursomServer' -include 'web', 'aop', 'database', 'utils', 'utils:xml', 'utils:async-http', 'web:netty-web' -include 'socket', 'socket:socket-async' -include 'AsyncSocket' -include 'log' -include 'json' -include 'utils:yaml' -include 'web:web-coroutine' -include 'microservices' -include 'database:database-mysql' -include 'database:mongodb' -include 'database:mongodb:mongodb-async' -include 'database:redis' -include 'utils:ws-client' -include 'utils:mail' -include 'utils:csv' -include 'utils:delegation' -include 'utils:observer' -include 'utils:TrafficForward' -include 'utils:performance-test' -include 'utils:math' -include 'utils:json' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..8348b3b --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,25 @@ +rootProject.name = "TursomServer" +include("ts-core", "ts-core:ts-buffer", "ts-core:ts-encrypt", "ts-core:ts-datastruct") +include("ts-core:ts-pool") +include("ts-core:ts-hash") +//include("web", "aop", "database", "utils", "utils:xml", "utils:async-http", "web:netty-web") +//include("socket", "socket:socket-async") +//include("AsyncSocket") +//include("log") +//include("json") +//include("utils:yaml") +//include("web:web-coroutine") +//include("microservices") +//include("database:database-mysql") +//include("database:mongodb") +//include("database:mongodb:mongodb-async") +//include("database:redis") +//include("utils:ws-client") +//include("utils:mail") +//include("utils:csv") +//include("utils:delegation") +//include("utils:observer") +//include("utils:TrafficForward") +//include("utils:performance-test") +//include("utils:math") +//include("utils:json") \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt b/src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt deleted file mode 100644 index 34d15ee..0000000 --- a/src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt +++ /dev/null @@ -1,26 +0,0 @@ -package cn.tursom.core - -import java.nio.ByteBuffer - -/** - * HOOK java.nio.HeapByteBuffer - */ -object HeapByteBufferUtil { - private val field = ByteBuffer::class.java.getDeclaredField("offset") - - init { - field.isAccessible = true - } - - fun wrap(array: ByteArray, offset: Int = 0, size: Int = array.size - offset): ByteBuffer { - val buffer = ByteBuffer.wrap(array, 0, offset + size) - //return if (offset == 0) buffer else { - // buffer.position(offset) - // buffer.slice() - //} - if (offset > 0) field.set(buffer, offset) - return buffer - } - - fun wrap(string: String) = wrap(string.toByteArray()) -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/RandomCode.kt b/src/main/kotlin/cn/tursom/core/RandomCode.kt deleted file mode 100644 index 1711a51..0000000 --- a/src/main/kotlin/cn/tursom/core/RandomCode.kt +++ /dev/null @@ -1,24 +0,0 @@ -package cn.tursom.core - -import java.io.File -import java.util.* - -class RandomCode { - private val randomCode = "${randomInt(10000000, 99999999)}" - - override fun toString(): String { - return randomCode - } - - fun showCode(codeName: String = "passcode", filepath: String? = null) { - println("$codeName: $randomCode") - filepath ?: return - val file = File(filepath) - file.createNewFile() - file.writeText("$codeName = $randomCode") - } - - companion object { - private fun randomInt(min: Int, max: Int) = Random().nextInt(max) % (max - min + 1) + min - } -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt b/src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt deleted file mode 100644 index 720d4f5..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt +++ /dev/null @@ -1,30 +0,0 @@ -package cn.tursom.core.datastruct - -class ContainMap(override val keys: Set) : Map { - override val entries: Set> = EntrySet(keys) - override val size: Int get() = keys.size - override val values: Collection = listOf(true) - override fun containsKey(key: K): Boolean = keys.contains(key) - override fun containsValue(value: Boolean): Boolean = true - override fun get(key: K): Boolean = keys.contains(key) - override fun isEmpty(): Boolean = keys.isEmpty() - - private class EntrySet(val keys: Set) : Set> { - override val size: Int get() = keys.size - override fun isEmpty(): Boolean = keys.isEmpty() - override fun iterator(): Iterator> = EntrySerIterator(keys) - override fun contains(element: Map.Entry): Boolean = keys.contains(element.key) == element.value - override fun containsAll(elements: Collection>): Boolean { - elements.forEach { if (contains(it).not()) return false } - return true - } - } - - private class EntrySerIterator(keys: Set) : Iterator> { - private val iterator = keys.iterator() - override fun hasNext(): Boolean = iterator.hasNext() - override fun next(): Map.Entry = Entry(iterator.next(), true) - } - - private class Entry(override val key: K, override val value: Boolean) : Map.Entry -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt b/src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt deleted file mode 100644 index b15f0bf..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt +++ /dev/null @@ -1,15 +0,0 @@ -package cn.tursom.core.datastruct - -import kotlin.reflect.KProperty1 - -class KPropertyEntriesIterator(val target: Any, propertyMap: Map>) : Iterator> { - private val iterator = propertyMap.iterator() - override fun hasNext(): Boolean = iterator.hasNext() - override fun next(): Map.Entry { - val entry = iterator.next() - return object : Map.Entry { - override val key: String = entry.key - override val value: Any? get() = entry.value.get(target) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt b/src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt deleted file mode 100644 index 4ad89d6..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt +++ /dev/null @@ -1,22 +0,0 @@ -package cn.tursom.core.datastruct - -import java.util.concurrent.locks.ReentrantReadWriteLock -import kotlin.concurrent.read -import kotlin.concurrent.write - -class ReadWriteMap(val map: MutableMap) : MutableMap { - private val lock = ReentrantReadWriteLock() - - override val size: Int get() = lock.read { map.size } - override val entries get() = lock.read { map.entries } - override val keys get() = lock.read { map.keys } - override val values get() = lock.read { map.values } - override fun containsKey(key: K): Boolean = lock.read { map.containsKey(key) } - override fun containsValue(value: V): Boolean = lock.read { map.containsValue(value) } - override fun get(key: K): V? = lock.read { map.get(key) } - override fun isEmpty(): Boolean = lock.read { map.isEmpty() } - override fun clear() = lock.write { map.clear() } - override fun put(key: K, value: V): V? = lock.write { map.put(key, value) } - override fun putAll(from: Map) = lock.write { map.putAll(from) } - override fun remove(key: K): V? = lock.write { map.remove(key) } -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt b/src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt deleted file mode 100644 index d9705a6..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt +++ /dev/null @@ -1,48 +0,0 @@ -package cn.tursom.core.datastruct - -class ReversedList( - val list: List -) : List by list { - override fun get(index: Int): E = list[size - index - 1] - - override fun indexOf(element: E): Int { - val lastIndexOf = list.lastIndexOf(element) - return if (lastIndexOf >= 0) size - lastIndexOf else -1 - } - - override fun lastIndexOf(element: E): Int { - val indexOf = list.indexOf(element) - return if (indexOf >= 0) size - indexOf else -1 - } - - override fun iterator(): Iterator = listIterator() - override fun listIterator(): ListIterator = listIterator(0) - - override fun listIterator(index: Int): ListIterator = ReverseListIterator(list.listIterator(size - index)) - - override fun subList(fromIndex: Int, toIndex: Int): List { - return ReversedList(list.subList(size - toIndex, size - fromIndex)) - } - - override fun toString(): String { - val iterator = iterator() - return buildString { - append('[') - iterator.forEach { - append(it) - if (iterator.hasNext()) append(", ") - } - append(']') - } - } - - private class ReverseListIterator(val listIterator: ListIterator) : ListIterator { - override fun hasNext(): Boolean = listIterator.hasPrevious() - override fun next(): E = listIterator.previous() - override fun nextIndex(): Int = listIterator.previousIndex() - override fun hasPrevious(): Boolean = listIterator.hasNext() - override fun previous(): E = listIterator.next() - override fun previousIndex(): Int = listIterator.nextIndex() - } -} - diff --git a/src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt b/src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt deleted file mode 100644 index ff02284..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt +++ /dev/null @@ -1,66 +0,0 @@ -package cn.tursom.core.datastruct - -class SetMap(private val set: Set) : Map { - - override val keys: Set - get() = set - override val size: Int - get() = set.size - override val values: Collection = listOf() - - override fun containsKey(key: K): Boolean { - return set.contains(key) - } - - override fun containsValue(value: Unit): Boolean { - return true - } - - override fun get(key: K): Unit? { - return if (set.contains(key)) Unit else null - } - - override fun isEmpty(): Boolean { - return size == 0 - } - - override val entries: Set> = object : Set> { - override val size: Int - get() = set.size - - override fun contains(element: Map.Entry): Boolean { - return set.contains(element.key) - } - - override fun containsAll(elements: Collection>): Boolean { - elements.forEach { - if (!set.contains(it.key)) return false - } - return true - } - - override fun isEmpty(): Boolean { - return size == 0 - } - - override fun iterator(): Iterator> { - return SetMapIterator(set) - } - } - - class SetMapIterator(set: Set) : Iterator> { - private val iterator = set.iterator() - override fun hasNext(): Boolean { - return iterator.hasNext() - } - - override fun next(): Map.Entry { - return Entry(iterator.next()) - } - } - - data class Entry(override val key: K) : Map.Entry { - override val value: Unit - get() = Unit - } -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt b/src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt deleted file mode 100644 index a7a3f0b..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt +++ /dev/null @@ -1,34 +0,0 @@ -package cn.tursom.core.datastruct - -interface SimpMap : MutableMap { - /** - * @return prev value - */ - operator fun set(key: K, value: V) - - infix fun delete(key: K): V? - - fun setAndGet(key: K, value: V): V? { - val prev = get(key) - set(key, value) - return prev - } - - override fun put(key: K, value: V): V? = setAndGet(key, value) - - override fun remove(key: K): V? = delete(key) - - /** - * 清空整个表 - */ - override fun clear() - - fun first(): V? - - override infix fun putAll(from: Map) { - from.forEach { (k, u) -> - set(k, u) - } - } -} - diff --git a/src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt b/src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt deleted file mode 100644 index c7ba35a..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt +++ /dev/null @@ -1,21 +0,0 @@ -package cn.tursom.core.datastruct - -import java.lang.ref.SoftReference - -class SoftArrayMap(val map: MutableMap>) : MutableMap { - constructor(initialCapacity: Int = 16) : this(HashMap(initialCapacity)) - - override val size: Int get() = map.size - override val entries: MutableSet> get() = throw NotImplementedError() - override val keys: MutableSet get() = map.keys - override val values: MutableCollection get() = throw NotImplementedError() - - override fun put(key: K, value: V): V? = map.put(key, SoftReference(value))?.get() - override fun remove(key: K): V? = map.remove(key)?.get() - override fun clear() = map.clear() - override fun containsKey(key: K): Boolean = map.containsKey(key) - override fun containsValue(value: V): Boolean = map.containsValue(SoftReference(value)) - override fun get(key: K): V? = map[key]?.get() - override fun isEmpty(): Boolean = map.isEmpty() - override fun putAll(from: Map) = from.forEach { (k, u) -> map.put(k, SoftReference(u)) } -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt b/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt deleted file mode 100644 index 7997f62..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt +++ /dev/null @@ -1,10 +0,0 @@ -package cn.tursom.core.datastruct.async.interfaces - -interface AsyncCollection { - val size: Int - - suspend fun isEmpty(): Boolean - suspend infix fun contains(element: @UnsafeVariance E): Boolean - suspend infix fun containsAll(elements: AsyncCollection<@UnsafeVariance E>): Boolean - suspend fun forEach(action: suspend (E) -> Boolean): Boolean -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt b/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt deleted file mode 100644 index e18d653..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt +++ /dev/null @@ -1,24 +0,0 @@ -package cn.tursom.core.datastruct.async.interfaces - -interface AsyncMap : AsyncCollection> { - override val size: Int - val entries: AsyncSet> - val keys: AsyncSet - val values: AsyncCollection - - suspend infix fun containsKey(key: K): Boolean - suspend infix fun containsValue(value: V): Boolean - suspend infix fun get(key: K): V? - - override suspend fun isEmpty(): Boolean - suspend fun isNotEmpty(): Boolean = !isEmpty() - - override suspend fun contains(element: Map.Entry): Boolean { - return get(element.key) == element.value - } - - override suspend fun containsAll(elements: AsyncCollection>): Boolean { - return elements.forEach { contains(it) } - } -} - diff --git a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt b/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt deleted file mode 100644 index 64bd275..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt +++ /dev/null @@ -1,9 +0,0 @@ -package cn.tursom.core.datastruct.async.interfaces - -interface AsyncPotableMap : AsyncMap { - suspend fun clear() - suspend fun set(key: K, value: V): V? - suspend fun putIfAbsent(key: K, value: V): Boolean - suspend infix fun putAll(from: Map) - suspend infix fun remove(key: K): V? -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt b/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt deleted file mode 100644 index bfca54d..0000000 --- a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt +++ /dev/null @@ -1,9 +0,0 @@ -package cn.tursom.core.datastruct.async.interfaces - -interface AsyncPotableSet : AsyncSet { - suspend fun clear(): AsyncPotableSet - suspend fun put(key: K): AsyncPotableSet - suspend fun putIfAbsent(key: K): Boolean - suspend infix fun putAll(from: Set): AsyncPotableSet - suspend infix fun remove(key: K): AsyncPotableSet -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt b/src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt deleted file mode 100644 index 6193943..0000000 --- a/src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt +++ /dev/null @@ -1,7 +0,0 @@ -package cn.tursom.core.regex - -class ControlCharRegexUnit(private val char: Char) : RegexUnit { - constructor(char: ControlCharRegexUnit) : this(char.char) - - override fun toString() = "\\c$char" -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt b/src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt deleted file mode 100644 index 8f51137..0000000 --- a/src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt +++ /dev/null @@ -1,8 +0,0 @@ -package cn.tursom.core.regex - -class GetMatchingUnit(val subUnit: RegexUnit) : RegexUnit { - override val unit: String? - get() = toString() - - override fun toString(): String = "($subUnit)" -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/RegexMaker.kt b/src/main/kotlin/cn/tursom/core/regex/RegexMaker.kt deleted file mode 100644 index b5c845e..0000000 --- a/src/main/kotlin/cn/tursom/core/regex/RegexMaker.kt +++ /dev/null @@ -1,278 +0,0 @@ -package cn.tursom.core.regex - -/** - * 使用 regex 函数创建一个正则对象 - * - * 字符串前加 + 表示一个字符串单元,任何时候都会作为一个独立单元存在 - * 字符串前加 - 表示一个字符串,不会作为一个独立单元处理 - * 注意,我们不支持原始的字符串对象,请使用 + 或 - 将其打包 - * - * 在 RegexMaker 对象头部的这些对象都是字符转义,请根据需要使用 - * uppercase,lowercase 与 numbers 都是字符列表,用于表示在其范围内的单个字符 - * 使用 Char.control 获得控制字符转义 - * - * 接下来是连接两个正则单元用的方法,我们可以用 (单元1) link (单元2),(单元1) also (单元2),甚至是 (单元1)(单元2) 的形式连接两个单元 - * 当然,现在我们也可以用 + 甚至是 - 来连接两个单元了 - * - * 接着是创建单元组的方法,toSet 不建议使用,建议使用 ((单元1) or (单元2) or ...) 的形式创建一个单元组 - * - * 后面跟着的就都是表示重复次数的方法,(单元)-次数n 表示最多重复n次,相应的 * 与 .. 表示精确的 n 次,%表示至少 n 次 - * 我们还可以使用 (单元)-(min..max)的形式指定重复区间,对于这个接口,-、*、% 与 .. 的效果相同,范围区间还可以使用(min to max)的形式 - * 有时候,- 会导致运算符优先级的问题,这时我们可以用 / 来代替 - * - * 如果我们想匹配属于某一组的单个字符,可以使用 (开始字符 % 结束字符) 的形式,使用 and、also、link 或者 + 将多个字符组单元相连 - * 我们还可以在一个 CharRange 或 Pair 前面加 + 生成字符组 - * 或者我们也可以手动指定使用哪些字符,使用 list 方法,字符串会被转义成一个字符组单元 - * 如果你对自己足够有信心,也可以在字符串前面加 !,这会直接生成一个字符组对象,不经检查 - * - * 比如下面这句就是一个合法的表达式 - * '1' % '2' / 5 + list("ABC-\\") * lowercase * numbers % (2 to 3) + uppercase + any % 3 + caret % 1 + +"还行" * 2 - * 运行后会生成 - * [1-2]{0,5}[ABC\-\\a-z0-9]{2,3}[A-Z].{3,}\^+(还行){2} - */ -@Suppress("unused", "MemberVisibilityCanBePrivate", "DuplicatedCode") -object RegexMaker { - operator fun String.unaryPlus() = StringRegexUnit(this) - operator fun String.unaryMinus() = UnitRegexUnit(this) - operator fun RegexUnit.unaryPlus() = GetMatchingUnit(this) - operator fun RegexUnit.unaryMinus() = NonGetMatchingUnit(this) - - val Any.str - get() = +toString() - val Any.unit - get() = -toString() - - val slush = -"\\\\" - val point = -"\\." - val caret = -"\\^" - val dollar = -"\\$" - val plus = -"\\+" - val minus = -"\\-" - val star = -"\\*" - val roundBrackets = -"\\(" - val squareBrackets = -"\\[" - val curlyBrackets = -"\\{" - val backslash = -"\\\\" - val verticalBar = -"\\|" - val questionMark = -"\\?" - val nextPage = -"\\f" - val nextLine = -"\\n" - val enter = -"\\r" - val blankCharacter = -"\\s" - val nonBlankCharacter = -"\\S" - val tab = -"\\t" - val verticalTab = -"\\v" - val wordBoundary = -"\\b" - val nonWordBoundary = -"\\B" - val number = -"\\d" - val nonNumber = -"\\D" - val pageBreak = -"\\f" - val lineBreak = -"n" - val carriageReturn = -"\\r" - val lettersNumbersUnderscores = -"\\w" - val nonLettersNumbersUnderscores = -"\\W" - - /** - * @warning except \n - */ - val any = -"." - val beg = -"^" - val begin = -"^" - val end = -"$" - val empty = -"()" - - val uppercase = 'A' % 'Z' - val lowercase = 'a' % 'z' - val numbers = '0' % '9' - - val Char.control - get() = ControlCharRegexUnit(this) - - infix fun RegexUnit.link(target: RegexUnit) = +"$this$target" - infix fun RegexUnit.link(target: (() -> RegexUnit)) = +"$this${target()}" - infix fun (() -> RegexUnit).link(target: RegexUnit) = +"${this()}$target" - infix fun (() -> RegexUnit).link(target: (() -> RegexUnit)) = +"${this()}${target()}" - infix fun RegexUnit.also(target: RegexUnit) = this link target - infix fun RegexUnit.also(target: (() -> RegexUnit)) = this link target - infix fun (() -> RegexUnit).also(target: RegexUnit) = this link target - infix fun (() -> RegexUnit).also(target: (() -> RegexUnit)) = this link target - infix operator fun RegexUnit.invoke(unit: RegexUnit) = this link unit - infix operator fun RegexUnit.invoke(unit: () -> RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).invoke(unit: () -> RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).invoke(unit: RegexUnit) = this link unit - infix operator fun RegexUnit.plus(unit: RegexUnit) = this link unit - infix operator fun RegexUnit.plus(unit: () -> RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).plus(unit: () -> RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).plus(unit: RegexUnit) = this link unit - infix operator fun RegexUnit.minus(unit: RegexUnit) = this link unit - infix operator fun RegexUnit.minus(unit: () -> RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).minus(unit: RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).minus(unit: () -> RegexUnit) = this link unit - infix operator fun RegexUnit.rangeTo(unit: RegexUnit) = this link unit - infix operator fun RegexUnit.rangeTo(unit: () -> RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).rangeTo(unit: () -> RegexUnit) = this link unit - infix operator fun (() -> RegexUnit).rangeTo(unit: RegexUnit) = this link unit - - val Iterable.toSet: StringRegexUnit? - get() { - val iterator = iterator() - if (!iterator.hasNext()) return null - val stringBuilder = StringBuilder() - stringBuilder.append(iterator.next().unit) - forEach { - stringBuilder.append("|${it.unit}") - } - return StringRegexUnit(stringBuilder.toString()) - } - - val Array.toSet: StringRegexUnit? - get() { - val iterator = iterator() - if (!iterator.hasNext()) return null - val stringBuilder = StringBuilder() - stringBuilder.append(iterator.next().unit) - forEach { - stringBuilder.append("|${it.unit}") - } - return StringRegexUnit(stringBuilder.toString()) - } - - infix fun RegexUnit.or(target: RegexUnit): StringRegexUnit { - val unit = this.unit - val targetUnit = target.unit - return +when { - unit == null -> targetUnit ?: "" - targetUnit == null -> unit - else -> "$unit|$targetUnit" - } - } - - infix fun (() -> RegexUnit).or(target: RegexUnit) = this() or target - - val RegexUnit.onceMore - get() = RepeatRegexUnit(this, 1, -1) - val (() -> RegexUnit).onceMore - get() = RepeatRegexUnit(this(), 1, -1) - - val RegexUnit.anyTime - get() = RepeatRegexUnit(this, -1) - val (() -> RegexUnit).anyTime - get() = RepeatRegexUnit(this(), -1) - - val RegexUnit.onceBelow - get() = RepeatRegexUnit(this, 0, 1) - val (() -> RegexUnit).onceBelow - get() = RepeatRegexUnit(this(), 0, 1) - - infix fun RegexUnit.repeat(times: Int) = RepeatRegexUnit(this, times) - infix fun RegexUnit.repeat(times: IntRange) = RepeatRegexUnit(this, times) - infix fun RegexUnit.repeat(times: Pair) = RepeatRegexUnit(this, times) - fun RegexUnit.timeRange(from: Int, to: Int) = RepeatRegexUnit(this, from, to) - - infix fun (() -> RegexUnit).repeat(times: Int) = RepeatRegexUnit(this(), times) - infix fun (() -> RegexUnit).repeat(times: IntRange) = RepeatRegexUnit(this(), times) - infix fun (() -> RegexUnit).repeat(times: Pair) = RepeatRegexUnit(this(), times) - fun (() -> RegexUnit).timeRange(from: Int, to: Int) = RepeatRegexUnit(this(), from, to) - - infix operator fun RegexUnit.invoke(times: Int) = this repeat times - infix operator fun RegexUnit.invoke(times: IntRange) = this repeat times - infix operator fun RegexUnit.invoke(times: Pair) = this repeat times - operator fun RegexUnit.invoke(from: Int, to: Int) = this.timeRange(from, to) - - infix operator fun (() -> RegexUnit).invoke(unit: Int) = this()(unit) - infix operator fun (() -> RegexUnit).invoke(unit: IntRange) = this()(unit) - infix operator fun (() -> RegexUnit).invoke(unit: Pair) = this()(unit) - operator fun (() -> RegexUnit).invoke(from: Int, to: Int) = this().timeRange(from, to) - - infix fun RegexUnit.upTo(times: Int) = RepeatRegexUnit(this, 0, times) - infix fun RegexUnit.repeatTime(times: Int) = RepeatRegexUnit(this, times) - infix fun RegexUnit.repeatLast(times: Int) = RepeatRegexUnit(this, times, -1) - infix fun RegexUnit.last(times: Int) = RepeatRegexUnit(this, times, -1) - - infix fun (() -> RegexUnit).upTo(times: Int) = this() upTo times - infix fun (() -> RegexUnit).repeatTime(times: Int) = this() repeatTime times - infix fun (() -> RegexUnit).repeatLast(times: Int) = this() repeatLast times - infix fun (() -> RegexUnit).last(times: Int) = this() last times - - infix operator fun RegexUnit.rem(times: Int) = RepeatRegexUnit(this, times, -1) - infix operator fun RegexUnit.times(times: Int) = RepeatRegexUnit(this, times) - infix operator fun RegexUnit.minus(times: Int) = RepeatRegexUnit(this, 0, times) - infix operator fun RegexUnit.div(times: Int) = RepeatRegexUnit(this, 0, times) - infix operator fun RegexUnit.rangeTo(range: Int) = RepeatRegexUnit(this, range) - - infix operator fun (() -> RegexUnit).rem(times: Int) = this() rem times - infix operator fun (() -> RegexUnit).times(times: Int) = this() times times - infix operator fun (() -> RegexUnit).minus(times: Int) = this() minus times - infix operator fun (() -> RegexUnit).div(times: Int) = this() div times - infix operator fun (() -> RegexUnit).rangeTo(range: Int) = this() rangeTo range - - infix operator fun RegexUnit.rem(range: Pair) = RepeatRegexUnit(this, range) - infix operator fun RegexUnit.rem(range: IntRange) = RepeatRegexUnit(this, range) - infix operator fun RegexUnit.times(range: IntRange) = RepeatRegexUnit(this, range) - infix operator fun RegexUnit.times(range: Pair) = RepeatRegexUnit(this, range) - infix operator fun RegexUnit.minus(range: IntRange) = RepeatRegexUnit(this, range) - infix operator fun RegexUnit.minus(range: Pair) = RepeatRegexUnit(this, range) - infix operator fun RegexUnit.rangeTo(range: IntRange) = RepeatRegexUnit(this, range) - infix operator fun RegexUnit.rangeTo(range: Pair) = RepeatRegexUnit(this, range) - - infix operator fun (() -> RegexUnit).rem(range: Pair) = this() rem range - infix operator fun (() -> RegexUnit).rem(range: IntRange) = this() rem range - infix operator fun (() -> RegexUnit).times(range: IntRange) = this() times range - infix operator fun (() -> RegexUnit).times(range: Pair) = this() times range - infix operator fun (() -> RegexUnit).minus(range: IntRange) = this() minus range - infix operator fun (() -> RegexUnit).minus(range: Pair) = this() minus range - infix operator fun (() -> RegexUnit).rangeTo(range: IntRange) = this() rangeTo range - infix operator fun (() -> RegexUnit).rangeTo(range: Pair) = this() rangeTo range - - infix fun Char.list(target: Char) = UnitListRegexUnit(this, target) - infix operator fun Char.rem(char: Char) = UnitListRegexUnit(this, char) - operator fun CharRange.unaryPlus() = UnitListRegexUnit(this) - operator fun CharRange.unaryMinus() = UnitListRegexUnit(this) - operator fun CharRange.not() = UnitListRegexUnit(this) - operator fun Pair.unaryPlus() = UnitListRegexUnit(this) - operator fun Pair.unaryMinus() = UnitListRegexUnit(this) - operator fun Pair.not() = UnitListRegexUnit(this) - - infix operator fun UnitListRegexUnit.invoke(unitList: UnitListRegexUnit) = this and unitList - - object UnitList { - const val hyphen = "\\-" - const val slush = "\\\\" - operator fun invoke(action: UnitList.() -> Any) = !this.action() - } - - class UnitListCheckException : Exception() - - operator fun String.not() = UnitListRegexUnit(this) - operator fun Any.not() = !toString() - private val listChar = Regex("[-\\\\]") - - /** - * 获取str的字面符号表示的字符表 - */ - fun list(str: String): UnitListRegexUnit { - if (!listChar.containsMatchIn(str)) { - return !str - } - val sb = StringBuilder() - str.forEach { c -> - when (c) { - '\\', '-', ':' -> sb.append("\\") - } - sb.append(c) - } - return !sb - } - - val RegexUnit.nonGetMatch get() = NonGetMatchingUnit(this) - val RegexUnit.lookAheadPositiveAssert get() = LookAheadPositiveAssertUnit(this) - val RegexUnit.lookAheadNegativeAssert get() = LookAheadNegativeAssertUnit(this) - val RegexUnit.lookBehindPositiveAssert get() = LookBehindPositiveAssertUnit(this) - val RegexUnit.lookBehindNegativeAssert get() = LookBehindNegativeAssertUnit(this) - - fun make(func: RegexMaker.() -> RegexUnit) = this.func() - - operator fun invoke(func: RegexMaker.() -> RegexUnit) = this.func() -} - -fun regex(func: RegexMaker.() -> RegexUnit) = Regex(RegexMaker.func().toString()) \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt b/src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt deleted file mode 100644 index 82f976c..0000000 --- a/src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt +++ /dev/null @@ -1,7 +0,0 @@ -package cn.tursom.core.regex - -interface RegexUnit { - val unit: String? get() = toString() - val regex get() = toString().toRegex() - override fun toString(): String -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt b/src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt deleted file mode 100644 index 7a5ea9d..0000000 --- a/src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt +++ /dev/null @@ -1,46 +0,0 @@ -package cn.tursom.core.regex - -/** - * 将 ${repeatUnit} 匹配 ${from} 到 ${to} 次 - * 匹配任意次数 如果 ${from} < 0 - * 精确匹配 ${from} 次 如果 ${to} == 0 - * 最少匹配 ${from} 次 如果 ${to} < 0 - */ -class RepeatRegexUnit(repeatUnit: RegexUnit?, from: Int, to: Int = 0) : RegexUnit { - constructor(repeatUnit: RegexUnit?, range: IntRange) : this(repeatUnit, range.start, range.last) - constructor(repeatUnit: RegexUnit?, range: Pair) : this(repeatUnit, range.first, range.second) - - private val str = when { - from < 0 -> "*" - to == 0 -> when (from) { - 0 -> null - 1 -> "" - else -> "{$from}" - } - to < 0 -> when (from) { - 0 -> "*" - 1 -> "+" - else -> "{$from,}" - } - to == 1 && from == 0 -> "?" - to == from -> when (from) { - 0 -> null - 1 -> "" - else -> "{$from}" - } - else -> "{$from,$to}" - }?.let { range -> - repeatUnit?.unit?.let { - if (it.isNotEmpty()) "$it$range" - else "" - } - } ?: "" - - override val unit = if (str.isEmpty()) { - "" - } else { - "($str)" - } - - override fun toString() = str -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt b/src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt deleted file mode 100644 index e667b60..0000000 --- a/src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt +++ /dev/null @@ -1,13 +0,0 @@ -package cn.tursom.core.regex - -class StringRegexUnit(private val str: String) : RegexUnit { - constructor(str: StringRegexUnit) : this(str.str) - - override val unit = when (str.length) { - 0 -> null - 1 -> str - else -> "($str)" - } - - override fun toString() = str -} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt b/src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt deleted file mode 100644 index e32e049..0000000 --- a/src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt +++ /dev/null @@ -1,20 +0,0 @@ -package cn.tursom.core.regex - -class UnitListRegexUnit(private val valList: String) : RegexUnit { - constructor(from: Char, to: Char) : this("$from-$to") - constructor(range: Pair) : this("${range.first}-${range.second}") - constructor(range: CharRange) : this("${range.first}-${range.last}") - constructor(range: UnitListRegexUnit) : this(range.valList) - - val reverse - get() = UnitListRegexUnit(if (valList.first() == '^') valList.drop(1) else "^$valList") - - operator fun not() = reverse - infix operator fun plus(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") - infix operator fun times(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") - infix fun also(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") - infix fun and(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") - infix fun link(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") - - override fun toString() = "[$valList]" -} \ No newline at end of file diff --git a/ts-core/build.gradle.kts b/ts-core/build.gradle.kts new file mode 100644 index 0000000..f1ed5e9 --- /dev/null +++ b/ts-core/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + kotlin("jvm") +} + +dependencies { + api(project(":")) + compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.6") +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + diff --git a/src/main/kotlin/cn/tursom/core/ClassLoaderUtil.kt b/ts-core/src/main/kotlin/cn/tursom/core/ClassLoaderUtil.kt similarity index 95% rename from src/main/kotlin/cn/tursom/core/ClassLoaderUtil.kt rename to ts-core/src/main/kotlin/cn/tursom/core/ClassLoaderUtil.kt index 4e48b3f..0fc64a7 100644 --- a/src/main/kotlin/cn/tursom/core/ClassLoaderUtil.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/ClassLoaderUtil.kt @@ -3,7 +3,6 @@ package cn.tursom.core import java.io.File import java.net.URL import java.net.URLClassLoader -import java.util.ArrayList import java.util.jar.JarFile @Suppress("UNCHECKED_CAST") @@ -60,11 +59,13 @@ object ClassLoaderUtil { for (childFile in childFiles) { if (childFile.isDirectory) { if (childPackage) { - myClassName.addAll(getClassNameByFile( - childFile.path, - "$basePackage.${childFile.path.substringAfterLast(File.separator)}", - childPackage - )) + myClassName.addAll( + getClassNameByFile( + childFile.path, + "$basePackage.${childFile.path.substringAfterLast(File.separator)}", + childPackage + ) + ) } } else { val childFilePath: String = childFile.path diff --git a/src/main/kotlin/cn/tursom/core/Collections.kt b/ts-core/src/main/kotlin/cn/tursom/core/Collections.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/Collections.kt rename to ts-core/src/main/kotlin/cn/tursom/core/Collections.kt diff --git a/src/main/kotlin/cn/tursom/core/CurrentTimeMillisClock.kt b/ts-core/src/main/kotlin/cn/tursom/core/CurrentTimeMillisClock.kt similarity index 81% rename from src/main/kotlin/cn/tursom/core/CurrentTimeMillisClock.kt rename to ts-core/src/main/kotlin/cn/tursom/core/CurrentTimeMillisClock.kt index d23c40e..302fe9e 100644 --- a/src/main/kotlin/cn/tursom/core/CurrentTimeMillisClock.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/CurrentTimeMillisClock.kt @@ -1,7 +1,5 @@ package cn.tursom.core -import java.util.concurrent.TimeUnit -import java.util.concurrent.ScheduledThreadPoolExecutor import kotlin.concurrent.thread diff --git a/src/main/kotlin/cn/tursom/core/Disposable.kt b/ts-core/src/main/kotlin/cn/tursom/core/Disposable.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/Disposable.kt rename to ts-core/src/main/kotlin/cn/tursom/core/Disposable.kt diff --git a/src/main/kotlin/cn/tursom/core/EnumTypeAdapterFactory.kt b/ts-core/src/main/kotlin/cn/tursom/core/EnumTypeAdapterFactory.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/EnumTypeAdapterFactory.kt rename to ts-core/src/main/kotlin/cn/tursom/core/EnumTypeAdapterFactory.kt diff --git a/src/main/kotlin/cn/tursom/core/Finalized.kt b/ts-core/src/main/kotlin/cn/tursom/core/Finalized.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/Finalized.kt rename to ts-core/src/main/kotlin/cn/tursom/core/Finalized.kt diff --git a/src/main/kotlin/cn/tursom/core/GsonDataTypeAdaptor.kt b/ts-core/src/main/kotlin/cn/tursom/core/GsonDataTypeAdaptor.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/GsonDataTypeAdaptor.kt rename to ts-core/src/main/kotlin/cn/tursom/core/GsonDataTypeAdaptor.kt diff --git a/src/main/kotlin/cn/tursom/core/ListClassLoader.kt b/ts-core/src/main/kotlin/cn/tursom/core/ListClassLoader.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/ListClassLoader.kt rename to ts-core/src/main/kotlin/cn/tursom/core/ListClassLoader.kt diff --git a/src/main/kotlin/cn/tursom/core/Members.kt b/ts-core/src/main/kotlin/cn/tursom/core/Members.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/Members.kt rename to ts-core/src/main/kotlin/cn/tursom/core/Members.kt diff --git a/src/main/kotlin/cn/tursom/core/NonLockLinkedList.kt b/ts-core/src/main/kotlin/cn/tursom/core/NonLockLinkedList.kt similarity index 91% rename from src/main/kotlin/cn/tursom/core/NonLockLinkedList.kt rename to ts-core/src/main/kotlin/cn/tursom/core/NonLockLinkedList.kt index bfbc572..2b3695e 100644 --- a/src/main/kotlin/cn/tursom/core/NonLockLinkedList.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/NonLockLinkedList.kt @@ -23,8 +23,8 @@ open class NonLockLinkedList { } private class TaskListNode( - val data: T, - @Volatile var next: TaskListNode? + val data: T, + @Volatile var next: TaskListNode? ) class NotSupportedException : Exception() diff --git a/src/main/kotlin/cn/tursom/core/Parser.kt b/ts-core/src/main/kotlin/cn/tursom/core/Parser.kt similarity index 98% rename from src/main/kotlin/cn/tursom/core/Parser.kt rename to ts-core/src/main/kotlin/cn/tursom/core/Parser.kt index 6a9669b..5272df7 100644 --- a/src/main/kotlin/cn/tursom/core/Parser.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/Parser.kt @@ -7,9 +7,6 @@ import java.lang.reflect.Modifier import java.lang.reflect.ParameterizedType import java.text.SimpleDateFormat import java.util.* -import kotlin.collections.ArrayList -import kotlin.collections.HashMap -import kotlin.collections.HashSet object Parser { private val dateFormat = ThreadLocalSimpleDateFormat() diff --git a/ts-core/src/main/kotlin/cn/tursom/core/RandomCode.kt b/ts-core/src/main/kotlin/cn/tursom/core/RandomCode.kt new file mode 100644 index 0000000..9028b48 --- /dev/null +++ b/ts-core/src/main/kotlin/cn/tursom/core/RandomCode.kt @@ -0,0 +1,24 @@ +package cn.tursom.core + +import java.io.File +import java.util.* + +class RandomCode { + private val randomCode = "${randomInt(10000000, 99999999)}" + + override fun toString(): String { + return randomCode + } + + fun showCode(codeName: String = "passcode", filepath: String? = null) { + println("$codeName: $randomCode") + filepath ?: return + val file = File(filepath) + file.createNewFile() + file.writeText("$codeName = $randomCode") + } + + companion object { + private fun randomInt(min: Int, max: Int) = Random().nextInt(max) % (max - min + 1) + min + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/SimpThreadLocal.kt b/ts-core/src/main/kotlin/cn/tursom/core/SimpThreadLocal.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/SimpThreadLocal.kt rename to ts-core/src/main/kotlin/cn/tursom/core/SimpThreadLocal.kt diff --git a/src/main/kotlin/cn/tursom/core/ThreadLocalSimpleDateFormat.kt b/ts-core/src/main/kotlin/cn/tursom/core/ThreadLocalSimpleDateFormat.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/ThreadLocalSimpleDateFormat.kt rename to ts-core/src/main/kotlin/cn/tursom/core/ThreadLocalSimpleDateFormat.kt diff --git a/src/main/kotlin/cn/tursom/core/Tools.kt b/ts-core/src/main/kotlin/cn/tursom/core/Tools.kt similarity index 92% rename from src/main/kotlin/cn/tursom/core/Tools.kt rename to ts-core/src/main/kotlin/cn/tursom/core/Tools.kt index ae78510..b24adc7 100644 --- a/src/main/kotlin/cn/tursom/core/Tools.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/Tools.kt @@ -2,8 +2,6 @@ package cn.tursom.core -import cn.tursom.core.datastruct.ReversedList -import cn.tursom.core.datastruct.StepList import com.google.gson.Gson import com.google.gson.GsonBuilder import sun.reflect.Reflection @@ -19,8 +17,6 @@ import java.security.MessageDigest import java.security.NoSuchAlgorithmException import java.util.* import java.util.concurrent.Executor -import kotlin.collections.ArrayList -import kotlin.collections.HashSet import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract import kotlin.coroutines.resume @@ -386,35 +382,6 @@ fun Any.serialize(): ByteArray { return outputStream.toByteArray() } -operator fun List.get(startIndex: Int = 0, endIndex: Int = size, step: Int = 1): List { - if (step <= 0) throw IllegalArgumentException("step($step) is negative or zero") - val fromIndex = when { - startIndex < 0 -> size + startIndex - startIndex >= size -> size - else -> startIndex - } - val toIndex = when { - endIndex < 0 -> size + endIndex + 1 - endIndex >= size -> size - else -> endIndex - } - var targetList = if (fromIndex > toIndex) ReversedList(subList(toIndex, fromIndex)) else subList(fromIndex, toIndex) - if (step != 1) targetList = targetList step step - return targetList -} - -operator fun List.get(intProgression: IntProgression): List { - val first = intProgression.first - val last = intProgression.last - val step = intProgression.step - return when { - step == 0 -> get(first, last + if (last < 0) 0 else 1, 1) - step < 0 -> get(first + if (last > 0 && first >= 0) 1 else 0, last, -step) - else -> get(first, last + if (last < 0) 0 else 1, step) - } -} - -infix fun List.step(step: Int): List = StepList(this, step) inline infix fun String.ifEmpty(ifEmpty: () -> String) = if (isNotEmpty()) this else ifEmpty() inline infix fun String.ifBlank(ifBlank: () -> String) = if (isNotBlank()) this else ifBlank() diff --git a/src/main/kotlin/cn/tursom/core/Unsafe.kt b/ts-core/src/main/kotlin/cn/tursom/core/Unsafe.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/Unsafe.kt rename to ts-core/src/main/kotlin/cn/tursom/core/Unsafe.kt diff --git a/src/main/kotlin/cn/tursom/core/UpdatableThreadLocal.kt b/ts-core/src/main/kotlin/cn/tursom/core/UpdatableThreadLocal.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/UpdatableThreadLocal.kt rename to ts-core/src/main/kotlin/cn/tursom/core/UpdatableThreadLocal.kt diff --git a/src/main/kotlin/cn/tursom/core/UpdatableThreadLocalSimpleDateFormat.kt b/ts-core/src/main/kotlin/cn/tursom/core/UpdatableThreadLocalSimpleDateFormat.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/UpdatableThreadLocalSimpleDateFormat.kt rename to ts-core/src/main/kotlin/cn/tursom/core/UpdatableThreadLocalSimpleDateFormat.kt diff --git a/src/main/kotlin/cn/tursom/core/functional.kt b/ts-core/src/main/kotlin/cn/tursom/core/functional.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/functional.kt rename to ts-core/src/main/kotlin/cn/tursom/core/functional.kt diff --git a/ts-core/src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt new file mode 100644 index 0000000..ab611a8 --- /dev/null +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/ControlCharRegexUnit.kt @@ -0,0 +1,7 @@ +package cn.tursom.core.regex + +class ControlCharRegexUnit(private val char: Char) : RegexUnit { + constructor(char: ControlCharRegexUnit) : this(char.char) + + override fun toString() = "\\c$char" +} \ No newline at end of file diff --git a/ts-core/src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt new file mode 100644 index 0000000..274fc88 --- /dev/null +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/GetMatchingUnit.kt @@ -0,0 +1,8 @@ +package cn.tursom.core.regex + +class GetMatchingUnit(val subUnit: RegexUnit) : RegexUnit { + override val unit: String? + get() = toString() + + override fun toString(): String = "($subUnit)" +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/LookAheadNegativeAssertUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/LookAheadNegativeAssertUnit.kt similarity index 65% rename from src/main/kotlin/cn/tursom/core/regex/LookAheadNegativeAssertUnit.kt rename to ts-core/src/main/kotlin/cn/tursom/core/regex/LookAheadNegativeAssertUnit.kt index 91279a7..6f20862 100644 --- a/src/main/kotlin/cn/tursom/core/regex/LookAheadNegativeAssertUnit.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/LookAheadNegativeAssertUnit.kt @@ -1,5 +1,5 @@ package cn.tursom.core.regex class LookAheadNegativeAssertUnit(val subUnit: RegexUnit) : RegexUnit { - override fun toString(): String = "(?=$subUnit)" + override fun toString(): String = "(?=$subUnit)" } \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/LookAheadPositiveAssertUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/LookAheadPositiveAssertUnit.kt similarity index 66% rename from src/main/kotlin/cn/tursom/core/regex/LookAheadPositiveAssertUnit.kt rename to ts-core/src/main/kotlin/cn/tursom/core/regex/LookAheadPositiveAssertUnit.kt index 7f34ea1..0bd1f3e 100644 --- a/src/main/kotlin/cn/tursom/core/regex/LookAheadPositiveAssertUnit.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/LookAheadPositiveAssertUnit.kt @@ -1,5 +1,5 @@ package cn.tursom.core.regex class LookAheadPositiveAssertUnit(val subUnit: RegexUnit) : RegexUnit { - override fun toString(): String = "(?=$subUnit)" + override fun toString(): String = "(?=$subUnit)" } \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/LookBehindNegativeAssertUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/LookBehindNegativeAssertUnit.kt similarity index 65% rename from src/main/kotlin/cn/tursom/core/regex/LookBehindNegativeAssertUnit.kt rename to ts-core/src/main/kotlin/cn/tursom/core/regex/LookBehindNegativeAssertUnit.kt index 29daf32..60f2d7e 100644 --- a/src/main/kotlin/cn/tursom/core/regex/LookBehindNegativeAssertUnit.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/LookBehindNegativeAssertUnit.kt @@ -1,5 +1,5 @@ package cn.tursom.core.regex class LookBehindNegativeAssertUnit(val subUnit: RegexUnit) : RegexUnit { - override fun toString(): String = "(? 前面加 + 生成字符组 + * 或者我们也可以手动指定使用哪些字符,使用 list 方法,字符串会被转义成一个字符组单元 + * 如果你对自己足够有信心,也可以在字符串前面加 !,这会直接生成一个字符组对象,不经检查 + * + * 比如下面这句就是一个合法的表达式 + * '1' % '2' / 5 + list("ABC-\\") * lowercase * numbers % (2 to 3) + uppercase + any % 3 + caret % 1 + +"还行" * 2 + * 运行后会生成 + * [1-2]{0,5}[ABC\-\\a-z0-9]{2,3}[A-Z].{3,}\^+(还行){2} + */ +@Suppress("unused", "MemberVisibilityCanBePrivate", "DuplicatedCode") +object RegexMaker { + operator fun String.unaryPlus() = StringRegexUnit(this) + operator fun String.unaryMinus() = UnitRegexUnit(this) + operator fun RegexUnit.unaryPlus() = GetMatchingUnit(this) + operator fun RegexUnit.unaryMinus() = NonGetMatchingUnit(this) + + val Any.str + get() = +toString() + val Any.unit + get() = -toString() + + val slush = -"\\\\" + val point = -"\\." + val caret = -"\\^" + val dollar = -"\\$" + val plus = -"\\+" + val minus = -"\\-" + val star = -"\\*" + val roundBrackets = -"\\(" + val squareBrackets = -"\\[" + val curlyBrackets = -"\\{" + val backslash = -"\\\\" + val verticalBar = -"\\|" + val questionMark = -"\\?" + val nextPage = -"\\f" + val nextLine = -"\\n" + val enter = -"\\r" + val blankCharacter = -"\\s" + val nonBlankCharacter = -"\\S" + val tab = -"\\t" + val verticalTab = -"\\v" + val wordBoundary = -"\\b" + val nonWordBoundary = -"\\B" + val number = -"\\d" + val nonNumber = -"\\D" + val pageBreak = -"\\f" + val lineBreak = -"n" + val carriageReturn = -"\\r" + val lettersNumbersUnderscores = -"\\w" + val nonLettersNumbersUnderscores = -"\\W" + + /** + * @warning except \n + */ + val any = -"." + val beg = -"^" + val begin = -"^" + val end = -"$" + val empty = -"()" + + val uppercase = 'A' % 'Z' + val lowercase = 'a' % 'z' + val numbers = '0' % '9' + + val Char.control + get() = ControlCharRegexUnit(this) + + infix fun RegexUnit.link(target: RegexUnit) = +"$this$target" + infix fun RegexUnit.link(target: (() -> RegexUnit)) = +"$this${target()}" + infix fun (() -> RegexUnit).link(target: RegexUnit) = +"${this()}$target" + infix fun (() -> RegexUnit).link(target: (() -> RegexUnit)) = +"${this()}${target()}" + infix fun RegexUnit.also(target: RegexUnit) = this link target + infix fun RegexUnit.also(target: (() -> RegexUnit)) = this link target + infix fun (() -> RegexUnit).also(target: RegexUnit) = this link target + infix fun (() -> RegexUnit).also(target: (() -> RegexUnit)) = this link target + infix operator fun RegexUnit.invoke(unit: RegexUnit) = this link unit + infix operator fun RegexUnit.invoke(unit: () -> RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).invoke(unit: () -> RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).invoke(unit: RegexUnit) = this link unit + infix operator fun RegexUnit.plus(unit: RegexUnit) = this link unit + infix operator fun RegexUnit.plus(unit: () -> RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).plus(unit: () -> RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).plus(unit: RegexUnit) = this link unit + infix operator fun RegexUnit.minus(unit: RegexUnit) = this link unit + infix operator fun RegexUnit.minus(unit: () -> RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).minus(unit: RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).minus(unit: () -> RegexUnit) = this link unit + infix operator fun RegexUnit.rangeTo(unit: RegexUnit) = this link unit + infix operator fun RegexUnit.rangeTo(unit: () -> RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).rangeTo(unit: () -> RegexUnit) = this link unit + infix operator fun (() -> RegexUnit).rangeTo(unit: RegexUnit) = this link unit + + val Iterable.toSet: StringRegexUnit? + get() { + val iterator = iterator() + if (!iterator.hasNext()) return null + val stringBuilder = StringBuilder() + stringBuilder.append(iterator.next().unit) + forEach { + stringBuilder.append("|${it.unit}") + } + return StringRegexUnit(stringBuilder.toString()) + } + + val Array.toSet: StringRegexUnit? + get() { + val iterator = iterator() + if (!iterator.hasNext()) return null + val stringBuilder = StringBuilder() + stringBuilder.append(iterator.next().unit) + forEach { + stringBuilder.append("|${it.unit}") + } + return StringRegexUnit(stringBuilder.toString()) + } + + infix fun RegexUnit.or(target: RegexUnit): StringRegexUnit { + val unit = this.unit + val targetUnit = target.unit + return +when { + unit == null -> targetUnit ?: "" + targetUnit == null -> unit + else -> "$unit|$targetUnit" + } + } + + infix fun (() -> RegexUnit).or(target: RegexUnit) = this() or target + + val RegexUnit.onceMore + get() = RepeatRegexUnit(this, 1, -1) + val (() -> RegexUnit).onceMore + get() = RepeatRegexUnit(this(), 1, -1) + + val RegexUnit.anyTime + get() = RepeatRegexUnit(this, -1) + val (() -> RegexUnit).anyTime + get() = RepeatRegexUnit(this(), -1) + + val RegexUnit.onceBelow + get() = RepeatRegexUnit(this, 0, 1) + val (() -> RegexUnit).onceBelow + get() = RepeatRegexUnit(this(), 0, 1) + + infix fun RegexUnit.repeat(times: Int) = RepeatRegexUnit(this, times) + infix fun RegexUnit.repeat(times: IntRange) = RepeatRegexUnit(this, times) + infix fun RegexUnit.repeat(times: Pair) = RepeatRegexUnit(this, times) + fun RegexUnit.timeRange(from: Int, to: Int) = RepeatRegexUnit(this, from, to) + + infix fun (() -> RegexUnit).repeat(times: Int) = RepeatRegexUnit(this(), times) + infix fun (() -> RegexUnit).repeat(times: IntRange) = RepeatRegexUnit(this(), times) + infix fun (() -> RegexUnit).repeat(times: Pair) = RepeatRegexUnit(this(), times) + fun (() -> RegexUnit).timeRange(from: Int, to: Int) = RepeatRegexUnit(this(), from, to) + + infix operator fun RegexUnit.invoke(times: Int) = this repeat times + infix operator fun RegexUnit.invoke(times: IntRange) = this repeat times + infix operator fun RegexUnit.invoke(times: Pair) = this repeat times + operator fun RegexUnit.invoke(from: Int, to: Int) = this.timeRange(from, to) + + infix operator fun (() -> RegexUnit).invoke(unit: Int) = this()(unit) + infix operator fun (() -> RegexUnit).invoke(unit: IntRange) = this()(unit) + infix operator fun (() -> RegexUnit).invoke(unit: Pair) = this()(unit) + operator fun (() -> RegexUnit).invoke(from: Int, to: Int) = this().timeRange(from, to) + + infix fun RegexUnit.upTo(times: Int) = RepeatRegexUnit(this, 0, times) + infix fun RegexUnit.repeatTime(times: Int) = RepeatRegexUnit(this, times) + infix fun RegexUnit.repeatLast(times: Int) = RepeatRegexUnit(this, times, -1) + infix fun RegexUnit.last(times: Int) = RepeatRegexUnit(this, times, -1) + + infix fun (() -> RegexUnit).upTo(times: Int) = this() upTo times + infix fun (() -> RegexUnit).repeatTime(times: Int) = this() repeatTime times + infix fun (() -> RegexUnit).repeatLast(times: Int) = this() repeatLast times + infix fun (() -> RegexUnit).last(times: Int) = this() last times + + infix operator fun RegexUnit.rem(times: Int) = RepeatRegexUnit(this, times, -1) + infix operator fun RegexUnit.times(times: Int) = RepeatRegexUnit(this, times) + infix operator fun RegexUnit.minus(times: Int) = RepeatRegexUnit(this, 0, times) + infix operator fun RegexUnit.div(times: Int) = RepeatRegexUnit(this, 0, times) + infix operator fun RegexUnit.rangeTo(range: Int) = RepeatRegexUnit(this, range) + + infix operator fun (() -> RegexUnit).rem(times: Int) = this() rem times + infix operator fun (() -> RegexUnit).times(times: Int) = this() times times + infix operator fun (() -> RegexUnit).minus(times: Int) = this() minus times + infix operator fun (() -> RegexUnit).div(times: Int) = this() div times + infix operator fun (() -> RegexUnit).rangeTo(range: Int) = this() rangeTo range + + infix operator fun RegexUnit.rem(range: Pair) = RepeatRegexUnit(this, range) + infix operator fun RegexUnit.rem(range: IntRange) = RepeatRegexUnit(this, range) + infix operator fun RegexUnit.times(range: IntRange) = RepeatRegexUnit(this, range) + infix operator fun RegexUnit.times(range: Pair) = RepeatRegexUnit(this, range) + infix operator fun RegexUnit.minus(range: IntRange) = RepeatRegexUnit(this, range) + infix operator fun RegexUnit.minus(range: Pair) = RepeatRegexUnit(this, range) + infix operator fun RegexUnit.rangeTo(range: IntRange) = RepeatRegexUnit(this, range) + infix operator fun RegexUnit.rangeTo(range: Pair) = RepeatRegexUnit(this, range) + + infix operator fun (() -> RegexUnit).rem(range: Pair) = this() rem range + infix operator fun (() -> RegexUnit).rem(range: IntRange) = this() rem range + infix operator fun (() -> RegexUnit).times(range: IntRange) = this() times range + infix operator fun (() -> RegexUnit).times(range: Pair) = this() times range + infix operator fun (() -> RegexUnit).minus(range: IntRange) = this() minus range + infix operator fun (() -> RegexUnit).minus(range: Pair) = this() minus range + infix operator fun (() -> RegexUnit).rangeTo(range: IntRange) = this() rangeTo range + infix operator fun (() -> RegexUnit).rangeTo(range: Pair) = this() rangeTo range + + infix fun Char.list(target: Char) = UnitListRegexUnit(this, target) + infix operator fun Char.rem(char: Char) = UnitListRegexUnit(this, char) + operator fun CharRange.unaryPlus() = UnitListRegexUnit(this) + operator fun CharRange.unaryMinus() = UnitListRegexUnit(this) + operator fun CharRange.not() = UnitListRegexUnit(this) + operator fun Pair.unaryPlus() = UnitListRegexUnit(this) + operator fun Pair.unaryMinus() = UnitListRegexUnit(this) + operator fun Pair.not() = UnitListRegexUnit(this) + + infix operator fun UnitListRegexUnit.invoke(unitList: UnitListRegexUnit) = this and unitList + + object UnitList { + const val hyphen = "\\-" + const val slush = "\\\\" + operator fun invoke(action: UnitList.() -> Any) = !this.action() + } + + class UnitListCheckException : Exception() + + operator fun String.not() = UnitListRegexUnit(this) + operator fun Any.not() = !toString() + private val listChar = Regex("[-\\\\]") + + /** + * 获取str的字面符号表示的字符表 + */ + fun list(str: String): UnitListRegexUnit { + if (!listChar.containsMatchIn(str)) { + return !str + } + val sb = StringBuilder() + str.forEach { c -> + when (c) { + '\\', '-', ':' -> sb.append("\\") + } + sb.append(c) + } + return !sb + } + + val RegexUnit.nonGetMatch get() = NonGetMatchingUnit(this) + val RegexUnit.lookAheadPositiveAssert get() = LookAheadPositiveAssertUnit(this) + val RegexUnit.lookAheadNegativeAssert get() = LookAheadNegativeAssertUnit(this) + val RegexUnit.lookBehindPositiveAssert get() = LookBehindPositiveAssertUnit(this) + val RegexUnit.lookBehindNegativeAssert get() = LookBehindNegativeAssertUnit(this) + + fun make(func: RegexMaker.() -> RegexUnit) = this.func() + + operator fun invoke(func: RegexMaker.() -> RegexUnit) = this.func() +} + +fun regex(func: RegexMaker.() -> RegexUnit) = Regex(RegexMaker.func().toString()) \ No newline at end of file diff --git a/ts-core/src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt new file mode 100644 index 0000000..19452e7 --- /dev/null +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/RegexUnit.kt @@ -0,0 +1,7 @@ +package cn.tursom.core.regex + +interface RegexUnit { + val unit: String? get() = toString() + val regex get() = toString().toRegex() + override fun toString(): String +} \ No newline at end of file diff --git a/ts-core/src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt new file mode 100644 index 0000000..abf0f3d --- /dev/null +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/RepeatRegexUnit.kt @@ -0,0 +1,46 @@ +package cn.tursom.core.regex + +/** + * 将 ${repeatUnit} 匹配 ${from} 到 ${to} 次 + * 匹配任意次数 如果 ${from} < 0 + * 精确匹配 ${from} 次 如果 ${to} == 0 + * 最少匹配 ${from} 次 如果 ${to} < 0 + */ +class RepeatRegexUnit(repeatUnit: RegexUnit?, from: Int, to: Int = 0) : RegexUnit { + constructor(repeatUnit: RegexUnit?, range: IntRange) : this(repeatUnit, range.start, range.last) + constructor(repeatUnit: RegexUnit?, range: Pair) : this(repeatUnit, range.first, range.second) + + private val str = when { + from < 0 -> "*" + to == 0 -> when (from) { + 0 -> null + 1 -> "" + else -> "{$from}" + } + to < 0 -> when (from) { + 0 -> "*" + 1 -> "+" + else -> "{$from,}" + } + to == 1 && from == 0 -> "?" + to == from -> when (from) { + 0 -> null + 1 -> "" + else -> "{$from}" + } + else -> "{$from,$to}" + }?.let { range -> + repeatUnit?.unit?.let { + if (it.isNotEmpty()) "$it$range" + else "" + } + } ?: "" + + override val unit = if (str.isEmpty()) { + "" + } else { + "($str)" + } + + override fun toString() = str +} \ No newline at end of file diff --git a/ts-core/src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt new file mode 100644 index 0000000..2324089 --- /dev/null +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/StringRegexUnit.kt @@ -0,0 +1,13 @@ +package cn.tursom.core.regex + +class StringRegexUnit(private val str: String) : RegexUnit { + constructor(str: StringRegexUnit) : this(str.str) + + override val unit = when (str.length) { + 0 -> null + 1 -> str + else -> "($str)" + } + + override fun toString() = str +} \ No newline at end of file diff --git a/ts-core/src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt new file mode 100644 index 0000000..244fed2 --- /dev/null +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/UnitListRegexUnit.kt @@ -0,0 +1,20 @@ +package cn.tursom.core.regex + +class UnitListRegexUnit(private val valList: String) : RegexUnit { + constructor(from: Char, to: Char) : this("$from-$to") + constructor(range: Pair) : this("${range.first}-${range.second}") + constructor(range: CharRange) : this("${range.first}-${range.last}") + constructor(range: UnitListRegexUnit) : this(range.valList) + + val reverse + get() = UnitListRegexUnit(if (valList.first() == '^') valList.drop(1) else "^$valList") + + operator fun not() = reverse + infix operator fun plus(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") + infix operator fun times(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") + infix fun also(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") + infix fun and(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") + infix fun link(unitList: UnitListRegexUnit) = UnitListRegexUnit("$valList${unitList.valList}") + + override fun toString() = "[$valList]" +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/regex/UnitRegexUnit.kt b/ts-core/src/main/kotlin/cn/tursom/core/regex/UnitRegexUnit.kt similarity index 51% rename from src/main/kotlin/cn/tursom/core/regex/UnitRegexUnit.kt rename to ts-core/src/main/kotlin/cn/tursom/core/regex/UnitRegexUnit.kt index 2ade941..eb19b7a 100644 --- a/src/main/kotlin/cn/tursom/core/regex/UnitRegexUnit.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/regex/UnitRegexUnit.kt @@ -1,7 +1,7 @@ package cn.tursom.core.regex class UnitRegexUnit(override val unit: String) : RegexUnit { - constructor(unit: UnitRegexUnit) : this(unit.unit) - - override fun toString() = unit + constructor(unit: UnitRegexUnit) : this(unit.unit) + + override fun toString() = unit } \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/storage/BufferedStorageHandler.kt b/ts-core/src/main/kotlin/cn/tursom/core/storage/BufferedStorageHandler.kt similarity index 99% rename from src/main/kotlin/cn/tursom/core/storage/BufferedStorageHandler.kt rename to ts-core/src/main/kotlin/cn/tursom/core/storage/BufferedStorageHandler.kt index fc05d16..48b1ed2 100644 --- a/src/main/kotlin/cn/tursom/core/storage/BufferedStorageHandler.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/storage/BufferedStorageHandler.kt @@ -24,6 +24,7 @@ class BufferedStorageHandler( private val writeHandler: (list: Collection) -> Unit ) : StorageHandler { private val onWrite = AtomicBoolean(false) + @Volatile private var msgList = ConcurrentLinkedQueue() diff --git a/src/main/kotlin/cn/tursom/core/storage/InstantStorageHandler.kt b/ts-core/src/main/kotlin/cn/tursom/core/storage/InstantStorageHandler.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/storage/InstantStorageHandler.kt rename to ts-core/src/main/kotlin/cn/tursom/core/storage/InstantStorageHandler.kt diff --git a/src/main/kotlin/cn/tursom/core/storage/StorageHandler.kt b/ts-core/src/main/kotlin/cn/tursom/core/storage/StorageHandler.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/storage/StorageHandler.kt rename to ts-core/src/main/kotlin/cn/tursom/core/storage/StorageHandler.kt diff --git a/src/main/kotlin/cn/tursom/core/storage/ThreadPoolStorageHandler.kt b/ts-core/src/main/kotlin/cn/tursom/core/storage/ThreadPoolStorageHandler.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/storage/ThreadPoolStorageHandler.kt rename to ts-core/src/main/kotlin/cn/tursom/core/storage/ThreadPoolStorageHandler.kt diff --git a/src/main/kotlin/cn/tursom/core/timer/NonLockTaskQueue.kt b/ts-core/src/main/kotlin/cn/tursom/core/timer/NonLockTaskQueue.kt similarity index 89% rename from src/main/kotlin/cn/tursom/core/timer/NonLockTaskQueue.kt rename to ts-core/src/main/kotlin/cn/tursom/core/timer/NonLockTaskQueue.kt index 1b8b1a3..4145134 100644 --- a/src/main/kotlin/cn/tursom/core/timer/NonLockTaskQueue.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/timer/NonLockTaskQueue.kt @@ -35,10 +35,10 @@ class NonLockTaskQueue : TaskQueue { } private class TaskListNode( - override val timeout: Long, - override val task: () -> Unit, - override val createTime: Long, - @Volatile var next: TaskListNode? + override val timeout: Long, + override val task: () -> Unit, + override val createTime: Long, + @Volatile var next: TaskListNode? ) : TimerTask { @Volatile override var canceled: Boolean = false diff --git a/src/main/kotlin/cn/tursom/core/timer/SynchronizedTaskQueue.kt b/ts-core/src/main/kotlin/cn/tursom/core/timer/SynchronizedTaskQueue.kt similarity index 87% rename from src/main/kotlin/cn/tursom/core/timer/SynchronizedTaskQueue.kt rename to ts-core/src/main/kotlin/cn/tursom/core/timer/SynchronizedTaskQueue.kt index f4ab237..94f77ef 100644 --- a/src/main/kotlin/cn/tursom/core/timer/SynchronizedTaskQueue.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/timer/SynchronizedTaskQueue.kt @@ -40,11 +40,11 @@ class SynchronizedTaskQueue : TaskQueue { } inner class TaskNode( - override val timeout: Long, - override val task: () -> Unit, - @Volatile var prev: TaskNode?, - @Volatile var next: TaskNode?, - override val createTime: Long = CurrentTimeMillisClock.now + override val timeout: Long, + override val task: () -> Unit, + @Volatile var prev: TaskNode?, + @Volatile var next: TaskNode?, + override val createTime: Long = CurrentTimeMillisClock.now ) : TimerTask { @Volatile override var canceled: Boolean = false diff --git a/src/main/kotlin/cn/tursom/core/timer/TaskQueue.kt b/ts-core/src/main/kotlin/cn/tursom/core/timer/TaskQueue.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/timer/TaskQueue.kt rename to ts-core/src/main/kotlin/cn/tursom/core/timer/TaskQueue.kt diff --git a/src/main/kotlin/cn/tursom/core/timer/Timer.kt b/ts-core/src/main/kotlin/cn/tursom/core/timer/Timer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/timer/Timer.kt rename to ts-core/src/main/kotlin/cn/tursom/core/timer/Timer.kt diff --git a/src/main/kotlin/cn/tursom/core/timer/TimerTask.kt b/ts-core/src/main/kotlin/cn/tursom/core/timer/TimerTask.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/timer/TimerTask.kt rename to ts-core/src/main/kotlin/cn/tursom/core/timer/TimerTask.kt diff --git a/src/main/kotlin/cn/tursom/core/timer/WheelTimer.kt b/ts-core/src/main/kotlin/cn/tursom/core/timer/WheelTimer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/timer/WheelTimer.kt rename to ts-core/src/main/kotlin/cn/tursom/core/timer/WheelTimer.kt diff --git a/src/test/kotlin/main.kt b/ts-core/src/test/kotlin/main.kt similarity index 100% rename from src/test/kotlin/main.kt rename to ts-core/src/test/kotlin/main.kt diff --git a/ts-core/ts-buffer/build.gradle.kts b/ts-core/ts-buffer/build.gradle.kts new file mode 100644 index 0000000..fa9c22b --- /dev/null +++ b/ts-core/ts-buffer/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + kotlin("jvm") +} + +dependencies { + api(project(":")) +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + diff --git a/src/main/kotlin/cn/tursom/core/AsyncFile.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/AsyncFile.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/AsyncFile.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/AsyncFile.kt diff --git a/src/main/kotlin/cn/tursom/core/DataOperate.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/DataOperate.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/DataOperate.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/DataOperate.kt diff --git a/src/main/kotlin/cn/tursom/core/FlvChecker.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/FlvChecker.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/FlvChecker.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/FlvChecker.kt diff --git a/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt new file mode 100644 index 0000000..c20016c --- /dev/null +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/HeapByteBufferUtil.kt @@ -0,0 +1,26 @@ +package cn.tursom.core + +import java.nio.ByteBuffer + +/** + * HOOK java.nio.HeapByteBuffer + */ +object HeapByteBufferUtil { + private val field = ByteBuffer::class.java.getDeclaredField("offset") + + init { + field.isAccessible = true + } + + fun wrap(array: ByteArray, offset: Int = 0, size: Int = array.size - offset): ByteBuffer { + val buffer = ByteBuffer.wrap(array, 0, offset + size) + //return if (offset == 0) buffer else { + // buffer.position(offset) + // buffer.slice() + //} + if (offset > 0) field.set(buffer, offset) + return buffer + } + + fun wrap(string: String) = wrap(string.toByteArray()) +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/HttpRequest.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/HttpRequest.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/HttpRequest.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/HttpRequest.kt diff --git a/src/main/kotlin/cn/tursom/core/Snowflake.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/Snowflake.kt similarity index 96% rename from src/main/kotlin/cn/tursom/core/Snowflake.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/Snowflake.kt index 65d2c4f..4089fa0 100644 --- a/src/main/kotlin/cn/tursom/core/Snowflake.kt +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/Snowflake.kt @@ -64,8 +64,10 @@ class Snowflake( }, updateRateMs, updateRateMs, TimeUnit.MICROSECONDS) } - override fun toString() = "Snowflake(workerId=${nodeId - }, timestamp=0x${timestamp.toHexString(false) + override fun toString() = "Snowflake(workerId=${ + nodeId + }, timestamp=0x${ + timestamp.toHexString(false) }, seed=0x${seed.get().toHexString(false)})" enum class WorkMode { diff --git a/src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt diff --git a/src/main/kotlin/cn/tursom/core/buffer/ByteBufferExtension.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ByteBufferExtension.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/ByteBufferExtension.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ByteBufferExtension.kt diff --git a/src/main/kotlin/cn/tursom/core/buffer/ClosedBufferException.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ClosedBufferException.kt similarity index 72% rename from src/main/kotlin/cn/tursom/core/buffer/ClosedBufferException.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ClosedBufferException.kt index 20b7886..7bd4b72 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/ClosedBufferException.kt +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ClosedBufferException.kt @@ -5,5 +5,10 @@ class ClosedBufferException : Exception { constructor(message: String?) : super(message) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) - constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super(message, cause, enableSuppression, writableStackTrace) + constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super( + message, + cause, + enableSuppression, + writableStackTrace + ) } \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/buffer/MarkableByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/MarkableByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/MarkableByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/MarkableByteBuffer.kt diff --git a/src/main/kotlin/cn/tursom/core/buffer/MultipleByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/MultipleByteBuffer.kt similarity index 99% rename from src/main/kotlin/cn/tursom/core/buffer/MultipleByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/MultipleByteBuffer.kt index 900f72e..b701260 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/MultipleByteBuffer.kt +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/MultipleByteBuffer.kt @@ -5,10 +5,8 @@ import cn.tursom.core.buffer.impl.ListByteBuffer import cn.tursom.core.forEachIndex import cn.tursom.core.toBytes import java.io.Closeable -import java.io.IOException import java.io.InputStream import java.io.OutputStream -import kotlin.math.min @Suppress("unused") interface MultipleByteBuffer : List, Closeable, ByteBuffer { diff --git a/src/main/kotlin/cn/tursom/core/buffer/ProxyByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ProxyByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/ProxyByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/ProxyByteBuffer.kt diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/ArrayByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/ArrayByteBuffer.kt similarity index 80% rename from src/main/kotlin/cn/tursom/core/buffer/impl/ArrayByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/ArrayByteBuffer.kt index 72d532c..7be3732 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/impl/ArrayByteBuffer.kt +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/ArrayByteBuffer.kt @@ -1,7 +1,6 @@ package cn.tursom.core.buffer.impl import cn.tursom.core.buffer.ByteBuffer -import cn.tursom.buffer.MultipleByteBuffer class ArrayByteBuffer( override vararg val buffers: ByteBuffer diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/CloseSafeByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/CloseSafeByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/impl/CloseSafeByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/CloseSafeByteBuffer.kt diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/DirectByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/DirectByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/impl/DirectByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/DirectByteBuffer.kt diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/HeapByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/HeapByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/impl/HeapByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/HeapByteBuffer.kt index 2eae40a..1fd65e1 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/impl/HeapByteBuffer.kt +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/HeapByteBuffer.kt @@ -1,7 +1,7 @@ package cn.tursom.core.buffer.impl -import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.HeapByteBufferUtil +import cn.tursom.core.buffer.ByteBuffer class HeapByteBuffer( private var buffer: java.nio.ByteBuffer, diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/ListByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/ListByteBuffer.kt similarity index 99% rename from src/main/kotlin/cn/tursom/core/buffer/impl/ListByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/ListByteBuffer.kt index 2822c5a..50acb89 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/impl/ListByteBuffer.kt +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/ListByteBuffer.kt @@ -45,6 +45,7 @@ open class ListByteBuffer(val bufferList: List) : MultipleByteBuffer updateRead() return readOperator!!.get() } + override fun put(byte: Byte) { TODO("Not yet implemented") } diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/MarkedByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/MarkedByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/impl/MarkedByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/MarkedByteBuffer.kt index c82ef89..ebfb17d 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/impl/MarkedByteBuffer.kt +++ b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/MarkedByteBuffer.kt @@ -1,7 +1,7 @@ package cn.tursom.core.buffer.impl -import cn.tursom.core.buffer.ByteBuffer import cn.tursom.buffer.MarkableByteBuffer +import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.buffer.ProxyByteBuffer class MarkedByteBuffer(override val agent: ByteBuffer) : ProxyByteBuffer, MarkableByteBuffer, ByteBuffer by agent { diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/SplitByteBuffer.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/SplitByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/impl/SplitByteBuffer.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/buffer/impl/SplitByteBuffer.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/IOStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/IOStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/IOStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/IOStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/InputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/InputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/InputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/InputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/OutputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/OutputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/OutputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/OutputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/Stream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/Stream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/Stream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/Stream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/SuspendInputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/SuspendInputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/SuspendInputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/SuspendInputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferIOStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferIOStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferIOStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferIOStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferInputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferInputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferInputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferInputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferOutputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferOutputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferOutputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/ByteBufferOutputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/BytesIOStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/BytesIOStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/BytesIOStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/BytesIOStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/BytesInputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/BytesInputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/BytesInputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/BytesInputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/BytesOutputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/BytesOutputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/BytesOutputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/BytesOutputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStreamProxy.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStreamProxy.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStreamProxy.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/JavaInputStreamProxy.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/JavaOutputStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/JavaOutputStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/JavaOutputStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/JavaOutputStream.kt diff --git a/src/main/kotlin/cn/tursom/core/stream/impl/PairIOStream.kt b/ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/PairIOStream.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/stream/impl/PairIOStream.kt rename to ts-core/ts-buffer/src/main/kotlin/cn/tursom/core/stream/impl/PairIOStream.kt diff --git a/ts-core/ts-datastruct/build.gradle.kts b/ts-core/ts-datastruct/build.gradle.kts new file mode 100644 index 0000000..34546fc --- /dev/null +++ b/ts-core/ts-datastruct/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + kotlin("jvm") +} + +dependencies { + api(project(":ts-core:ts-buffer")) + api(project(":ts-core:ts-hash")) + compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.6") +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + diff --git a/src/main/kotlin/cn/tursom/core/datastruct/AbstractList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AbstractList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/AbstractList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AbstractList.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/AbstractListIterator.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AbstractListIterator.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/AbstractListIterator.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AbstractListIterator.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/AbstractMutableList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AbstractMutableList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/AbstractMutableList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AbstractMutableList.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/ArrayBitSet.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ArrayBitSet.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/ArrayBitSet.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ArrayBitSet.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/ArrayMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ArrayMap.kt similarity index 98% rename from src/main/kotlin/cn/tursom/core/datastruct/ArrayMap.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ArrayMap.kt index d7dd2f7..aa529c8 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/ArrayMap.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ArrayMap.kt @@ -240,7 +240,9 @@ open class ArrayMap(initialCapacity: Int = 16) : SimpMap { override fun add(element: K): Boolean = false override fun addAll(elements: Collection): Boolean = false override fun clear() = map.clear() - override fun retainAll(elements: Collection): Boolean = map.entries.retainAll(elements.map { map.getNode(it) }.filterNotNull()) + override fun retainAll(elements: Collection): Boolean = + map.entries.retainAll(elements.map { map.getNode(it) }.filterNotNull()) + override fun remove(element: K): Boolean = map.remove(element) != null override fun removeAll(elements: Collection): Boolean { elements.forEach { remove(it) } diff --git a/src/main/kotlin/cn/tursom/core/datastruct/AtomicBitSet.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AtomicBitSet.kt similarity index 97% rename from src/main/kotlin/cn/tursom/core/datastruct/AtomicBitSet.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AtomicBitSet.kt index 3f9e997..7511f14 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/AtomicBitSet.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/AtomicBitSet.kt @@ -213,7 +213,12 @@ class AtomicBitSet(beginSize: Long = 256, val defaultState: Boolean = false) : S } } - private inline fun AtomicLongArray.forEachIndexed(startIndex: Int, length: Int = length(), asc: Boolean = true, action: (index: Int, Long) -> Unit) { + private inline fun AtomicLongArray.forEachIndexed( + startIndex: Int, + length: Int = length(), + asc: Boolean = true, + action: (index: Int, Long) -> Unit + ) { repeat(length) { val index = if (asc) { startIndex + it diff --git a/src/main/kotlin/cn/tursom/core/datastruct/BloomFilter.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/BloomFilter.kt similarity index 94% rename from src/main/kotlin/cn/tursom/core/datastruct/BloomFilter.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/BloomFilter.kt index 5e10d55..e3fa5a0 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/BloomFilter.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/BloomFilter.kt @@ -8,7 +8,12 @@ import kotlin.math.pow class BloomFilter(val hash: Hash = murmur3Hash, val bitSize: Long, val hashCount: Int = 5) { private val bitSet = ArrayBitSet(bitSize) - constructor(valueCount: Long = 1000000, hashCount: Int = 5, wrongChance: Double = 0.03, hash: Hash = murmur3Hash) : this( + constructor( + valueCount: Long = 1000000, + hashCount: Int = 5, + wrongChance: Double = 0.03, + hash: Hash = murmur3Hash + ) : this( hash, wrongChance.run { assert(wrongChance in 0.0..1.0) diff --git a/src/main/kotlin/cn/tursom/core/datastruct/ComparableArrayMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ComparableArrayMap.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/ComparableArrayMap.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ComparableArrayMap.kt diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt new file mode 100644 index 0000000..6f08683 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ContainMap.kt @@ -0,0 +1,30 @@ +package cn.tursom.core.datastruct + +class ContainMap(override val keys: Set) : Map { + override val entries: Set> = EntrySet(keys) + override val size: Int get() = keys.size + override val values: Collection = listOf(true) + override fun containsKey(key: K): Boolean = keys.contains(key) + override fun containsValue(value: Boolean): Boolean = true + override fun get(key: K): Boolean = keys.contains(key) + override fun isEmpty(): Boolean = keys.isEmpty() + + private class EntrySet(val keys: Set) : Set> { + override val size: Int get() = keys.size + override fun isEmpty(): Boolean = keys.isEmpty() + override fun iterator(): Iterator> = EntrySerIterator(keys) + override fun contains(element: Map.Entry): Boolean = keys.contains(element.key) == element.value + override fun containsAll(elements: Collection>): Boolean { + elements.forEach { if (contains(it).not()) return false } + return true + } + } + + private class EntrySerIterator(keys: Set) : Iterator> { + private val iterator = keys.iterator() + override fun hasNext(): Boolean = iterator.hasNext() + override fun next(): Map.Entry = Entry(iterator.next(), true) + } + + private class Entry(override val key: K, override val value: Boolean) : Map.Entry +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMap.kt similarity index 99% rename from src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMap.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMap.kt index e6b806a..1a9b6ad 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMap.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMap.kt @@ -1,7 +1,6 @@ package cn.tursom.core.datastruct import cn.tursom.core.cast -import java.util.* class DefaultValueMap( private val map: Map, diff --git a/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMutableMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMutableMap.kt similarity index 98% rename from src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMutableMap.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMutableMap.kt index ba24714..456f610 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMutableMap.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/DefaultValueMutableMap.kt @@ -1,7 +1,6 @@ package cn.tursom.core.datastruct import cn.tursom.core.cast -import java.util.NoSuchElementException class DefaultValueMutableMap( private val map: MutableMap, diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt new file mode 100644 index 0000000..d170b66 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/KPropertyEntriesIterator.kt @@ -0,0 +1,16 @@ +package cn.tursom.core.datastruct + +import kotlin.reflect.KProperty1 + +class KPropertyEntriesIterator(val target: Any, propertyMap: Map>) : + Iterator> { + private val iterator = propertyMap.iterator() + override fun hasNext(): Boolean = iterator.hasNext() + override fun next(): Map.Entry { + val entry = iterator.next() + return object : Map.Entry { + override val key: String = entry.key + override val value: Any? get() = entry.value.get(target) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/KPropertyValueCollectionIterator.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/KPropertyValueCollectionIterator.kt similarity index 52% rename from src/main/kotlin/cn/tursom/core/datastruct/KPropertyValueCollectionIterator.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/KPropertyValueCollectionIterator.kt index 24b125f..e779d38 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/KPropertyValueCollectionIterator.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/KPropertyValueCollectionIterator.kt @@ -3,7 +3,7 @@ package cn.tursom.core.datastruct import kotlin.reflect.KProperty1 class KPropertyValueCollectionIterator(val target: Any, propertyMap: Map>) : Iterator { - private val iterator = propertyMap.iterator() - override fun hasNext(): Boolean = iterator.hasNext() - override fun next(): Any? = iterator.next().value.get(target) + private val iterator = propertyMap.iterator() + override fun hasNext(): Boolean = iterator.hasNext() + override fun next(): Any? = iterator.next().value.get(target) } \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/LongBitSet.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/LongBitSet.kt similarity index 91% rename from src/main/kotlin/cn/tursom/core/datastruct/LongBitSet.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/LongBitSet.kt index 2d93746..0490437 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/LongBitSet.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/LongBitSet.kt @@ -88,8 +88,8 @@ class LongBitSet { private val Long.bitCount get() = bitCountArray[toInt().and(0xff)] + bitCountArray[shr(8).toInt().and(0xff)] + - bitCountArray[shr(16).toInt().and(0xff)] + bitCountArray[shr(24).toInt().and(0xff)] + - bitCountArray[shr(32).toInt().and(0xff)] + bitCountArray[shr(40).toInt().and(0xff)] + - bitCountArray[shr(48).toInt().and(0xff)] + bitCountArray[shr(56).toInt().and(0xff)] + bitCountArray[shr(16).toInt().and(0xff)] + bitCountArray[shr(24).toInt().and(0xff)] + + bitCountArray[shr(32).toInt().and(0xff)] + bitCountArray[shr(40).toInt().and(0xff)] + + bitCountArray[shr(48).toInt().and(0xff)] + bitCountArray[shr(56).toInt().and(0xff)] } } \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/MutableSubList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/MutableSubList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/MutableSubList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/MutableSubList.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/ParallelArrayMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ParallelArrayMap.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/ParallelArrayMap.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ParallelArrayMap.kt diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt new file mode 100644 index 0000000..2c632ff --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReadWriteMap.kt @@ -0,0 +1,22 @@ +package cn.tursom.core.datastruct + +import java.util.concurrent.locks.ReentrantReadWriteLock +import kotlin.concurrent.read +import kotlin.concurrent.write + +class ReadWriteMap(val map: MutableMap) : MutableMap { + private val lock = ReentrantReadWriteLock() + + override val size: Int get() = lock.read { map.size } + override val entries get() = lock.read { map.entries } + override val keys get() = lock.read { map.keys } + override val values get() = lock.read { map.values } + override fun containsKey(key: K): Boolean = lock.read { map.containsKey(key) } + override fun containsValue(value: V): Boolean = lock.read { map.containsValue(value) } + override fun get(key: K): V? = lock.read { map.get(key) } + override fun isEmpty(): Boolean = lock.read { map.isEmpty() } + override fun clear() = lock.write { map.clear() } + override fun put(key: K, value: V): V? = lock.write { map.put(key, value) } + override fun putAll(from: Map) = lock.write { map.putAll(from) } + override fun remove(key: K): V? = lock.write { map.remove(key) } +} \ No newline at end of file diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt new file mode 100644 index 0000000..795e1b2 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/ReversedList.kt @@ -0,0 +1,48 @@ +package cn.tursom.core.datastruct + +class ReversedList( + val list: List +) : List by list { + override fun get(index: Int): E = list[size - index - 1] + + override fun indexOf(element: E): Int { + val lastIndexOf = list.lastIndexOf(element) + return if (lastIndexOf >= 0) size - lastIndexOf else -1 + } + + override fun lastIndexOf(element: E): Int { + val indexOf = list.indexOf(element) + return if (indexOf >= 0) size - indexOf else -1 + } + + override fun iterator(): Iterator = listIterator() + override fun listIterator(): ListIterator = listIterator(0) + + override fun listIterator(index: Int): ListIterator = ReverseListIterator(list.listIterator(size - index)) + + override fun subList(fromIndex: Int, toIndex: Int): List { + return ReversedList(list.subList(size - toIndex, size - fromIndex)) + } + + override fun toString(): String { + val iterator = iterator() + return buildString { + append('[') + iterator.forEach { + append(it) + if (iterator.hasNext()) append(", ") + } + append(']') + } + } + + private class ReverseListIterator(val listIterator: ListIterator) : ListIterator { + override fun hasNext(): Boolean = listIterator.hasPrevious() + override fun next(): E = listIterator.previous() + override fun nextIndex(): Int = listIterator.previousIndex() + override fun hasPrevious(): Boolean = listIterator.hasNext() + override fun previous(): E = listIterator.next() + override fun previousIndex(): Int = listIterator.nextIndex() + } +} + diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt new file mode 100644 index 0000000..b1b4172 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SetMap.kt @@ -0,0 +1,66 @@ +package cn.tursom.core.datastruct + +class SetMap(private val set: Set) : Map { + + override val keys: Set + get() = set + override val size: Int + get() = set.size + override val values: Collection = listOf() + + override fun containsKey(key: K): Boolean { + return set.contains(key) + } + + override fun containsValue(value: Unit): Boolean { + return true + } + + override fun get(key: K): Unit? { + return if (set.contains(key)) Unit else null + } + + override fun isEmpty(): Boolean { + return size == 0 + } + + override val entries: Set> = object : Set> { + override val size: Int + get() = set.size + + override fun contains(element: Map.Entry): Boolean { + return set.contains(element.key) + } + + override fun containsAll(elements: Collection>): Boolean { + elements.forEach { + if (!set.contains(it.key)) return false + } + return true + } + + override fun isEmpty(): Boolean { + return size == 0 + } + + override fun iterator(): Iterator> { + return SetMapIterator(set) + } + } + + class SetMapIterator(set: Set) : Iterator> { + private val iterator = set.iterator() + override fun hasNext(): Boolean { + return iterator.hasNext() + } + + override fun next(): Map.Entry { + return Entry(iterator.next()) + } + } + + data class Entry(override val key: K) : Map.Entry { + override val value: Unit + get() = Unit + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/SimpHashMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SimpHashMap.kt similarity index 68% rename from src/main/kotlin/cn/tursom/core/datastruct/SimpHashMap.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SimpHashMap.kt index ae9ec15..30b84c4 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/SimpHashMap.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SimpHashMap.kt @@ -24,15 +24,15 @@ class SimpHashMap( } } - override fun put(key: K, value: V): V? { - return hashMap.put(key, value) - } + override fun put(key: K, value: V): V? { + return hashMap.put(key, value) + } - override fun putAll(from: Map) { - hashMap.putAll(from) - } + override fun putAll(from: Map) { + hashMap.putAll(from) + } - override fun remove(key: K): V? { - return hashMap.remove(key) - } + override fun remove(key: K): V? { + return hashMap.remove(key) + } } \ No newline at end of file diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt new file mode 100644 index 0000000..ac9d6dd --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SimpMap.kt @@ -0,0 +1,34 @@ +package cn.tursom.core.datastruct + +interface SimpMap : MutableMap { + /** + * @return prev value + */ + operator fun set(key: K, value: V) + + infix fun delete(key: K): V? + + fun setAndGet(key: K, value: V): V? { + val prev = get(key) + set(key, value) + return prev + } + + override fun put(key: K, value: V): V? = setAndGet(key, value) + + override fun remove(key: K): V? = delete(key) + + /** + * 清空整个表 + */ + override fun clear() + + fun first(): V? + + override infix fun putAll(from: Map) { + from.forEach { (k, u) -> + set(k, u) + } + } +} + diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt new file mode 100644 index 0000000..f7eec07 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/SoftArrayMap.kt @@ -0,0 +1,21 @@ +package cn.tursom.core.datastruct + +import java.lang.ref.SoftReference + +class SoftArrayMap(val map: MutableMap>) : MutableMap { + constructor(initialCapacity: Int = 16) : this(HashMap(initialCapacity)) + + override val size: Int get() = map.size + override val entries: MutableSet> get() = throw NotImplementedError() + override val keys: MutableSet get() = map.keys + override val values: MutableCollection get() = throw NotImplementedError() + + override fun put(key: K, value: V): V? = map.put(key, SoftReference(value))?.get() + override fun remove(key: K): V? = map.remove(key)?.get() + override fun clear() = map.clear() + override fun containsKey(key: K): Boolean = map.containsKey(key) + override fun containsValue(value: V): Boolean = map.containsValue(SoftReference(value)) + override fun get(key: K): V? = map[key]?.get() + override fun isEmpty(): Boolean = map.isEmpty() + override fun putAll(from: Map) = from.forEach { (k, u) -> map.put(k, SoftReference(u)) } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/StepList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/StepList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/StepList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/StepList.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/StringRadixTree.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/StringRadixTree.kt similarity index 98% rename from src/main/kotlin/cn/tursom/core/datastruct/StringRadixTree.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/StringRadixTree.kt index c810be3..221ccfb 100644 --- a/src/main/kotlin/cn/tursom/core/datastruct/StringRadixTree.kt +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/StringRadixTree.kt @@ -210,7 +210,12 @@ class StringRadixTree { /** * 基数树的节点,用来储存数据和子节点 */ - private data class Node(var str: String = "", var value: T? = null, var parent: Node? = null, var subNodes: SimpMap> = ArrayMap(0)) { + private data class Node( + var str: String = "", + var value: T? = null, + var parent: Node? = null, + var subNodes: SimpMap> = ArrayMap(0) + ) { constructor(parent: Node, str: String = "", value: T? = null) : this(str, value, parent, parent.subNodes) { parent.subNodes = ArrayMap(1) parent.subNodes.setAndGet(this[0], this) diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt new file mode 100644 index 0000000..b08773f --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncCollection.kt @@ -0,0 +1,10 @@ +package cn.tursom.core.datastruct.async.interfaces + +interface AsyncCollection { + val size: Int + + suspend fun isEmpty(): Boolean + suspend infix fun contains(element: @UnsafeVariance E): Boolean + suspend infix fun containsAll(elements: AsyncCollection<@UnsafeVariance E>): Boolean + suspend fun forEach(action: suspend (E) -> Boolean): Boolean +} \ No newline at end of file diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt new file mode 100644 index 0000000..f69ef4c --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncMap.kt @@ -0,0 +1,24 @@ +package cn.tursom.core.datastruct.async.interfaces + +interface AsyncMap : AsyncCollection> { + override val size: Int + val entries: AsyncSet> + val keys: AsyncSet + val values: AsyncCollection + + suspend infix fun containsKey(key: K): Boolean + suspend infix fun containsValue(value: V): Boolean + suspend infix fun get(key: K): V? + + override suspend fun isEmpty(): Boolean + suspend fun isNotEmpty(): Boolean = !isEmpty() + + override suspend fun contains(element: Map.Entry): Boolean { + return get(element.key) == element.value + } + + override suspend fun containsAll(elements: AsyncCollection>): Boolean { + return elements.forEach { contains(it) } + } +} + diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt new file mode 100644 index 0000000..504d713 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableMap.kt @@ -0,0 +1,9 @@ +package cn.tursom.core.datastruct.async.interfaces + +interface AsyncPotableMap : AsyncMap { + suspend fun clear() + suspend fun set(key: K, value: V): V? + suspend fun putIfAbsent(key: K, value: V): Boolean + suspend infix fun putAll(from: Map) + suspend infix fun remove(key: K): V? +} \ No newline at end of file diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt new file mode 100644 index 0000000..86ac5d0 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncPotableSet.kt @@ -0,0 +1,9 @@ +package cn.tursom.core.datastruct.async.interfaces + +interface AsyncPotableSet : AsyncSet { + suspend fun clear(): AsyncPotableSet + suspend fun put(key: K): AsyncPotableSet + suspend fun putIfAbsent(key: K): Boolean + suspend infix fun putAll(from: Set): AsyncPotableSet + suspend infix fun remove(key: K): AsyncPotableSet +} \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncSet.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncSet.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncSet.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/async/interfaces/AsyncSet.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingArrayList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingArrayList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingArrayList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingArrayList.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingLinkedList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingLinkedList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingLinkedList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingLinkedList.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/BlockingList.kt diff --git a/src/main/kotlin/cn/tursom/core/datastruct/concurrent/ConcurrentLinkedList.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/ConcurrentLinkedList.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/datastruct/concurrent/ConcurrentLinkedList.kt rename to ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/concurrent/ConcurrentLinkedList.kt diff --git a/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/tools.kt b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/tools.kt new file mode 100644 index 0000000..b03d391 --- /dev/null +++ b/ts-core/ts-datastruct/src/main/kotlin/cn/tursom/core/datastruct/tools.kt @@ -0,0 +1,31 @@ +package cn.tursom.core.datastruct + +operator fun List.get(startIndex: Int = 0, endIndex: Int = size, step: Int = 1): List { + if (step <= 0) throw IllegalArgumentException("step($step) is negative or zero") + val fromIndex = when { + startIndex < 0 -> size + startIndex + startIndex >= size -> size + else -> startIndex + } + val toIndex = when { + endIndex < 0 -> size + endIndex + 1 + endIndex >= size -> size + else -> endIndex + } + var targetList = if (fromIndex > toIndex) ReversedList(subList(toIndex, fromIndex)) else subList(fromIndex, toIndex) + if (step != 1) targetList = targetList step step + return targetList +} + +operator fun List.get(intProgression: IntProgression): List { + val first = intProgression.first + val last = intProgression.last + val step = intProgression.step + return when { + step == 0 -> get(first, last + if (last < 0) 0 else 1, 1) + step < 0 -> get(first + if (last > 0 && first >= 0) 1 else 0, last, -step) + else -> get(first, last + if (last < 0) 0 else 1, step) + } +} + +infix fun List.step(step: Int): List = StepList(this, step) \ No newline at end of file diff --git a/ts-core/ts-encrypt/build.gradle.kts b/ts-core/ts-encrypt/build.gradle.kts new file mode 100644 index 0000000..c03ffa2 --- /dev/null +++ b/ts-core/ts-encrypt/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + kotlin("jvm") +} + +dependencies { + api(project(":ts-core:ts-buffer")) + compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.6") +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + diff --git a/src/main/kotlin/cn/tursom/core/encrypt/AES.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AES.kt similarity index 95% rename from src/main/kotlin/cn/tursom/core/encrypt/AES.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AES.kt index 481b3e2..c65a21e 100644 --- a/src/main/kotlin/cn/tursom/core/encrypt/AES.kt +++ b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AES.kt @@ -24,7 +24,14 @@ class AES( it.generateKey() }) - constructor(key: ByteArray, keySize: Int = key.size, offset: Int = 0) : this(SecretKeySpec(key, offset, keySize, "AES")) + constructor(key: ByteArray, keySize: Int = key.size, offset: Int = 0) : this( + SecretKeySpec( + key, + offset, + keySize, + "AES" + ) + ) override fun encrypt(data: ByteArray, offset: Int, size: Int): ByteArray { return encryptCipher.doFinal(data, offset, size) diff --git a/src/main/kotlin/cn/tursom/core/encrypt/AESPool.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AESPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/encrypt/AESPool.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AESPool.kt diff --git a/src/main/kotlin/cn/tursom/core/encrypt/AbstractPublicKeyEncrypt.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AbstractPublicKeyEncrypt.kt similarity index 97% rename from src/main/kotlin/cn/tursom/core/encrypt/AbstractPublicKeyEncrypt.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AbstractPublicKeyEncrypt.kt index 0bb9244..fe9dd4a 100644 --- a/src/main/kotlin/cn/tursom/core/encrypt/AbstractPublicKeyEncrypt.kt +++ b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/AbstractPublicKeyEncrypt.kt @@ -94,8 +94,11 @@ abstract class AbstractPublicKeyEncrypt( override fun encrypt(data: ByteArray, offset: Int, size: Int): ByteArray = blockCipher.encrypt(data, offset, size) override fun decrypt(data: ByteArray, offset: Int, size: Int): ByteArray = blockCipher.decrypt(data, offset, size) - override fun encrypt(data: ByteArray, buffer: ByteArray, bufferOffset: Int, offset: Int, size: Int): Int = blockCipher.encrypt(data, buffer, bufferOffset, offset, size) - override fun decrypt(data: ByteArray, buffer: ByteArray, bufferOffset: Int, offset: Int, size: Int): Int = blockCipher.decrypt(data, buffer, bufferOffset, offset, size) + override fun encrypt(data: ByteArray, buffer: ByteArray, bufferOffset: Int, offset: Int, size: Int): Int = + blockCipher.encrypt(data, buffer, bufferOffset, offset, size) + + override fun decrypt(data: ByteArray, buffer: ByteArray, bufferOffset: Int, offset: Int, size: Int): Int = + blockCipher.decrypt(data, buffer, bufferOffset, offset, size) protected open fun signature(digest: String) = "${digest}with$algorithm" diff --git a/src/main/kotlin/cn/tursom/core/encrypt/BlockCipherModeOfOperation.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/BlockCipherModeOfOperation.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/encrypt/BlockCipherModeOfOperation.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/BlockCipherModeOfOperation.kt diff --git a/src/main/kotlin/cn/tursom/core/encrypt/DSA.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/DSA.kt similarity index 86% rename from src/main/kotlin/cn/tursom/core/encrypt/DSA.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/DSA.kt index cae3f82..66f67c8 100644 --- a/src/main/kotlin/cn/tursom/core/encrypt/DSA.kt +++ b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/DSA.kt @@ -31,5 +31,7 @@ class DSA( it.generateKeyPair() }) - constructor(publicKey: ByteArray) : this(KeyFactory.getInstance("DSA").generatePublic(X509EncodedKeySpec(publicKey)) as DSAPublicKey) + constructor(publicKey: ByteArray) : this( + KeyFactory.getInstance("DSA").generatePublic(X509EncodedKeySpec(publicKey)) as DSAPublicKey + ) } \ No newline at end of file diff --git a/src/main/kotlin/cn/tursom/core/encrypt/ECC.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/ECC.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/encrypt/ECC.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/ECC.kt diff --git a/src/main/kotlin/cn/tursom/core/encrypt/Encrypt.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/Encrypt.kt similarity index 72% rename from src/main/kotlin/cn/tursom/core/encrypt/Encrypt.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/Encrypt.kt index 5c24efe..24a2420 100644 --- a/src/main/kotlin/cn/tursom/core/encrypt/Encrypt.kt +++ b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/Encrypt.kt @@ -12,8 +12,21 @@ interface Encrypt { fun encrypt(data: ByteArray, offset: Int = 0, size: Int = data.size - offset): ByteArray fun decrypt(data: ByteArray, offset: Int = 0, size: Int = data.size - offset): ByteArray - fun encrypt(data: ByteArray, buffer: ByteArray, bufferOffset: Int = 0, offset: Int = 0, size: Int = data.size - offset): Int - fun decrypt(data: ByteArray, buffer: ByteArray, bufferOffset: Int = 0, offset: Int = 0, size: Int = data.size - offset): Int + fun encrypt( + data: ByteArray, + buffer: ByteArray, + bufferOffset: Int = 0, + offset: Int = 0, + size: Int = data.size - offset + ): Int + + fun decrypt( + data: ByteArray, + buffer: ByteArray, + bufferOffset: Int = 0, + offset: Int = 0, + size: Int = data.size - offset + ): Int fun encrypt(data: ByteBuffer): ByteArray { return if (data.hasArray) { diff --git a/src/main/kotlin/cn/tursom/core/encrypt/EncryptPool.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/EncryptPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/encrypt/EncryptPool.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/EncryptPool.kt diff --git a/src/main/kotlin/cn/tursom/core/encrypt/PublicKeyEncrypt.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/PublicKeyEncrypt.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/encrypt/PublicKeyEncrypt.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/PublicKeyEncrypt.kt diff --git a/src/main/kotlin/cn/tursom/core/encrypt/RSA.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/RSA.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/encrypt/RSA.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/RSA.kt diff --git a/src/main/kotlin/cn/tursom/core/encrypt/RSAPool.kt b/ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/RSAPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/encrypt/RSAPool.kt rename to ts-core/ts-encrypt/src/kotlin/cn/tursom/core/encrypt/RSAPool.kt diff --git a/ts-core/ts-hash/build.gradle.kts b/ts-core/ts-hash/build.gradle.kts new file mode 100644 index 0000000..1dca010 --- /dev/null +++ b/ts-core/ts-hash/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + kotlin("jvm") +} + +dependencies { + api(project(":ts-core")) + api(project(":ts-core:ts-buffer")) + compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.6") +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + diff --git a/src/main/kotlin/cn/tursom/core/hash/MurmurHash3.kt b/ts-core/ts-hash/src/main/kotlin/cn/tursom/core/hash/MurmurHash3.kt similarity index 94% rename from src/main/kotlin/cn/tursom/core/hash/MurmurHash3.kt rename to ts-core/ts-hash/src/main/kotlin/cn/tursom/core/hash/MurmurHash3.kt index 9caad37..bea6dc0 100644 --- a/src/main/kotlin/cn/tursom/core/hash/MurmurHash3.kt +++ b/ts-core/ts-hash/src/main/kotlin/cn/tursom/core/hash/MurmurHash3.kt @@ -49,7 +49,8 @@ object MurmurHash3 { var i = offset while (i < roundedEnd) { // little endian load order - var k1: Int = data[i].toInt() and 0xff or (data[i + 1].toInt() and 0xff shl 8) or (data[i + 2].toInt() and 0xff shl 16) or (data[i + 3].toInt() shl 24) + var k1: Int = + data[i].toInt() and 0xff or (data[i + 1].toInt() and 0xff shl 8) or (data[i + 2].toInt() and 0xff shl 16) or (data[i + 3].toInt() shl 24) k1 *= c1 k1 = k1 shl 15 or (k1 ushr 17) // ROTL32(k1,15); k1 *= c2 @@ -154,12 +155,24 @@ object MurmurHash3 { return fmix32(h1 xor nBytes) } - fun murmurHash3_x64_128(key: ByteArray, offset: Int = 0, len: Int = key.size - offset, seed: Int, out: LongPair = LongPair()): LongPair { + fun murmurHash3_x64_128( + key: ByteArray, + offset: Int = 0, + len: Int = key.size - offset, + seed: Int, + out: LongPair = LongPair() + ): LongPair { return murmurHash3_x64_128(key, offset, len, seed.toLong() and 0x00000000FFFFFFFFL, out) } /** Returns the MurmurHash3_x64_128 hash, placing the result in "out". */ - fun murmurHash3_x64_128(key: ByteArray, offset: Int = 0, len: Int = key.size - offset, seed: Long = 0, out: LongPair = LongPair()): LongPair { + fun murmurHash3_x64_128( + key: ByteArray, + offset: Int = 0, + len: Int = key.size - offset, + seed: Long = 0, + out: LongPair = LongPair() + ): LongPair { // The original algorithm does have a 32 bit unsigned seed. // We have to mask to match the behavior of the unsigned types and prevent sign extension. var h1 = seed diff --git a/ts-core/ts-pool/build.gradle.kts b/ts-core/ts-pool/build.gradle.kts new file mode 100644 index 0000000..f61d245 --- /dev/null +++ b/ts-core/ts-pool/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + kotlin("jvm") +} + +dependencies { + api(project(":ts-core:ts-buffer")) + api(project(":ts-core:ts-datastruct")) +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + diff --git a/src/main/kotlin/cn/tursom/core/RewriteFlvChecker.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/RewriteFlvChecker.kt similarity index 91% rename from src/main/kotlin/cn/tursom/core/RewriteFlvChecker.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/RewriteFlvChecker.kt index da59444..b539ec7 100644 --- a/src/main/kotlin/cn/tursom/core/RewriteFlvChecker.kt +++ b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/RewriteFlvChecker.kt @@ -3,7 +3,9 @@ package cn.tursom.core import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.buffer.impl.HeapByteBuffer import cn.tursom.core.pool.HeapMemoryPool -import java.io.* +import java.io.File +import java.io.InputStream +import java.io.OutputStream /** * 原理 https://www.cnblogs.com/lidabo/p/9018548.html @@ -38,7 +40,12 @@ class RewriteFlvChecker { private val skipBuf = ByteArray(4) private val zeroTimestamp = byteArrayOf(0, 0, 0, 0) - private fun handleFrame(inputStream: InputStream, outputStream: OutputStream, lastTimestampRead: IntArray, lastTimestampWrite: IntArray): Boolean { + private fun handleFrame( + inputStream: InputStream, + outputStream: OutputStream, + lastTimestampRead: IntArray, + lastTimestampWrite: IntArray + ): Boolean { // 读取前一个tag size val frame = pool.get() frame.put(inputStream, 4) @@ -88,7 +95,13 @@ class RewriteFlvChecker { /** * 处理音/视频时间戳 */ - private fun dealTimestamp(buffer: ByteBuffer, timestamp: Int, tagType: Int, lastTimestampRead: IntArray, lastTimestampWrite: IntArray) { + private fun dealTimestamp( + buffer: ByteBuffer, + timestamp: Int, + tagType: Int, + lastTimestampRead: IntArray, + lastTimestampWrite: IntArray + ) { // 如果是首帧 if (lastTimestampRead[tagType] == -1) { lastTimestampWrite[tagType] = 0 diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/InstantByteBuffer.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer/InstantByteBuffer.kt similarity index 86% rename from src/main/kotlin/cn/tursom/core/buffer/impl/InstantByteBuffer.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer/InstantByteBuffer.kt index 490516a..a390818 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/impl/InstantByteBuffer.kt +++ b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer/InstantByteBuffer.kt @@ -5,8 +5,8 @@ import cn.tursom.core.buffer.ProxyByteBuffer import cn.tursom.core.pool.MemoryPool class InstantByteBuffer( - override val agent: ByteBuffer, - val pool: MemoryPool + override val agent: ByteBuffer, + val pool: MemoryPool ) : ProxyByteBuffer, ByteBuffer by agent { override var closed = false diff --git a/src/main/kotlin/cn/tursom/core/buffer/impl/PooledByteBuffer.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer/PooledByteBuffer.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/buffer/impl/PooledByteBuffer.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer/PooledByteBuffer.kt index bec27ea..a3a98ca 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/impl/PooledByteBuffer.kt +++ b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/buffer/PooledByteBuffer.kt @@ -1,8 +1,8 @@ package cn.tursom.core.buffer.impl import cn.tursom.core.buffer.ByteBuffer -import cn.tursom.core.buffer.ProxyByteBuffer import cn.tursom.core.buffer.ClosedBufferException +import cn.tursom.core.buffer.ProxyByteBuffer import cn.tursom.core.pool.MemoryPool import java.lang.ref.PhantomReference import java.lang.ref.Reference diff --git a/src/main/kotlin/cn/tursom/core/pool/AbstractMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/AbstractMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/AbstractMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/AbstractMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/DirectMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/DirectMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/DirectMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/DirectMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/ExpandableMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ExpandableMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/ExpandableMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ExpandableMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/HeapMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/HeapMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/HeapMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/HeapMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/InstantMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/InstantMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/InstantMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/InstantMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/LinkedPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LinkedPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/LinkedPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LinkedPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/LongBitSetAbstractMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetAbstractMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/LongBitSetAbstractMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetAbstractMemoryPool.kt index 0e4e041..8eb6d80 100644 --- a/src/main/kotlin/cn/tursom/core/pool/LongBitSetAbstractMemoryPool.kt +++ b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetAbstractMemoryPool.kt @@ -1,9 +1,9 @@ package cn.tursom.core.pool -import cn.tursom.core.datastruct.LongBitSet import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.buffer.impl.HeapByteBuffer import cn.tursom.core.buffer.impl.PooledByteBuffer +import cn.tursom.core.datastruct.LongBitSet /** * 无锁,固定容量的内存池 diff --git a/src/main/kotlin/cn/tursom/core/pool/LongBitSetDirectMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetDirectMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/LongBitSetDirectMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetDirectMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/LongBitSetHeapMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetHeapMemoryPool.kt similarity index 93% rename from src/main/kotlin/cn/tursom/core/pool/LongBitSetHeapMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetHeapMemoryPool.kt index a9bb788..5ff1af7 100644 --- a/src/main/kotlin/cn/tursom/core/pool/LongBitSetHeapMemoryPool.kt +++ b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/LongBitSetHeapMemoryPool.kt @@ -3,7 +3,7 @@ package cn.tursom.core.pool import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.buffer.impl.HeapByteBuffer -class LongBitSetHeapMemoryPool ( +class LongBitSetHeapMemoryPool( blockSize: Int, emptyPoolBuffer: (blockSize: Int) -> ByteBuffer = ::HeapByteBuffer ) : LongBitSetAbstractMemoryPool(blockSize, emptyPoolBuffer, HeapByteBuffer(64 * blockSize)) { diff --git a/src/main/kotlin/cn/tursom/core/pool/MarkedMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/MarkedMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/MarkedMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/MarkedMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/MemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/MemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/MemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/MemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/Pool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/Pool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/Pool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/Pool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/ScalabilityMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ScalabilityMemoryPool.kt similarity index 99% rename from src/main/kotlin/cn/tursom/core/pool/ScalabilityMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ScalabilityMemoryPool.kt index 4694d04..6944d37 100644 --- a/src/main/kotlin/cn/tursom/core/pool/ScalabilityMemoryPool.kt +++ b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ScalabilityMemoryPool.kt @@ -10,6 +10,7 @@ import java.util.concurrent.atomic.AtomicBoolean */ class ScalabilityMemoryPool(private val poolFactory: () -> MemoryPool) : MemoryPool { private val poolList = ConcurrentLinkedQueue>() + @Volatile private var usingPool: MemoryPool private val poolLock = AtomicBoolean(false) diff --git a/src/main/kotlin/cn/tursom/core/pool/ThreadLocalMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadLocalMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/ThreadLocalMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadLocalMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeAbstractMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeAbstractMemoryPool.kt similarity index 97% rename from src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeAbstractMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeAbstractMemoryPool.kt index 1fd68f5..58c6e99 100644 --- a/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeAbstractMemoryPool.kt +++ b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeAbstractMemoryPool.kt @@ -30,7 +30,7 @@ abstract class ThreadUnsafeAbstractMemoryPool( } private fun unsafeGetMemory(token: Int): ByteBuffer { - return PooledByteBuffer(memoryPool.slice(token * blockSize, blockSize), this, token,autoCollection) + return PooledByteBuffer(memoryPool.slice(token * blockSize, blockSize), this, token, autoCollection) } /** diff --git a/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeDirectMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeDirectMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeDirectMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeDirectMemoryPool.kt diff --git a/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeHeapMemoryPool.kt b/ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeHeapMemoryPool.kt similarity index 100% rename from src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeHeapMemoryPool.kt rename to ts-core/ts-pool/src/main/kotlin/cn/tursom/core/pool/ThreadUnsafeHeapMemoryPool.kt