[Android] Rewrite containsPath() functions in PathUtils using Kotlin's firstOrNull() extension function.

Isira Seneviratne git at videolan.org
Thu Apr 16 11:52:08 CEST 2020


vlc-android | branch: master | Isira Seneviratne <isirasen96 at gmail.com> | Sat Apr 11 19:29:04 2020 +0530| [7cb20b3a4838dd617a24c37e11b646b65d8714e0] | committer: Geoffrey Métais

Rewrite containsPath() functions in PathUtils using Kotlin's firstOrNull() extension function.

> https://code.videolan.org/videolan/vlc-android/commit/7cb20b3a4838dd617a24c37e11b646b65d8714e0
---

 .../src/main/java/org/videolan/tools/PathUtils.kt      | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/application/tools/src/main/java/org/videolan/tools/PathUtils.kt b/application/tools/src/main/java/org/videolan/tools/PathUtils.kt
index e8bfd541c..ad9f5f453 100644
--- a/application/tools/src/main/java/org/videolan/tools/PathUtils.kt
+++ b/application/tools/src/main/java/org/videolan/tools/PathUtils.kt
@@ -1,24 +1,14 @@
 package org.videolan.tools
 
 /**
- *  Checks if the specified (sanitized) path is contained in this collection (of sanitized pathes)
+ *  Checks if the specified (sanitized) path is contained in this collection (of sanitized paths)
  */
-fun List<String>.containsPath(path: String): Boolean {
-    for (string in this) {
-        if (string.sanitizePath() == path.sanitizePath()) {
-            return true
-        }
-    }
-    return false
-}
+fun List<String>.containsPath(path: String) = any { it.sanitizePath() == path.sanitizePath() }
 
 /**
- *  Checks if the specified (sanitized) path is contained in this array (of sanitized pathes)
+ *  Checks if the specified (sanitized) path is contained in this array (of sanitized paths)
  */
-fun Array<String>.containsPath(path: String): Boolean {
-
-    return toList().containsPath(path)
-}
+fun Array<String>.containsPath(path: String) = any { it.sanitizePath() == path.sanitizePath() }
 
 /**
  * Sanitize a path [String] to remove leading "file://" and trailing "/"



More information about the Android mailing list