/** * This method returns the plural term as per inflector. ATTENTION: this * method does NOT take @RooPlural into account. Use getPlural(..) instead! * * @param term The term to be pluralized * @param locale Locale * @return pluralized term */ public static String getInflectorPlural(final String term, final Locale locale) { try { // ROO-3817: Uncapitalize term to obtain the plural correctly. String termUncapitalized = StringUtils.uncapitalize(term); String thePluralUncapitalized = Noun.pluralOf(termUncapitalized, locale); // ROO-3817: After that, returns the plural term taking in count if the received term is capitalized or not. if (StringUtils .equalsIgnoreCase(term.substring(0, 1), thePluralUncapitalized.substring(0, 1)) && !StringUtils.equals(term.substring(0, 1), thePluralUncapitalized.substring(0, 1))) { return StringUtils.capitalize(thePluralUncapitalized); } return thePluralUncapitalized; } catch (final RuntimeException re) { // Inflector failed (see for example ROO-305), so don't pluralize it return term; } }
/** * <p> * Converts a noun to its plural form using the {@link Pluralizer} for the default locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @return the plural form */ public static String pluralOf(String word) { return pluralOf(word, pluralizer()); }
/** * <p> * Converts a noun to its plural form using the given {@link Pluralizer}. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param pluralizer a noun pluralizer * @return the plural form */ public static String pluralOf(String word, Pluralizer pluralizer) { return pluralizer == null ? null : pluralizer.pluralize(word); }
/** * <p> * Goes through the rules in turn until a match is found at which point the rule is applied * and the result returned. * If no rule matches, returns <code>null</code>. * </p> * @param word a singular noun * @return the plural form of the noun, or <code>null</code> if no rule matches */ protected String pluralizeInternal(String word) { for (Rule rule : rules) { if (rule.applies(word)) { return rule.apply(word); } } return null; }
/** * <p> * Creates a new {@link Pluralizer} instance for the default locale. * </p> * @return a pluralizer instance for the default locale */ public static Pluralizer pluralizer() { return pluralizer(Locale.getDefault()); }
/** * <p> * Converts a noun or pronoun to its plural form. * </p> * <p> * This method is equivalent to calling <code>pluralize(word, 2)</code>. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular noun * @return the plural form of the noun */ public String pluralize(String word) { return pluralize(word, 2); }
@Override protected String postProcess(String trimmedWord, String pluralizedWord) { if (trimmedWord.matches("^I$")) { return pluralizedWord; } return super.postProcess(trimmedWord, pluralizedWord); }
/** * <p> * Converts a noun to its plural form using the {@link Pluralizer} for the default locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @return the plural form */ public static String pluralOf(String word) { return pluralOf(word, pluralizer()); }
/** * This method returns the plural term as per inflector. ATTENTION: this * method does NOT take @RooPlural into account. Use getPlural(..) instead! * * @param term The term to be pluralized * @param locale Locale * @return pluralized term */ public String getInflectorPlural(final String term, final Locale locale) { try { // ROO-3817: Uncapitalize term to obtain the plural correctly. String termUncapitalized = StringUtils.uncapitalize(term); String thePluralUncapitalized = Noun.pluralOf(termUncapitalized, locale); // ROO-3817: After that, returns the plural term taking in count if the received term is capitalized or not. if (StringUtils .equalsIgnoreCase(term.substring(0, 1), thePluralUncapitalized.substring(0, 1)) && !StringUtils.equals(term.substring(0, 1), thePluralUncapitalized.substring(0, 1))) { return StringUtils.capitalize(thePluralUncapitalized); } return thePluralUncapitalized; } catch (final RuntimeException re) { // Inflector failed (see for example ROO-305), so don't pluralize it return term; } }
/** * <p> * Goes through the rules in turn until a match is found at which point the rule is applied * and the result returned. * If no rule matches, returns <code>null</code>. * </p> * @param word a singular noun * @return the plural form of the noun, or <code>null</code> if no rule matches */ protected String pluralizeInternal(String word) { for (Rule rule : rules) { if (rule.applies(word)) { return rule.apply(word); } } return null; }
/** * <p> * Converts a noun to its plural form using the given {@link Pluralizer}. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param pluralizer a noun pluralizer * @return the plural form */ public static String pluralOf(String word, Pluralizer pluralizer) { return pluralizer == null ? null : pluralizer.pluralize(word); }
/** * <p> * Converts a noun or pronoun to its plural form. * </p> * <p> * This method is equivalent to calling <code>pluralize(word, 2)</code>. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular noun * @return the plural form of the noun */ public String pluralize(String word) { return pluralize(word, 2); }
/** * <p> * Converts a noun to its plural form using the {@link Pluralizer} for the given locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param locale the locale specifying the language of the pluralizer * @return the plural form */ public static String pluralOf(String word, Locale locale) { return pluralOf(word, pluralizer(locale)); }
private String getInflectorPlural(final String term) { try { return Noun.pluralOf(term, Locale.ENGLISH); } catch (final RuntimeException e) { // Inflector failed (see for example ROO-305), so don't pluralize it return term; } }
/** * <p> * Converts a noun to its plural form for the given number of instances * using the given {@link Pluralizer}. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param number the number of objects being referred to in the plural * @param pluralizer a noun pluralizer * @return the plural form */ public static String pluralOf(String word, int number, Pluralizer pluralizer) { return pluralizer == null ? null : pluralizer.pluralize(word, number); }
/** * <p> * Converts a noun to its plural form using the {@link Pluralizer} for the given locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param locale the locale specifying the language of the pluralizer * @return the plural form */ public static String pluralOf(String word, Locale locale) { return pluralOf(word, pluralizer(locale)); }
/** * <p> * Converts a noun to its plural form for the given number of instances * using the {@link Pluralizer} for the default locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param number the number of objects being referred to in the plural * @return the plural form */ public static String pluralOf(String word, int number) { return pluralOf(word, number, pluralizer()); }
/** * <p> * Converts a noun to its plural form for the given number of instances * using the {@link Pluralizer} for the default locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param number the number of objects being referred to in the plural * @return the plural form */ public static String pluralOf(String word, int number) { return pluralOf(word, number, pluralizer()); }
/** * <p> * Converts a noun to its plural form for the given number of instances * using the {@link Pluralizer} for the given locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param number the number of objects being referred to in the plural * @param locale the locale specifying the language of the pluralizer * @return the plural form */ public static String pluralOf(String word, int number, Locale locale) { return pluralOf(word, number, pluralizer(locale)); }
/** * <p> * Converts a noun to its plural form for the given number of instances * using the {@link Pluralizer} for the given locale. * </p> * <p> * The return value is not defined if this method is passed a plural form. * </p> * @param word a singular form * @param number the number of objects being referred to in the plural * @param locale the locale specifying the language of the pluralizer * @return the plural form */ public static String pluralOf(String word, int number, Locale locale) { return pluralOf(word, number, pluralizer(locale)); }