Using StringUtils upper/lowerCase().

This commit is contained in:
Erik C. Thauvin 2020-03-30 18:00:57 -07:00
parent 30b7a80c49
commit cfdbfca0a2
7 changed files with 21 additions and 21 deletions

View file

@ -102,6 +102,7 @@ import java.util.Set;
import java.util.Timer; import java.util.Timer;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.lowerCase;
/** /**
* Implements the #mobitopia bot. * Implements the #mobitopia bot.
@ -360,7 +361,7 @@ public class Mobibot extends PircBot {
System.exit(1); System.exit(1);
} }
final String nickname = p.getProperty("nick", Mobibot.class.getName().toLowerCase(Constants.LOCALE)); final String nickname = p.getProperty("nick", lowerCase(Mobibot.class.getName()));
final String channel = p.getProperty("channel"); final String channel = p.getProperty("channel");
final String logsDir = Utils.ensureDir(p.getProperty("logs", "."), false); final String logsDir = Utils.ensureDir(p.getProperty("logs", "."), false);
@ -567,8 +568,8 @@ public class Mobibot extends PircBot {
for (final char c : getNick().toCharArray()) { for (final char c : getNick().toCharArray()) {
if (Character.isLetter(c)) { if (Character.isLetter(c)) {
buff.append('[').append(String.valueOf(c).toLowerCase(Constants.LOCALE)).append( buff.append('[').append(lowerCase(String.valueOf(c))).append(StringUtils.upperCase(String.valueOf(c)))
String.valueOf(c).toUpperCase(Constants.LOCALE)).append(']'); .append(']');
} else { } else {
buff.append(c); buff.append(c);
} }
@ -697,7 +698,7 @@ public class Mobibot extends PircBot {
if (StringUtils.isBlank(topic)) { if (StringUtils.isBlank(topic)) {
helpDefault(sender, isOp, isPrivate); helpDefault(sender, isOp, isPrivate);
} else { } else {
final String lcTopic = topic.toLowerCase(Constants.LOCALE).trim(); final String lcTopic = lowerCase(topic).trim();
if (lcTopic.equals(getChannelName())) { if (lcTopic.equals(getChannelName())) {
send(sender, "To list the last 5 posts from the channel's weblog:", isPrivate); send(sender, "To list the last 5 posts from the channel's weblog:", isPrivate);
send(sender, Utils.helpIndent(getNick() + ": " + getChannelName()), isPrivate); send(sender, Utils.helpIndent(getNick() + ": " + getChannelName()), isPrivate);
@ -783,7 +784,7 @@ public class Mobibot extends PircBot {
isCommand = true; isCommand = true;
final String[] cmds = message.substring(message.indexOf(':') + 1).trim().split(" ", 2); final String[] cmds = message.substring(message.indexOf(':') + 1).trim().split(" ", 2);
final String cmd = cmds[0].toLowerCase(Constants.LOCALE); final String cmd = lowerCase(cmds[0]);
String args = ""; String args = "";
@ -850,7 +851,7 @@ public class Mobibot extends PircBot {
} }
final String[] cmds = message.split(" ", 2); final String[] cmds = message.split(" ", 2);
final String cmd = cmds[0].toLowerCase(Constants.LOCALE); final String cmd = lowerCase(cmds[0]);
String args = ""; String args = "";
if (cmds.length > 1) { if (cmds.length > 1) {

View file

@ -35,7 +35,7 @@ package net.thauvin.erik.mobibot;
import net.thauvin.erik.mobibot.entries.EntryLink; import net.thauvin.erik.mobibot.entries.EntryLink;
import net.thauvin.erik.pinboard.PinboardPoster; import net.thauvin.erik.pinboard.PinboardPoster;
import javax.swing.SwingWorker; import javax.swing.*;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;

View file

@ -32,7 +32,6 @@
package net.thauvin.erik.mobibot.commands.links package net.thauvin.erik.mobibot.commands.links
import net.thauvin.erik.mobibot.Constants
import net.thauvin.erik.mobibot.Mobibot import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils import net.thauvin.erik.mobibot.Utils
import net.thauvin.erik.mobibot.commands.AbstractCommand import net.thauvin.erik.mobibot.commands.AbstractCommand
@ -73,7 +72,7 @@ class View : AbstractCommand() {
private fun showPosts(bot: Mobibot, args: String, sender: String) { private fun showPosts(bot: Mobibot, args: String, sender: String) {
val max = entriesCount val max = entriesCount
var lcArgs = args.toLowerCase(Constants.LOCALE) var lcArgs = args.toLowerCase()
var i = 0 var i = 0
if (lcArgs.isEmpty() && max > maxEntries) { if (lcArgs.isEmpty() && max > maxEntries) {
i = max - maxEntries i = max - maxEntries

View file

@ -35,7 +35,6 @@ package net.thauvin.erik.mobibot.entries;
import com.rometools.rome.feed.synd.SyndCategory; import com.rometools.rome.feed.synd.SyndCategory;
import com.rometools.rome.feed.synd.SyndCategoryImpl; import com.rometools.rome.feed.synd.SyndCategoryImpl;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.Constants;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.Serializable; import java.io.Serializable;
@ -361,7 +360,7 @@ public class EntryLink implements Serializable {
if (part.length() >= 2) { if (part.length() >= 2) {
tag = new SyndCategoryImpl(); tag = new SyndCategoryImpl();
tag.setName(part.substring(1).toLowerCase(Constants.LOCALE)); tag.setName(StringUtils.lowerCase(part.substring(1)));
mod = part.charAt(0); mod = part.charAt(0);
@ -375,7 +374,7 @@ public class EntryLink implements Serializable {
this.tags.add(tag); this.tags.add(tag);
} }
} else { } else {
tag.setName(part.trim().toLowerCase(Constants.LOCALE)); tag.setName(StringUtils.lowerCase(part.trim()));
if (!this.tags.contains(tag)) { if (!this.tags.contains(tag)) {
this.tags.add(tag); this.tags.add(tag);

View file

@ -55,6 +55,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import static org.apache.commons.lang3.StringUtils.upperCase;
/** /**
* The CurrentConverter module. * The CurrentConverter module.
* *
@ -100,8 +102,8 @@ public final class CurrencyConverter extends ThreadedModule {
if (cmds[3].equals(cmds[1]) || "0".equals(cmds[0])) { if (cmds[3].equals(cmds[1]) || "0".equals(cmds[0])) {
return new PublicMessage("You're kidding, right?"); return new PublicMessage("You're kidding, right?");
} else { } else {
final String to = cmds[1].toUpperCase(Constants.LOCALE); final String to = upperCase(cmds[1]);
final String from = cmds[3].toUpperCase(Constants.LOCALE); final String from = upperCase(cmds[3]);
if (EXCHANGE_RATES.containsKey(to) && EXCHANGE_RATES.containsKey(from)) { if (EXCHANGE_RATES.containsKey(to) && EXCHANGE_RATES.containsKey(from)) {
try { try {
@ -112,13 +114,13 @@ public final class CurrencyConverter extends ThreadedModule {
return new PublicMessage( return new PublicMessage(
NumberFormat.getCurrencyInstance(Constants.LOCALE).format(amt).substring(1) NumberFormat.getCurrencyInstance(Constants.LOCALE).format(amt).substring(1)
+ ' ' + ' '
+ cmds[1].toUpperCase(Constants.LOCALE) + upperCase(cmds[1])
+ " = " + " = "
+ NumberFormat.getCurrencyInstance(Constants.LOCALE) + NumberFormat.getCurrencyInstance(Constants.LOCALE)
.format((amt * doubleTo) / doubleFrom) .format((amt * doubleTo) / doubleFrom)
.substring(1) .substring(1)
+ ' ' + ' '
+ cmds[3].toUpperCase(Constants.LOCALE)); + upperCase(cmds[3]));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return new ErrorMessage("Let's try with some real numbers next time, okay?"); return new ErrorMessage("Let's try with some real numbers next time, okay?");
} }

View file

@ -33,12 +33,12 @@
package net.thauvin.erik.mobibot.modules; package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.Constants;
import net.thauvin.erik.mobibot.Mobibot; import net.thauvin.erik.mobibot.Mobibot;
import net.thauvin.erik.mobibot.Utils; import net.thauvin.erik.mobibot.Utils;
import net.thauvin.erik.mobibot.msg.ErrorMessage; import net.thauvin.erik.mobibot.msg.ErrorMessage;
import net.thauvin.erik.mobibot.msg.Message; import net.thauvin.erik.mobibot.msg.Message;
import net.thauvin.erik.mobibot.msg.PublicMessage; import net.thauvin.erik.mobibot.msg.PublicMessage;
import org.apache.commons.lang3.StringUtils;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
@ -188,8 +188,7 @@ public final class WorldTime extends AbstractModule {
*/ */
@SuppressFBWarnings("STT_STRING_PARSING_A_FIELD") @SuppressFBWarnings("STT_STRING_PARSING_A_FIELD")
static Message worldTime(final String query) { static Message worldTime(final String query) {
final String tz = (COUNTRIES_MAP.get((query.substring(query.indexOf(' ') + 1).trim() final String tz = (COUNTRIES_MAP.get((StringUtils.upperCase(query.substring(query.indexOf(' ') + 1).trim()))));
.toUpperCase(Constants.LOCALE))));
final String response; final String response;
if (tz != null) { if (tz != null) {

View file

@ -32,7 +32,7 @@
package net.thauvin.erik.mobibot.modules; package net.thauvin.erik.mobibot.modules;
import net.thauvin.erik.mobibot.Constants; import org.apache.commons.lang3.StringUtils;
import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeSuite;
import java.io.IOException; import java.io.IOException;
@ -65,7 +65,7 @@ class LocalProperties {
} }
private static String keyToEnv(final String key) { private static String keyToEnv(final String key) {
return key.replace('-', '_').toUpperCase(Constants.LOCALE); return StringUtils.upperCase(key.replace('-', '_'));
} }
@BeforeSuite(alwaysRun = true) @BeforeSuite(alwaysRun = true)