Skip to content

Commit

Permalink
[Refactor] Use Kotlin String?.orEmpty().
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Nov 28, 2023
1 parent a872204 commit 62eda8f
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SetSeLinuxContextDialogFragment : AppCompatDialogFragment() {
private val argsSeLinuxContext: String
get() {
val attributes = args.file.attributes as PosixFileAttributes
return attributes.seLinuxContext()?.toString() ?: ""
return attributes.seLinuxContext()?.toString().orEmpty()
}

private fun restoreSeLinuxContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal class LocalArchiveFileSystem(
if (!entry.isSymbolicLink) {
throw NotLinkException(link.toString())
}
entry.symbolicLinkTarget ?: ""
entry.symbolicLinkTarget.orEmpty()
}

fun addPassword(password: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class UriAuthority(
throw IllegalArgumentException(e)
}
// URI.getRawAuthority() returns null when authority is empty.
return uri.rawAuthority ?: ""
return uri.rawAuthority.orEmpty()
}

// toString() is called by UI when the URI may not be valid, so build the string manually.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ object FtpFileSystemProvider : FileSystemProvider(), PathObservableProvider, Sea
get() {
val protocol = Protocol.fromScheme(scheme)
val port = if (port != -1) port else protocol.defaultPort
val username = userInfo ?: ""
val username = userInfo.orEmpty()
val queryUri = decodedQueryByteString?.toString()?.let { Uri.parse(it) }
val mode = queryUri?.getQueryParameter(FtpPath.QUERY_PARAMETER_MODE)
?.let { mode -> Mode.entries.first { it.name.equals(mode, true) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ object SftpFileSystemProvider : FileSystemProvider(), PathObservableProvider, Se
private val URI.sftpAuthority: Authority
get() {
val port = if (port != -1) port else Authority.DEFAULT_PORT
val username = userInfo ?: ""
val username = userInfo.orEmpty()
return Authority(host, port, username)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object SmbFileSystemProvider : FileSystemProvider(), PathObservableProvider, Sea
private val URI.smbAuthority: Authority
get() {
val port = if (port != -1) port else Authority.DEFAULT_PORT
val userInfo = userInfo ?: ""
val userInfo = userInfo.orEmpty()
val domainSeparatorIndex = userInfo.indexOf('\\')
val username: String
val domain: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ val Address.addressLines: Iterable<String?>
// @see com.android.documentsui.inspector.MediaView.getAddress
val Address.userFriendlyString: String?
get() =
addressLines.joinToString("\n") { it ?: "" }.takeIfNotBlank()
addressLines.joinToString("\n") { it.orEmpty() }.takeIfNotBlank()
?: locality.takeIfNotBlank() ?: subAdminArea.takeIfNotBlank()
?: adminArea.takeIfNotBlank() ?: countryName.takeIfNotBlank()

0 comments on commit 62eda8f

Please sign in to comment.