Package com.axelor.common
Class Inflector
java.lang.Object
com.axelor.common.Inflector
The
Inflector
provides various methods to transform words to plural, singular, titles,
class names, table names etc.-
Method Summary
Modifier and TypeMethodDescriptionConvert the given word to camel case.Convert the given word to camel case.capitalize
(String word) Capitalize the given string.Convert the given word to class name.Convert the give word to dasherized form.Shorten the given text upto the length by appending three ellipses.static Inflector
Convert the given word to human readable form.ordinalize
(int number) Return ordinal suffixed string for the given number.Returns the plural form of the word in the given string.Simplify the text to its unaccented version.singularize
(String word) Returns the singular form of the word in the given string.Convert the given word to table name.Convert the given string to nicer looking title string.underscore
(String camelCase) Convert the given string to underscored, lowercase form.
-
Method Details
-
getInstance
-
pluralize
Returns the plural form of the word in the given string.inflection.pluralize("post"); // "posts" inflection.pluralize("child"); // "children" inflection.pluralize("octopus"); // "octopi" inflection.pluralize("sheep"); // "sheep"
- Parameters:
word
- the string to pluralize- Returns:
- pluralized string
-
singularize
Returns the singular form of the word in the given string.inflection.singularize("posts"); // "post" inflection.singularize("children"); // "child" inflection.singularize("octopi"); // "octopus" inflection.singularize("sheep"); // "sheep"
- Parameters:
word
- the string to singularize- Returns:
- singularized string
-
camelize
Convert the given word to camel case.inflection.camelcase("address_book", false); // "AddressBook" inflection.camelcase("address-book", true); // "addressBook" inflection.camelcase("Address book", false); // "AddressBook"
- Parameters:
word
- the word to convertlower
- whether to create lower camel case- Returns:
- camel case string
-
camelize
Convert the given word to camel case.inflection.camelcase("address_book"); // "AddressBook" inflection.camelcase("address-book"); // "AddressBook" inflection.camelcase("Address book"); // "AddressBook"
- Parameters:
word
- the word to convert- Returns:
- camel case string
-
underscore
Convert the given string to underscored, lowercase form.inflection.underscore("AddressBook"); // "address_book" inflection.underscore("address-book"); // "address_book" inflection.underscore("Address book"); // "address_book"
- Parameters:
camelCase
- the string to convert- Returns:
- converted string
-
humanize
Convert the given word to human readable form.inflection.humanize("contact_id"); // "Contact" inflection.humanize("address_list"); // "Addresses" inflection.humanize("_id"); // "Id"
- Parameters:
word
- the string to convert- Returns:
- converted string
-
titleize
Convert the given string to nicer looking title string.inflection.titleize("address_book"); // "Address Book" inflection.titleize("My address_book"); // "My Address Book"
- Parameters:
word
- the string to convert- Returns:
- converted string
-
tableize
Convert the given word to table name.inflection.tableize("AddressBook"); // "address_books" inflection.tableize("Contact"); // "contacts"
- Parameters:
camelCase
- the string to convert- Returns:
- converted string
-
classify
Convert the given word to class name.inflection.tableize("address_books"); // "AddressBook" inflection.tableize("contacts"); // "Contact"
- Parameters:
text
- the string to convert- Returns:
- converted string
-
dasherize
Convert the give word to dasherized form.inflection.tableize("address_books"); // "address-book" inflection.tableize("AddressBook"); // "address-book"
- Parameters:
word
- the string to convert- Returns:
- converted string
-
capitalize
Capitalize the given string.- Parameters:
word
- the string to convert- Returns:
- converted string
-
ordinalize
Return ordinal suffixed string for the given number.inflection.ordinalize(1); // "1st" inflection.ordinalize(2); // "2nd" inflection.ordinalize(3); // "3rd" inflection.ordinalize(100); // "100th" inflection.ordinalize(103); // "103rd" inflection.ordinalize(10013); // "10013th"
- Parameters:
number
- the number to suffix- Returns:
- the converted string
-
ellipsize
Shorten the given text upto the length by appending three ellipses.- Parameters:
text
- text to shortenlength
- desired length- Returns:
- shortened text
-
simplify
Simplify the text to its unaccented version.It uses
Normalizer.normalize(CharSequence, java.text.Normalizer.Form)
withNormalizer.Form.NFD
normalization and then replaces accented characters with their equivalent unaccented characters.- Parameters:
text
- the text to normalize- Returns:
- normalized text
-