Package org.javalite.common
Class Inflector
- java.lang.Object
-
- org.javalite.common.Inflector
-
public class Inflector extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddIrregular(String rule, String replacement)static voidaddPlural(String rule, String replacement)static voidaddSingular(String rule, String replacement)static Stringcamelize(String underscore)Generates a camel case version of a phrase from underscore.static Stringcamelize(String underscore, boolean capitalizeFirstChar)Generates a camel case version of a phrase from underscore.static Stringcapitalize(String word)Capitalizes a word - only a first character is converted to upper case.static StringgetIdName(String tableName)static 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 Stringgsub(String word, String rule, String replacement)Replaces a found pattern in a word and returns a transformed word.static Stringpluralize(String word)static Stringsingularize(String word)static Stringtableize(String camelCase)Converts a camel case to underscore and then pluralizes.static Stringunderscore(String camel)Converts a CamelCase string to underscores: "AliceInWonderLand" becomes: "alice_in_wonderland"
-
-
-
Method Detail
-
gsub
public static String gsub(String word, String rule, String replacement)
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.
-
tableize
public static String tableize(String camelCase)
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
public static String underscore(String camel)
Converts a CamelCase string to underscores: "AliceInWonderLand" becomes: "alice_in_wonderland"- Parameters:
camel- camel case input- Returns:
- result converted to underscores.
-
camelize
public static String camelize(String underscore)
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
public static String camelize(String underscore, boolean capitalizeFirstChar)
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.
-
capitalize
public static String capitalize(String word)
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.
-
getOtherName
public static String getOtherName(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. 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.
-
-