/** * 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> * 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 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> * 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 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)); }
/** * 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; } }
/** */ @SuppressWarnings("unchecked") private static void fillCustomPluralization() { ArrayList<Object> tmpRule = (ArrayList<Object>) Config.config.getList("customPluralization.rule[@regexmatch]"); List<Rule> customRules = new ArrayList<Rule>(); for (int i = 0; i < tmpRule.size(); i++) { String match = Config.config.getString(String.format("customPluralization.rule(%d)[@regexmatch]", i), "*"); String replace = Config.config.getString(String.format("customPluralization.rule(%d)[@regexreplace]", i), ""); customRules.add(new RegexReplacementRule(match, replace)); } State.getInstance().setCustomPluralizer(new RuleBasedPluralizer(customRules, Locale.ENGLISH, Noun.pluralizer(Locale.ENGLISH))); }
/** * <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()); }
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 {@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()); }
private List<String> getCollectionNames(RestClient client) { for (Class type : typesToEnhance) { String plural = Noun.pluralOf(type.getSimpleName(), client.inflectionRules()); names.add(Character.toLowerCase(plural.charAt(0)) + plural.substring(1)); } return names; }
/** * <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)); }
protected String getPluralForm(E entity) { if (entity.getClass().isAnnotationPresent(PluralForm.class)) { return entity.getClass().getAnnotation(PluralForm.class).value(); } return Noun.pluralOf(getEntityName(entity)); }
/** * <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)); }
/** * Given a word, return the english plural equivalent * * @param input * @return nice english */ public static String pluralize(String input) { String result = input; if (!State.getInstance().disableEnglishPlural) { String tmp = Noun.pluralOf(input.substring(0, 1).toLowerCase() + input.substring(1), State.getInstance().getCustomPluralizer()); result = input.substring(0, 1) + tmp.substring(1); } return result; }
/** * <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)); }
/** * 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; } }
protected String toManyRelationshipName(DbRelationship... relationshipChain) { DbRelationship last = relationshipChain[relationshipChain.length - 1]; String baseName = stemmed(last.getTargetEntityName()); try { // by default we use English rules here... return Noun.pluralOf(baseName.toLowerCase(), Locale.ENGLISH); } catch (Exception inflectorError) { // seems that Inflector cannot be trusted. For instance, it // throws an exception when invoked for word "ADDRESS" (although // lower case works fine). To feel safe, we use superclass' // behavior if something's gone wrong return baseName; } }
name = Noun.pluralOf(key.getFKTableName().toLowerCase(), Locale.ENGLISH).toUpperCase();