org.javalite.common
Class Inflector

java.lang.Object
  extended by org.javalite.common.Inflector

public class Inflector
extends Object


Constructor Summary
Inflector()
           
 
Method Summary
static void addIrregular(String rule, String replacement)
           
static void addPlural(String rule, String replacement)
           
static void addSingular(String rule, String replacement)
           
static String camelize(String underscore)
          Generates a camel case version of a phrase from underscore.
static String camelize(String underscore, boolean capitalizeFirstChar)
          Generates a camel case version of a phrase from underscore.
static String capitalize(String word)
          Capitalizes a word - only a first character is converted to upper case.
static String getIdName(String tableName)
           
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.
static String gsub(String word, String rule, String replacement)
          Replaces a found pattern in a word and returns a transformed word.
static String pluralize(String word)
           
static String shortName(String className)
          Deprecated. Use clazz.getSimpleName() instead of Inflector.shortName(clazz.getName()).
static String singularize(String word)
           
static String tableize(String camelCase)
          Converts a camel case to underscore and then pluralizes.
static String underscore(String camel)
          Converts a CamelCase string to underscores: "AliceInWonderLand" becomes: "alice_in_wonderland"
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Inflector

public Inflector()
Method Detail

addPlural

public static void addPlural(String rule,
                             String replacement)

addSingular

public static void addSingular(String rule,
                               String replacement)

addIrregular

public static void addIrregular(String rule,
                                String replacement)

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.

pluralize

public static String pluralize(String word)

singularize

public static String singularize(String word)

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.

shortName

@Deprecated
public static String shortName(String className)
Deprecated. Use clazz.getSimpleName() instead of Inflector.shortName(clazz.getName()).


getIdName

public static String getIdName(String tableName)

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.


Copyright © 2015 JavaLite. All rights reserved.