com.scooterframework.common.util
Class WordUtil

java.lang.Object
  extended by com.scooterframework.common.util.WordUtil

public class WordUtil
extends java.lang.Object

Conversion between singular and plural form of a noun word.


Field Summary
static java.util.Map<java.lang.String,java.lang.String> plural2singles
           
static java.util.List<java.lang.String> plurals
           
static java.util.Map<java.lang.String,java.lang.String> single2plurals
           
static java.util.List<java.lang.String> singles
           
 
Constructor Summary
WordUtil()
           
 
Method Summary
static void addPlural(java.lang.String single, java.lang.String plural)
          Adds more pairs of single and plural words.
static java.lang.String camelize(java.lang.String word)
          Converts string to Camel case.
static java.lang.String camelize(java.lang.String word, boolean firstLetterInLowerCase)
          Converts string to Camel case.
static java.lang.String classify(java.lang.String tableName)
          Returns a model class name corresponding to the input database table name.
static java.lang.String humanize(java.lang.String phase)
          Replaces all dashes and underscores by spaces and capitalizes the first word.
static java.lang.String ordinalize(int number)
          Returns an ordinalized string.
static java.lang.String pluralize(java.lang.String word)
          Returns a pluralized word.
static java.lang.String replaceLast(java.lang.String data, java.lang.String oldSymbol, java.lang.String newSymbol)
          Replaces the last occurance of an old symbol with a new symbol.
static java.lang.String singularize(java.lang.String word)
          Returns a singularized word from a plural word.
static java.lang.String tableize(java.lang.String modelClassName)
          Returns a database table name corresponding to the input model class name.
static java.lang.String titleize(java.lang.String phase)
          Replaces all dashes and underscores by spaces and capitalizes all the words.
static java.lang.String underscore(java.lang.String phase)
          underscore is the reverse of camelize method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

single2plurals

public static final java.util.Map<java.lang.String,java.lang.String> single2plurals

plurals

public static final java.util.List<java.lang.String> plurals

plural2singles

public static final java.util.Map<java.lang.String,java.lang.String> plural2singles

singles

public static final java.util.List<java.lang.String> singles
Constructor Detail

WordUtil

public WordUtil()
Method Detail

pluralize

public static java.lang.String pluralize(java.lang.String word)
Returns a pluralized word.

Parameters:
word - the word to be converted to plural form
Returns:
pluralized string

singularize

public static java.lang.String singularize(java.lang.String word)
Returns a singularized word from a plural word.

Parameters:
word - the word to be converted to singular form
Returns:
singularized string

replaceLast

public static java.lang.String replaceLast(java.lang.String data,
                                           java.lang.String oldSymbol,
                                           java.lang.String newSymbol)
Replaces the last occurance of an old symbol with a new symbol.

Parameters:
data - the original string
oldSymbol - the old symbols to be replaced
newSymbol - the corresponding new symbol
Returns:
a new string

addPlural

public static void addPlural(java.lang.String single,
                             java.lang.String plural)
Adds more pairs of single and plural words.

Parameters:
single - singular form of the word
plural - plural form of the word

camelize

public static java.lang.String camelize(java.lang.String word)
Converts string to Camel case.

Parameters:
word - the word to be converted to camelized form
Returns:
a camelized string

camelize

public static java.lang.String camelize(java.lang.String word,
                                        boolean firstLetterInLowerCase)
Converts string to Camel case. If firstLetterInLowerCase is true, then the first letter of the result string is in lower case.
 Examples:
   camelize("hello")               ==> "Hello"
   camelize("hello world")         ==> "Hello world"
   camelize("active_record")       ==> "ActiveRecord"
   camelize("active_record", true) ==> "activeRecord"
 

Parameters:
word - the word to be converted to camelized form
firstLetterInLowerCase - true if the first character should be in lower case
Returns:
a camelized string

underscore

public static java.lang.String underscore(java.lang.String phase)
underscore is the reverse of camelize method.
 Examples:
   underscore("Hello world")  ==> "hello world"
   underscore("ActiveRecord") ==> "active_record"
   underscore("The RedCross") ==> "the red_cross"
   underscore("ABCD")         ==> "abcd"
 

Parameters:
phase - the original string
Returns:
an underscored string

titleize

public static java.lang.String titleize(java.lang.String phase)
Replaces all dashes and underscores by spaces and capitalizes all the words.
 Examples:
   titleize("ch 1:  Java-ActiveRecordIsFun") ==> "Ch 1:  Java Active Record Is Fun"
 

Parameters:
phase - the original string
Returns:
a titleized string

humanize

public static java.lang.String humanize(java.lang.String phase)
Replaces all dashes and underscores by spaces and capitalizes the first word. Also removes
 Examples:
   humanize("active_record") ==> "Active record"
   humanize("post_id")       ==> "Post"
 

Parameters:
phase - the original string
Returns:
a humanized string

tableize

public static java.lang.String tableize(java.lang.String modelClassName)
Returns a database table name corresponding to the input model class name.
 Examples:
   tableize("Person")   ==> "people"
   tableize("LineItem") ==> "line_items"
 

Parameters:
modelClassName -
Returns:
the table name of the java model class name

classify

public static java.lang.String classify(java.lang.String tableName)
Returns a model class name corresponding to the input database table name.
 Examples:
   classify("people")   ==> "Person"
   classify("line_items") ==> "LineItem"
 

Parameters:
tableName - java class name of the model
Returns:
a java model class name

ordinalize

public static java.lang.String ordinalize(int number)
Returns an ordinalized string.
 Examples:
   ordinalize(100)  ==> "100th"
   ordinalize(1003) ==> "1003rd"
 

Parameters:
number - the number
Returns:
an ordinalized string for the number