From 8b8cbb39f8524c255d3c125b43d0116fbfd946a5 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 26 Apr 2021 22:06:13 -0700 Subject: [PATCH] Added Utils.capitalize() --- src/main/java/net/thauvin/erik/mobibot/Utils.kt | 10 +++++++++- .../java/net/thauvin/erik/mobibot/commands/Info.java | 3 +-- .../net/thauvin/erik/mobibot/modules/GoogleSearch.kt | 3 +-- .../net/thauvin/erik/mobibot/modules/StockQuote.kt | 2 +- .../java/net/thauvin/erik/mobibot/modules/Weather2.kt | 4 ++-- src/test/java/net/thauvin/erik/mobibot/UtilsTest.kt | 7 +++++++ version.properties | 6 +++--- 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.kt b/src/main/java/net/thauvin/erik/mobibot/Utils.kt index 4e49c89..62f1695 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.kt @@ -81,7 +81,15 @@ object Utils { val replace = arrayOf(if (isPrivate) "/msg $botNick" else "$botNick:", botNick) return StringUtils.replaceEach(text, searchFlags, replace) } - + + /** + * Capitalize a string. + */ + @JvmStatic + fun capitalize(s: String?): String { + return s!!.replaceFirstChar { it.uppercase() } + } + /** * Colorize a string. */ diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Info.java b/src/main/java/net/thauvin/erik/mobibot/commands/Info.java index e419d39..5af7d4b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Info.java +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Info.java @@ -36,7 +36,6 @@ import net.thauvin.erik.mobibot.Mobibot; import net.thauvin.erik.mobibot.ReleaseInfo; import net.thauvin.erik.mobibot.Utils; import net.thauvin.erik.mobibot.commands.links.LinksMgr; -import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import java.lang.management.ManagementFactory; @@ -44,7 +43,7 @@ import java.util.List; public class Info extends AbstractCommand { private final List allVersions = List.of( - StringUtils.capitalize(ReleaseInfo.PROJECT) + " " + ReleaseInfo.VERSION + Utils.capitalize(ReleaseInfo.PROJECT) + " " + ReleaseInfo.VERSION + " (" + Utils.green(ReleaseInfo.WEBSITE) + ')', "Written by " + ReleaseInfo.AUTHOR + " (" + Utils.green(ReleaseInfo.AUTHOR_URL) + ')'); diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt b/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt index bbaec32..a801f55 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt @@ -35,7 +35,6 @@ import net.thauvin.erik.mobibot.Mobibot import net.thauvin.erik.mobibot.Utils import net.thauvin.erik.mobibot.msg.Message import net.thauvin.erik.mobibot.msg.NoticeMessage -import org.apache.commons.lang3.StringUtils import org.jibble.pircbot.Colors import org.json.JSONException import org.json.JSONObject @@ -87,7 +86,7 @@ class GoogleSearch(bot: Mobibot) : ThreadedModule(bot) { @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List { if (apiKey.isNullOrBlank() || cseKey.isNullOrBlank()) { - throw ModuleException("${StringUtils.capitalize(GOOGLE_CMD)} is disabled. The API keys are missing.") + throw ModuleException("${Utils.capitalize(GOOGLE_CMD)} is disabled. The API keys are missing.") } return if (query.isNotBlank()) { val results = mutableListOf() diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt index 3244e41..e9c2905 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt @@ -122,7 +122,7 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { fun getQuote(symbol: String, apiKey: String?): List { if (apiKey.isNullOrBlank()) { throw ModuleException( - "${STOCK_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.") + "${Utils.capitalize(STOCK_CMD)} is disabled. The API key is missing.") } return if (symbol.isNotBlank()) { val debugMessage = "getQuote($symbol)" diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt index f3b740d..5a164b5 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt @@ -101,7 +101,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { fun getWeather(query: String, apiKey: String?): List { if (apiKey.isNullOrBlank()) { throw ModuleException( - "${WEATHER_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.") + "${Utils.capitalize(WEATHER_CMD)} is disabled. The API key is missing.") } val owm = OWM(apiKey) val messages = mutableListOf() @@ -149,7 +149,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { for (w in list) { if (w != null) { condition.append(' ') - .append(w.getDescription().replaceFirstChar { it.uppercase() }) + .append(Utils.capitalize(w.getDescription())) .append('.') } } diff --git a/src/test/java/net/thauvin/erik/mobibot/UtilsTest.kt b/src/test/java/net/thauvin/erik/mobibot/UtilsTest.kt index fbe1ffb..f62663d 100644 --- a/src/test/java/net/thauvin/erik/mobibot/UtilsTest.kt +++ b/src/test/java/net/thauvin/erik/mobibot/UtilsTest.kt @@ -32,6 +32,7 @@ package net.thauvin.erik.mobibot import net.thauvin.erik.mobibot.Utils.bold +import net.thauvin.erik.mobibot.Utils.capitalize import net.thauvin.erik.mobibot.Utils.colorize import net.thauvin.erik.mobibot.Utils.cyan import net.thauvin.erik.mobibot.Utils.ensureDir @@ -77,6 +78,12 @@ class UtilsTest { Assertions.assertThat(bold(ascii)).`as`("bold(ascii)").isEqualTo(Colors.BOLD + ascii + Colors.BOLD) } + @Test + fun testCapitalize() { + Assertions.assertThat(capitalize("test")).`as`("capitalize(test)").isEqualTo("Test") + Assertions.assertThat(capitalize("Test")).`as`("capitalize(Test)").isEqualTo("Test") + } + @Test fun testColorize() { Assertions.assertThat(colorize(ascii, Colors.REVERSE)).`as`("colorize(reverse)").isEqualTo( diff --git a/version.properties b/version.properties index 6d5aa2a..cffabaf 100644 --- a/version.properties +++ b/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Mon Apr 26 18:00:07 PDT 2021 -version.buildmeta=462 +#Mon Apr 26 22:03:01 PDT 2021 +version.buildmeta=474 version.major=0 version.minor=8 version.patch=0 version.prerelease=beta version.project=mobibot -version.semver=0.8.0-beta+462 +version.semver=0.8.0-beta+474