Add acronym support (e.g. NPC) to LanguageUtil#getIndefiniteArticle.

This commit is contained in:
Major-
2015-03-09 12:57:30 +00:00
parent 3d00cf9251
commit 053e3a30be
+29 -6
View File
@@ -1,26 +1,49 @@
package org.apollo.util; package org.apollo.util;
/** /**
* A utility class which contains language-related methods. * Contains language-related utility methods.
* *
* @author Graham * @author Graham
* @author Major
*/ */
public final class LanguageUtil { public final class LanguageUtil {
/** /**
* Gets the indefinite article of a 'thing'. * Returns whether or not the each letter in the specified String is upper case (i.e. digits etc are ignored).
* *
* @param thing The thing. * @param string The string.
* @return {@code true} if no letters in the specified String are lower case, otherwise {@code false}.
*/
public static boolean allUpperCase(String string) {
for (char character : string.toCharArray()) {
if (Character.isLowerCase(character)) {
return false;
}
}
return true;
}
/**
* Gets the indefinite article of the specified String.
*
* @param string The String.
* @return The indefinite article. * @return The indefinite article.
*/ */
public static String getIndefiniteArticle(String thing) { public static String getIndefiniteArticle(String string) {
char first = thing.toLowerCase().charAt(0); char first = Character.toLowerCase(string.charAt(0));
if (allUpperCase(string)) {
if (first == 'f' || first == 'l' | first == 'm' || first == 'n' || first == 's') {
return "an";
}
}
boolean vowel = first == 'a' || first == 'e' || first == 'i' || first == 'o' || first == 'u'; boolean vowel = first == 'a' || first == 'e' || first == 'i' || first == 'o' || first == 'u';
return vowel ? "an" : "a"; return vowel ? "an" : "a";
} }
/** /**
* Default private constructor to prevent instantiation. * Sole private constructor to prevent instantiation.
*/ */
private LanguageUtil() { private LanguageUtil() {