Package com.axelor.common
Class Inflector
- java.lang.Object
-
- com.axelor.common.Inflector
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
camelize(String word)
Convert the given word to camel case.String
camelize(String word, boolean lower)
Convert the given word to camel case.String
capitalize(String word)
Capitalize the given string.String
classify(String text)
Convert the given word to class name.String
dasherize(String word)
Convert the give word to dasherized form.String
ellipsize(String text, int length)
Shorten the given text upto the length by appending three ellipses.static Inflector
getInstance()
String
humanize(String word)
Convert the given word to human readable form.String
ordinalize(int number)
Return ordinal suffixed string for the given number.String
pluralize(String word)
Returns the plural form of the word in the given string.String
simplify(String text)
Simplify the text to its unaccented version.String
singularize(String word)
Returns the singular form of the word in the given string.String
tableize(String camelCase)
Convert the given word to table name.String
titleize(String word)
Convert the given string to nicer looking title string.String
underscore(String camelCase)
Convert the given string to underscored, lowercase form.
-
-
-
Method Detail
-
getInstance
public static Inflector getInstance()
-
pluralize
public String pluralize(String word)
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
public String singularize(String word)
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
public String camelize(String word, boolean lower)
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
public String camelize(String word)
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
public String underscore(String camelCase)
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
public String humanize(String word)
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
public String titleize(String word)
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
public String tableize(String camelCase)
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
public String classify(String text)
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
public String dasherize(String word)
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
public String capitalize(String word)
Capitalize the given string.- Parameters:
word
- the string to convert- Returns:
- converted string
-
ordinalize
public String ordinalize(int number)
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
public String ellipsize(String text, int length)
Shorten the given text upto the length by appending three ellipses.- Parameters:
text
- text to shortenlength
- desired length- Returns:
- shortened text
-
simplify
public String simplify(String text)
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
-
-