diff --git a/EzXHelper/api/EzXHelper.api b/EzXHelper/api/EzXHelper.api index 7b2123f..c855567 100644 --- a/EzXHelper/api/EzXHelper.api +++ b/EzXHelper/api/EzXHelper.api @@ -574,7 +574,11 @@ public abstract class com/github/kyuubiran/ezxhelper/finders/base/BaseFinder : c public final fun plusAssign (Ljava/lang/Iterable;)V public final fun plusAssign (Lkotlin/sequences/Sequence;)V public final fun plusAssign ([Ljava/lang/Object;)V + public final fun requireSingle ()Ljava/lang/Object; + public final fun requireSingleOrNull ()Ljava/lang/Object; protected final fun setSequence (Lkotlin/sequences/Sequence;)V + public final fun single ()Ljava/lang/Object; + public final fun singleOrNull ()Ljava/lang/Object; public final fun toCollection (Ljava/util/Collection;)Ljava/util/Collection; public final fun toHashSet ()Ljava/util/HashSet; public final fun toList ()Ljava/util/List; diff --git a/EzXHelper/build.gradle b/EzXHelper/build.gradle index 370510e..9959424 100644 --- a/EzXHelper/build.gradle +++ b/EzXHelper/build.gradle @@ -6,16 +6,16 @@ plugins { id 'signing' } -def versionName = "2.0.8" +def versionName = "2.0.9" android { - compileSdkVersion = 33 - buildToolsVersion = "33.0.1" + compileSdkVersion = 34 + buildToolsVersion = "34.0.0" namespace = "com.github.kyuubiran" defaultConfig { minSdkVersion 24 - targetSdkVersion 33 + targetSdkVersion 34 consumerProguardFiles "consumer-rules.pro" } diff --git a/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/finders/base/BaseFinder.kt b/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/finders/base/BaseFinder.kt index a2c3854..5496cb7 100644 --- a/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/finders/base/BaseFinder.kt +++ b/EzXHelper/src/main/java/com/github/kyuubiran/ezxhelper/finders/base/BaseFinder.kt @@ -6,7 +6,7 @@ import com.github.kyuubiran.ezxhelper.Config import com.github.kyuubiran.ezxhelper.interfaces.INamed import com.github.kyuubiran.ezxhelper.misc.FinderExceptionMessage -abstract class BaseFinder constructor(protected var sequence: Sequence) : INamed { +abstract class BaseFinder(protected var sequence: Sequence) : INamed { // region exception message protected val exceptMsg: FinderExceptionMessage? = @@ -14,12 +14,14 @@ abstract class BaseFinder constructor(protected var sequence: Sequence< protected val exceptionMessageEnabled = exceptMsg != null - protected inline fun exceptMessageScope(block: FinderExceptionMessage.() -> Unit) = exceptMsg?.block() + protected inline fun exceptMessageScope(block: FinderExceptionMessage.() -> Unit) = + exceptMsg?.block() // endregion @Suppress("UNCHECKED_CAST") - protected inline fun applyThis(block: BaseFinder.() -> Unit) = this.apply(block) as Self + protected inline fun applyThis(block: BaseFinder.() -> Unit) = + this.apply(block) as Self // region get elem @@ -103,6 +105,34 @@ abstract class BaseFinder constructor(protected var sequence: Sequence< */ open fun lastOrNull(condition: T.() -> Boolean) = sequence.lastOrNull(condition) + /** + * Check sequence only has one element. + */ + @Throws(IllegalArgumentException::class, NoSuchElementException::class) + fun requireSingle() = applyThis { + sequence.single() + } + + /** + * Check sequence only has one element or null if not found. + */ + @Suppress("UNCHECKED_CAST") + fun requireSingleOrNull(): Self? { + val o = sequence.singleOrNull() + return if (o == null) null else this as Self + } + + /** + * Get the single element or throw an exception if there is no such element. + */ + @Throws(IllegalArgumentException::class, NoSuchElementException::class) + fun single() = sequence.single() + + /** + * Get the single element or null if not found. + */ + fun singleOrNull() = sequence.singleOrNull() + // endregion /** @@ -128,7 +158,8 @@ abstract class BaseFinder constructor(protected var sequence: Sequence< * @param action the action * @return [Self] the finder */ - fun onEachIndexed(action: (index: Int, T) -> Unit): Self = applyThis { sequence.forEachIndexed(action) } + fun onEachIndexed(action: (index: Int, T) -> Unit): Self = + applyThis { sequence.forEachIndexed(action) } /** * For-each loop for. @@ -174,7 +205,8 @@ abstract class BaseFinder constructor(protected var sequence: Sequence< * @param transform the transform action * @return [MutableSet] the mutable set */ - fun mapToMutableSet(transform: (T) -> R): MutableSet = sequence.map(transform).toMutableSet() + fun mapToMutableSet(transform: (T) -> R): MutableSet = + sequence.map(transform).toMutableSet() /** * Map to the hashset. @@ -188,7 +220,10 @@ abstract class BaseFinder constructor(protected var sequence: Sequence< * @param transform the transform action * @return [MutableCollection] the collection */ - fun mapToCollection(destination: C, transform: (T) -> R): C where C : MutableCollection = + fun mapToCollection( + destination: C, + transform: (T) -> R + ): C where C : MutableCollection = sequence.map(transform).toCollection(destination) // endregion @@ -227,7 +262,8 @@ abstract class BaseFinder constructor(protected var sequence: Sequence< * Make sequence to the collection. * @return [MutableCollection] the collection */ - fun toCollection(collection: C): C where C : MutableCollection = sequence.toCollection(collection) + fun toCollection(collection: C): C where C : MutableCollection = + sequence.toCollection(collection) // endregion diff --git a/README.md b/README.md index 095fb2e..79844ab 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ 加入Telegram群组来获取帮助: [![Telegram](https://img.shields.io/badge/Join-Telegram-blue)](https://t.me/EzXHelper) 一个使Xposed模块开发变的更轻松的工具库,2.x版本已支持Java! -2.x版本已经发布!最新版为`2.0.8` 旧版本请看`1.x`分支 +2.x版本已经发布!最新版为`2.0.9` 旧版本请看`1.x`分支 ### 使用本库的项目 diff --git a/README_en.md b/README_en.md index 02d8f64..52cca80 100644 --- a/README_en.md +++ b/README_en.md @@ -4,7 +4,7 @@ Join Telegram group to get help: [![Telegram](https://img.shields.io/badge/Join-Telegram-blue)](https://t.me/EzXHelper) A library to make Xposed modules development easier, 2.x version supports Java! -2.x is released now! The latest version is `2.0.8`. Old version please look the `1.x` branch. +2.x is released now! The latest version is `2.0.9`. Old version please look the `1.x` branch. ### Projects that use this library diff --git a/build.gradle b/build.gradle index 26db1db..1964b49 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.1.2' apply false - id 'com.android.library' version '8.1.2' apply false - id 'org.jetbrains.kotlin.android' version '1.9.10' apply false + id 'com.android.application' version '8.2.2' apply false + id 'com.android.library' version '8.2.2' apply false + id 'org.jetbrains.kotlin.android' version '1.9.22' apply false id 'org.jetbrains.dokka' version '1.9.10' apply false id 'org.jetbrains.kotlinx.binary-compatibility-validator' version '0.13.2' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..a363877 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists