Added default locale (PMD)
This commit is contained in:
parent
bd9bb8d47e
commit
1d7f8eb86b
7 changed files with 63 additions and 48 deletions
|
@ -32,6 +32,8 @@
|
|||
|
||||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The <code>Constants</code> class.
|
||||
*
|
||||
|
@ -55,6 +57,11 @@ public final class Constants {
|
|||
*/
|
||||
public static final String TWITTER_HANDLE_PROP = "twitter-handle";
|
||||
|
||||
/**
|
||||
* Default locale.
|
||||
*/
|
||||
public static final Locale LOCALE = Locale.getDefault();
|
||||
|
||||
/**
|
||||
* Disables the default constructor.
|
||||
*/
|
||||
|
|
|
@ -585,8 +585,8 @@ public class Mobibot extends PircBot {
|
|||
for (final char c : getNick().toCharArray()) {
|
||||
if (Character.isLetter(c)) {
|
||||
buff.append('[')
|
||||
.append(String.valueOf(c).toLowerCase())
|
||||
.append(String.valueOf(c).toUpperCase())
|
||||
.append(String.valueOf(c).toLowerCase(Constants.LOCALE))
|
||||
.append(String.valueOf(c).toUpperCase(Constants.LOCALE))
|
||||
.append(']');
|
||||
} else {
|
||||
buff.append(c);
|
||||
|
@ -651,7 +651,7 @@ public class Mobibot extends PircBot {
|
|||
* @param topic The help topic, if any.
|
||||
*/
|
||||
private void helpResponse(final String sender, final String topic) {
|
||||
final String lcTopic = topic.toLowerCase().trim();
|
||||
final String lcTopic = topic.toLowerCase(Constants.LOCALE).trim();
|
||||
|
||||
if (Commands.HELP_POSTING_KEYWORD.equals(lcTopic)) {
|
||||
send(sender, Utils.bold("Post a URL, by saying it on a line on its own:"));
|
||||
|
|
|
@ -84,7 +84,7 @@ public final class Utils {
|
|||
* @return The capitalized string.
|
||||
*/
|
||||
public static String capitalize(final String s) {
|
||||
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
||||
return s.substring(0, 1).toUpperCase(Constants.LOCALE) + s.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,6 +35,7 @@ package net.thauvin.erik.mobibot.entries;
|
|||
import com.rometools.rome.feed.synd.SyndCategory;
|
||||
import com.rometools.rome.feed.synd.SyndCategoryImpl;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.Constants;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
|
@ -307,7 +308,7 @@ public class EntryLink implements Serializable {
|
|||
|
||||
if (part.length() >= 2) {
|
||||
tag = new SyndCategoryImpl();
|
||||
tag.setName(part.substring(1).toLowerCase());
|
||||
tag.setName(part.substring(1).toLowerCase(Constants.LOCALE));
|
||||
|
||||
mod = part.charAt(0);
|
||||
|
||||
|
@ -321,7 +322,7 @@ public class EntryLink implements Serializable {
|
|||
this.tags.add(tag);
|
||||
}
|
||||
} else {
|
||||
tag.setName(part.trim().toLowerCase());
|
||||
tag.setName(part.trim().toLowerCase(Constants.LOCALE));
|
||||
|
||||
if (!this.tags.contains(tag)) {
|
||||
this.tags.add(tag);
|
||||
|
@ -395,6 +396,7 @@ public class EntryLink implements Serializable {
|
|||
*
|
||||
* @return A string representation of the object.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
|
||||
return super.toString() + "[ channel -> '" + channel + '\'' + ", comments -> " + comments + ", date -> " + date
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.Constants;
|
||||
import net.thauvin.erik.mobibot.Mobibot;
|
||||
import net.thauvin.erik.mobibot.Utils;
|
||||
import net.thauvin.erik.mobibot.msg.ErrorMessage;
|
||||
|
@ -80,9 +81,48 @@ public final class CurrencyConverter extends ThreadedModule {
|
|||
* Creates a new {@link CurrencyConverter} instance.
|
||||
*/
|
||||
public CurrencyConverter() {
|
||||
super();
|
||||
commands.add(CURRENCY_CMD);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
synchronized (this) {
|
||||
if (!pubDate.equals(Utils.today())) {
|
||||
EXCHANGE_RATES.clear();
|
||||
}
|
||||
}
|
||||
|
||||
super.commandResponse(bot, sender, args, isPrivate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified currencies.
|
||||
*/
|
||||
@SuppressFBWarnings("REDOS")
|
||||
@Override
|
||||
void run(final Mobibot bot, final String sender, final String query) {
|
||||
if (Utils.isValidString(sender) && Utils.isValidString(query)) {
|
||||
if (query.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ to [a-zA-Z]{3}+")) {
|
||||
try {
|
||||
final Message msg = convertCurrency(query);
|
||||
if (msg.isError()) {
|
||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, false);
|
||||
}
|
||||
bot.send(sender, msg);
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from a currency to another.
|
||||
*
|
||||
|
@ -136,19 +176,20 @@ public final class CurrencyConverter extends ThreadedModule {
|
|||
} else {
|
||||
try {
|
||||
final double amt = Double.parseDouble(cmds[0].replaceAll(",", ""));
|
||||
final double from = Double.parseDouble(EXCHANGE_RATES.get(cmds[1].toUpperCase()));
|
||||
final double to = Double.parseDouble(EXCHANGE_RATES.get(cmds[3].toUpperCase()));
|
||||
final double from = Double.parseDouble(EXCHANGE_RATES.get(cmds[1]
|
||||
.toUpperCase(Constants.LOCALE)));
|
||||
final double to = Double.parseDouble(EXCHANGE_RATES.get(cmds[3].toUpperCase(Constants.LOCALE)));
|
||||
|
||||
return new PublicMessage(
|
||||
NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1)
|
||||
+ ' '
|
||||
+ cmds[1].toUpperCase()
|
||||
+ cmds[1].toUpperCase(Constants.LOCALE)
|
||||
+ " = "
|
||||
+ NumberFormat.getCurrencyInstance(Locale.US)
|
||||
.format((amt * to) / from)
|
||||
.substring(1)
|
||||
+ ' '
|
||||
+ cmds[3].toUpperCase());
|
||||
+ cmds[3].toUpperCase(Constants.LOCALE));
|
||||
} catch (Exception e) {
|
||||
throw new ModuleException("convertCurrency(" + query + ')',
|
||||
"The supported currencies are: " + EXCHANGE_RATES.keySet(), e);
|
||||
|
@ -173,43 +214,6 @@ public final class CurrencyConverter extends ThreadedModule {
|
|||
return new ErrorMessage("The supported currencies are: " + EXCHANGE_RATES.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
synchronized (this) {
|
||||
if (!pubDate.equals(Utils.today())) {
|
||||
EXCHANGE_RATES.clear();
|
||||
}
|
||||
}
|
||||
|
||||
super.commandResponse(bot, sender, args, isPrivate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified currencies.
|
||||
*/
|
||||
@SuppressFBWarnings(value = "REDOS")
|
||||
void run(final Mobibot bot, final String sender, final String query) {
|
||||
if (Utils.isValidString(sender) && Utils.isValidString(query)) {
|
||||
if (query.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ to [a-zA-Z]{3}+")) {
|
||||
try {
|
||||
final Message msg = convertCurrency(query);
|
||||
if (msg.isError()) {
|
||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, false);
|
||||
}
|
||||
bot.send(sender, msg);
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.Constants;
|
||||
import net.thauvin.erik.mobibot.Mobibot;
|
||||
import net.thauvin.erik.mobibot.msg.ErrorMessage;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import net.thauvin.erik.mobibot.Constants;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -64,7 +65,7 @@ class LocalProperties {
|
|||
}
|
||||
|
||||
private static String keyToEnv(final String key) {
|
||||
return key.replaceAll("-", "_").toUpperCase();
|
||||
return key.replaceAll("-", "_").toUpperCase(Constants.LOCALE);
|
||||
}
|
||||
|
||||
@BeforeSuite(alwaysRun = true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue