String (String word, List<? extends Map.Entry<Pattern, String>> rules) { if (Strings.isEmpty(word) || uncountables.contains(word)) return word; int len = rules.size(); while (--len > -1) { Map.Entry<Pattern, String> rule = rules.get(len); Matcher matcher = rule.getKey().matcher(word); if (matcher.find()) { return matcher.replaceFirst(rule.getValue()); } } return null; }