@Test public void pluralizeWithDifferentLocale() { String expected = "interests"; String actual; Locale current = Locale.getDefault(); try { Locale.setDefault(Locale.forLanguageTag("tr")); actual = Utils.pluralize("Interest"); } finally { Locale.setDefault(current); } assertEquals(expected, actual); }
static String pluralize(String string) { string = string.toLowerCase(Locale.US); if (string.endsWith("s")) { return string; } else if (string.endsWith("ay")) { return string.replaceAll("ay$", "ays"); } else if (string.endsWith("ey")) { return string.replaceAll("ey$", "eys"); } else if (string.endsWith("oy")) { return string.replaceAll("oy$", "oys"); } else if (string.endsWith("uy")) { return string.replaceAll("uy$", "uys"); } else if (string.endsWith("y")) { return string.replaceAll("y$", "ies"); } else { return string + "s"; } }
Utils { static String pluralize(String string) { string = string.toLowerCase(Locale.US); if (string.endsWith("s")) { return string; } else if (string.endsWith("ay")) { return string.replaceAll("ay$", "ays"); } else if (string.endsWith("ey")) { return string.replaceAll("ey$", "eys"); } else if (string.endsWith("oy")) { return string.replaceAll("oy$", "oys"); } else if (string.endsWith("uy")) { return string.replaceAll("uy$", "uys"); } else if (string.endsWith("y")) { return string.replaceAll("y$", "ies"); } else { return string + "s"; } } }
Utils { static String pluralize(String string) { string = string.toLowerCase(Locale.US); if (string.endsWith("s")) { return string; } else if (string.endsWith("ay")) { return string.replaceAll("ay$", "ays"); } else if (string.endsWith("ey")) { return string.replaceAll("ey$", "eys"); } else if (string.endsWith("oy")) { return string.replaceAll("oy$", "oys"); } else if (string.endsWith("uy")) { return string.replaceAll("uy$", "uys"); } else if (string.endsWith("y")) { return string.replaceAll("y$", "ies"); } else { return string + "s"; } } private  Utils(); }
Utils { static String pluralize(String string) { string = string.toLowerCase(Locale.US); if (string.endsWith("s")) { return string; } else if (string.endsWith("ay")) { return string.replaceAll("ay$", "ays"); } else if (string.endsWith("ey")) { return string.replaceAll("ey$", "eys"); } else if (string.endsWith("oy")) { return string.replaceAll("oy$", "oys"); } else if (string.endsWith("uy")) { return string.replaceAll("uy$", "uys"); } else if (string.endsWith("y")) { return string.replaceAll("y$", "ies"); } else { return string + "s"; } } private  Utils();  }
Utils { static String pluralize(String string) { string = string.toLowerCase(Locale.US); if (string.endsWith("s")) { return string; } else if (string.endsWith("ay")) { return string.replaceAll("ay$", "ays"); } else if (string.endsWith("ey")) { return string.replaceAll("ey$", "eys"); } else if (string.endsWith("oy")) { return string.replaceAll("oy$", "oys"); } else if (string.endsWith("uy")) { return string.replaceAll("uy$", "uys"); } else if (string.endsWith("y")) { return string.replaceAll("y$", "ies"); } else { return string + "s"; } } private  Utils();   }