diff --git a/README.txt b/README.txt index 333fbf7..1d111a1 100644 --- a/README.txt +++ b/README.txt @@ -1,6 +1,6 @@ Some very basic instructions: - { clone with git or download the ZIP} + { clone with git or download the ZIP } git clone git://github.com/ethauvin/mobibot.git cd mobibot diff --git a/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java b/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java index 9b61dc1..b138c95 100644 --- a/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java +++ b/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java @@ -88,7 +88,7 @@ class CurrencyConverter implements Runnable * * @param bot The bot's instance. */ - public CurrencyConverter(Mobibot bot) + public CurrencyConverter(final Mobibot bot) { this.bot = bot; } @@ -186,23 +186,18 @@ class CurrencyConverter implements Runnable { bot.send(sender, "Last Update: " + pubDate); - final Iterator it = EXCHANGE_RATES.keySet().iterator(); - String rate; - final StringBuilder buff = new StringBuilder(0); - while (it.hasNext()) + for (final Map.Entry rate : EXCHANGE_RATES.entrySet()) { - rate = it.next(); if (buff.length() > 0) { buff.append(", "); } - buff.append(rate).append(": ").append(EXCHANGE_RATES.get(rate)); + buff.append(rate.getKey()).append(": ").append(rate.getValue()); } bot.send(sender, buff.toString()); - } } } @@ -221,7 +216,7 @@ class CurrencyConverter implements Runnable * @param query The currency query. */ - public synchronized void setQuery(String sender, String query) + public synchronized void setQuery(final String sender, final String query) { this.query = query; this.sender = sender; diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java index c43b6cd..75734d0 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.java +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java @@ -50,7 +50,7 @@ import java.util.Calendar; * @created 2014-04-26 * @since 1.0 */ -class Utils +final class Utils { /** * The timestamp simple date format. @@ -85,25 +85,11 @@ class Utils * * @return The bold string. */ - public static String bold(int i) + public static String bold(final int i) { return Colors.BOLD + i + Colors.BOLD; } - /** - * Makes the given int reverse color. - * - * @param i The int. - * - * @return The reverse color string. - */ - public static String reverseColor(int i) - { - return Colors.REVERSE + i + Colors.REVERSE; - } - - - /** * Builds an entry's comment for display on the channel. * @@ -113,7 +99,7 @@ class Utils * * @return The entry's comment. */ - static String buildComment(int entryIndex, int commentIndex, EntryComment comment) + static String buildComment(final int entryIndex, final int commentIndex, final EntryComment comment) { return (Commands.LINK_CMD + (entryIndex + 1) + '.' + (commentIndex + 1) + ": [" + comment.getNick() + "] " + comment.getComment()); @@ -129,7 +115,7 @@ class Utils * * @see #buildLink(int, net.thauvin.erik.mobibot.EntryLink, boolean) */ - static String buildLink(int index, EntryLink entry) + static String buildLink(final int index, final EntryLink entry) { return buildLink(index, entry, false); } @@ -143,7 +129,7 @@ class Utils * * @return The entry's link. */ - static String buildLink(int index, EntryLink entry, boolean isView) + static String buildLink(final int index, final EntryLink entry, final boolean isView) { final StringBuilder buff = new StringBuilder(Commands.LINK_CMD + (index + 1) + ": "); @@ -177,24 +163,11 @@ class Utils * * @return The bold string. */ - public static String bold(String s) + public static String bold(final String s) { return Colors.BOLD + s + Colors.BOLD; } - /** - * Makes the given string reverse color. - * - * @param s The string. - * - * @return The reverse color string. - */ - public static String reverseColor(String s) - { - return Colors.REVERSE + s + Colors.REVERSE; - } - - /** * Build an entry's tags/categories for display on the channel. * @@ -203,7 +176,7 @@ class Utils * * @return The entry's tags. */ - static String buildTags(int entryIndex, EntryLink entry) + static String buildTags(final int entryIndex, final EntryLink entry) { return (Commands.LINK_CMD + (entryIndex + 1) + "T: " + entry.getDeliciousTags().replaceAll(",", ", ")); } @@ -217,7 +190,7 @@ class Utils * @throws java.io.IOException If the file could not be copied. */ @SuppressWarnings("UnusedDeclaration") - public static void copyFile(File in, File out) + public static void copyFile(final File in, final File out) throws IOException { FileChannel inChannel = null; @@ -281,7 +254,7 @@ class Utils * * @return The location ending with a slash. */ - public static String ensureDir(String location, boolean isUrl) + public static String ensureDir(final String location, final boolean isUrl) { if (isUrl) { @@ -315,7 +288,7 @@ class Utils * * @return The port or default value if invalid. */ - public static int getIntProperty(String property, int def) + public static int getIntProperty(final String property, final int def) { int prop; @@ -361,11 +334,11 @@ class Utils if (beats < 10) { - return ("@00" + String.valueOf(beats)); + return ("@00" + beats); } else if (beats < 100) { - return ("@0" + String.valueOf(beats)); + return ("@0" + beats); } return ('@' + String.valueOf(beats)); @@ -378,9 +351,45 @@ class Utils * * @return true if the string is non-empty and not null, false otherwise. */ - public static boolean isValidString(String s) + public static boolean isValidString(final CharSequence s) { - return (s != null) && (s.trim().length() > 0); + final int len; + if (s == null || (len = s.length()) == 0) + { + return false; + } + for (int i = 0; i < len; i++) + { + if (!Character.isWhitespace(s.charAt(i))) + { + return true; + } + } + return false; + } + + /** + * Makes the given int reverse color. + * + * @param i The int. + * + * @return The reverse color string. + */ + public static String reverseColor(final int i) + { + return Colors.REVERSE + i + Colors.REVERSE; + } + + /** + * Makes the given string reverse color. + * + * @param s The string. + * + * @return The reverse color string. + */ + public static String reverseColor(final String s) + { + return Colors.REVERSE + s + Colors.REVERSE; } /** @@ -400,7 +409,7 @@ class Utils * * @return The unescaped string. */ - public static String unescapeXml(String str) + public static String unescapeXml(final String str) { String s = str.replaceAll("&", "&"); s = s.replaceAll("<", "<");