mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Add acronym support (e.g. NPC) to LanguageUtil#getIndefiniteArticle.
This commit is contained in:
@@ -1,26 +1,49 @@
|
||||
package org.apollo.util;
|
||||
|
||||
/**
|
||||
* A utility class which contains language-related methods.
|
||||
* Contains language-related utility methods.
|
||||
*
|
||||
* @author Graham
|
||||
* @author Major
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public static String getIndefiniteArticle(String thing) {
|
||||
char first = thing.toLowerCase().charAt(0);
|
||||
public static String getIndefiniteArticle(String string) {
|
||||
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';
|
||||
return vowel ? "an" : "a";
|
||||
}
|
||||
|
||||
/**
|
||||
* Default private constructor to prevent instantiation.
|
||||
* Sole private constructor to prevent instantiation.
|
||||
*/
|
||||
private LanguageUtil() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user