Package org.javalite.common
Class Inflector
java.lang.Object
org.javalite.common.Inflector
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddIrregular(String rule, String replacement)static voidstatic voidaddSingular(String rule, String replacement)static StringGenerates a camel case version of a phrase from underscore.static StringGenerates a camel case version of a phrase from underscore.Will camelize the keys of the map and will return a new map with the same values, but CamelCase keys.static Stringcapitalize(String word)Capitalizes a word - only a first character is converted to upper case.static Stringstatic StringgetOtherName(String source, String target)If a table name is made of two other table names (as is typical for many to many relationships), this method retrieves a name of "another" table from a join table name.static StringReplaces a found pattern in a word and returns a transformed word.static Stringstatic Stringsingularize(String word)static StringConverts a camel case to underscore and then pluralizes.static Stringunderscore(String camel)Converts a CamelCase string to underscores: "AliceInWonderLand" becomes: "alice_in_wonderland"underscore(Map<?,Object> input)Will underscore the keys of the map and will return a new map with the same values, but under_score keys.
-
Method Details
-
addPlural
-
addSingular
-
addIrregular
-
gsub
Replaces a found pattern in a word and returns a transformed word.- Parameters:
word-rule-replacement-- Returns:
- Replaces a found pattern in a word and returns a transformed word. Null is pattern does not match.
-
pluralize
-
singularize
-
tableize
Converts a camel case to underscore and then pluralizes. Example: "GrayDuck" is converted to "gray_ducks".- Parameters:
camelCase- any CamelCase phrase.- Returns:
- pluralized version of underscored CamelCase.
-
underscore
Converts a CamelCase string to underscores: "AliceInWonderLand" becomes: "alice_in_wonderland"- Parameters:
camel- camel case input- Returns:
- result converted to underscores.
-
camelize
Generates a camel case version of a phrase from underscore.- Parameters:
underscore- underscore version of a word to converted to camel case.- Returns:
- camel case version of underscore.
-
camelize
Generates a camel case version of a phrase from underscore.- Parameters:
underscore- underscore version of a word to converted to camel case.capitalizeFirstChar- set to true if first character needs to be capitalized, false if not.- Returns:
- camel case version of underscore.
-
camelize
Will camelize the keys of the map and will return a new map with the same values, but CamelCase keys.- Parameters:
input- map whose keys to conver to to CamelCasecapitalizeFirstChar- tru to capitalize a first character.- Returns:
- new map with the same values, but CamelCase keys
-
underscore
Will underscore the keys of the map and will return a new map with the same values, but under_score keys.- Parameters:
input- map whose keys to convert to to under_score- Returns:
- new map with the same values, but underscore keys
-
capitalize
Capitalizes a word - only a first character is converted to upper case.- Parameters:
word- word/phrase to capitalize.- Returns:
- same as input argument, but the first character is capitalized.
-
getIdName
-
getOtherName
If a table name is made of two other table names (as is typical for many to many relationships), this method retrieves a name of "another" table from a join table name. For instance, if a source table is "payer" and the target is "player_game", then the returned value will be "game".- Parameters:
source- known table name. It may or may not exist in the target table name.target- this is a potential "join" table name.- Returns:
- a name of "another" table from a join table name.
-