Skip to content
Permalink
Browse files

Always use named argument for `ignoreCase` in `String.equals()`

...to improve readability.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@here.com>
  • Loading branch information...
mnonnenmacher committed Sep 25, 2019
1 parent f5d65be commit 7a47228dd432e07812c2400444bf4199f5d5cc33
@@ -104,7 +104,7 @@ interface ClearlyDefinedService {
companion object {
@JsonCreator
@JvmStatic
fun fromString(value: String) = enumValues<Provider>().single { value.equals(it.value, true) }
fun fromString(value: String) = enumValues<Provider>().single { value.equals(it.value, ignoreCase = true) }
}

@JsonValue
@@ -129,7 +129,7 @@ interface ClearlyDefinedService {
companion object {
@JsonCreator
@JvmStatic
fun fromString(value: String) = enumValues<Provider>().single { value.equals(it.value, true) }
fun fromString(value: String) = enumValues<Provider>().single { value.equals(it.value, ignoreCase = true) }
}

@JsonValue
@@ -51,7 +51,7 @@ object ScannerCommand : CommandWithHelp() {
private class ScannerConverter : IStringConverter<ScannerFactory> {
override fun convert(scannerName: String): ScannerFactory {
// TODO: Consider allowing to enable multiple scanners (and potentially running them in parallel).
return Scanner.ALL.find { it.scannerName.equals(scannerName, true) }
return Scanner.ALL.find { it.scannerName.equals(scannerName, ignoreCase = true) }
?: throw ParameterException("Scanner '$scannerName' is not one of ${Scanner.ALL}.")
}
}
@@ -49,7 +49,7 @@ data class PackageCuration(
* disregarding the version.
*/
private fun isApplicableDisregardingVersion(pkgId: Identifier) =
id.type.equals(pkgId.type, true)
id.type.equals(pkgId.type, ignoreCase = true)
&& id.namespace == pkgId.namespace
&& id.name.equalsOrIsBlank(pkgId.name)

@@ -53,6 +53,6 @@ data class ScannerDetails(
* the scanners.
*/
fun isCompatible(other: ScannerDetails) =
name.equals(other.name, true) && configuration == other.configuration &&
name.equals(other.name, ignoreCase = true) && configuration == other.configuration &&
Semver(version, Semver.SemverType.LOOSE).diff(other.version) !in MAJOR_MINOR
}
@@ -183,7 +183,8 @@ fun generateEnumClass(
| /**
| * Return the enum value for the given [id], or null if it is no SPDX $description id.
| */
| fun forId(id: String) = values().find { id.equals(it.id, true) || id.equals(it.fullName, true) }
| fun forId(id: String) =
| values().find { id.equals(it.id, ignoreCase = true) || id.equals(it.fullName, ignoreCase = true) }
| }
|
|
@@ -444,7 +444,8 @@ enum class SpdxLicense(
/**
* Return the enum value for the given [id], or null if it is no SPDX license id.
*/
fun forId(id: String) = values().find { id.equals(it.id, true) || id.equals(it.fullName, true) }
fun forId(id: String) =
values().find { id.equals(it.id, ignoreCase = true) || id.equals(it.fullName, ignoreCase = true) }
}

/**
@@ -83,7 +83,8 @@ enum class SpdxLicenseException(
/**
* Return the enum value for the given [id], or null if it is no SPDX license exception id.
*/
fun forId(id: String) = values().find { id.equals(it.id, true) || id.equals(it.fullName, true) }
fun forId(id: String) =
values().find { id.equals(it.id, ignoreCase = true) || id.equals(it.fullName, ignoreCase = true) }
}

/**
@@ -56,7 +56,7 @@ fun filterVersionNames(version: String, names: List<String>, project: String? =
if (version.isBlank() || names.isEmpty()) return emptyList()

// If there are full matches, return them right away.
names.filter { it.equals(version, true) }.let { if (it.isNotEmpty()) return it }
names.filter { it.equals(version, ignoreCase = true) }.let { if (it.isNotEmpty()) return it }

// The list of supported version separators.
val versionSeparators = listOf('-', '_', '.')

0 comments on commit 7a47228

Please sign in to comment.
You can’t perform that action at this time.