diff --git a/EzXHelper/api/EzXHelper.api b/EzXHelper/api/EzXHelper.api index bf65369..505634e 100644 --- a/EzXHelper/api/EzXHelper.api +++ b/EzXHelper/api/EzXHelper.api @@ -757,6 +757,14 @@ 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 requireCount (I)Ljava/lang/Object; + public final fun requireCount (Lkotlin/jvm/functions/Function1;I)Ljava/lang/Object; + public final fun requireCount (Lkotlin/jvm/functions/Function1;Lkotlin/ranges/IntRange;)Ljava/lang/Object; + public final fun requireCount (Lkotlin/ranges/IntRange;)Ljava/lang/Object; + public final fun requireCountOrNull (I)Ljava/lang/Object; + public final fun requireCountOrNull (Lkotlin/jvm/functions/Function1;I)Ljava/lang/Object; + public final fun requireCountOrNull (Lkotlin/jvm/functions/Function1;Lkotlin/ranges/IntRange;)Ljava/lang/Object; + public final fun requireCountOrNull (Lkotlin/ranges/IntRange;)Ljava/lang/Object; public final fun requireSingle ()Ljava/lang/Object; public final fun requireSingle (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun requireSingleOrNull ()Ljava/lang/Object; diff --git a/EzXHelper/build.gradle b/EzXHelper/build.gradle index b3d49d8..b4ad478 100644 --- a/EzXHelper/build.gradle +++ b/EzXHelper/build.gradle @@ -6,7 +6,7 @@ plugins { id 'signing' } -def versionName = "2.1.2" +def versionName = "2.2.0" android { compileSdkVersion = 34 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 d9fbc07..e405ec0 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 @@ -133,6 +133,54 @@ abstract class BaseFinder(protected var sequence: Sequence) : INamed return if (o == null) null else this as Self } + @Throws(IllegalStateException::class) + fun requireCount(count: Int) = applyThis { + if (sequence.count() != count) { + throw IllegalStateException("The count of sequence is not $count") + } + } + + @Suppress("UNCHECKED_CAST") + fun requireCountOrNull(count: Int): Self? { + return if (sequence.count() == count) this as Self else null + } + + @Throws(IllegalStateException::class) + fun requireCount(condition: T.() -> Boolean, count: Int) = applyThis { + if (sequence.count(condition) != count) { + throw IllegalStateException("The count of sequence is not $count") + } + } + + @Suppress("UNCHECKED_CAST") + fun requireCountOrNull(condition: T.() -> Boolean, count: Int): Self? { + return if (sequence.count(condition) == count) this as Self else null + } + + @Throws(IllegalStateException::class) + fun requireCount(range: IntRange) = applyThis { + if (sequence.count() !in range) { + throw IllegalStateException("The count of sequence is not in $range") + } + } + + @Suppress("UNCHECKED_CAST") + fun requireCountOrNull(range: IntRange): Self? { + return if (sequence.count() in range) this as Self else null + } + + @Throws(IllegalStateException::class) + fun requireCount(condition: T.() -> Boolean, range: IntRange) = applyThis { + if (sequence.count(condition) !in range) { + throw IllegalStateException("The count of sequence is not in $range") + } + } + + @Suppress("UNCHECKED_CAST") + fun requireCountOrNull(condition: T.() -> Boolean, range: IntRange): Self? { + return if (sequence.count(condition) in range) this as Self else null + } + /** * Get the single element or throw an exception if there is no such element or more than one element. */ diff --git a/README.md b/README.md index 70ac038..b1c0f13 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.1.2` 旧版本请看`1.x`分支 +2.x版本已经发布!最新版为`2.2.0` 旧版本请看`1.x`分支 ### 使用本库的项目 diff --git a/README_en.md b/README_en.md index 15f119a..d8e9bc4 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.1.2`. Old version please look the `1.x` branch. +2.x is released now! The latest version is `2.2.0`. Old version please look the `1.x` branch. ### Projects that use this library diff --git a/build.gradle b/build.gradle index ffdd8cc..e87d8d2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.3.0' apply false - id 'com.android.library' version '8.3.0' apply false + id 'com.android.application' version '8.4.0' apply false + id 'com.android.library' version '8.4.0' 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 744c64d..20db9ad 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.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists