|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.scooterframework.common.util.WordUtil
public class WordUtil
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 |
---|
public static final java.util.Map<java.lang.String,java.lang.String> single2plurals
public static final java.util.List<java.lang.String> plurals
public static final java.util.Map<java.lang.String,java.lang.String> plural2singles
public static final java.util.List<java.lang.String> singles
Constructor Detail |
---|
public WordUtil()
Method Detail |
---|
public static java.lang.String pluralize(java.lang.String word)
word
- the word to be converted to plural form
public static java.lang.String singularize(java.lang.String word)
word
- the word to be converted to singular form
public static java.lang.String replaceLast(java.lang.String data, java.lang.String oldSymbol, java.lang.String newSymbol)
data
- the original stringoldSymbol
- the old symbols to be replacednewSymbol
- the corresponding new symbol
public static void addPlural(java.lang.String single, java.lang.String plural)
single
- singular form of the wordplural
- plural form of the wordpublic static java.lang.String camelize(java.lang.String word)
word
- the word to be converted to camelized form
public static java.lang.String camelize(java.lang.String word, boolean firstLetterInLowerCase)
Examples: camelize("hello") ==> "Hello" camelize("hello world") ==> "Hello world" camelize("active_record") ==> "ActiveRecord" camelize("active_record", true) ==> "activeRecord"
word
- the word to be converted to camelized formfirstLetterInLowerCase
- true if the first character should be in lower case
public static java.lang.String underscore(java.lang.String phase)
Examples: underscore("Hello world") ==> "hello world" underscore("ActiveRecord") ==> "active_record" underscore("The RedCross") ==> "the red_cross" underscore("ABCD") ==> "abcd"
phase
- the original string
public static java.lang.String titleize(java.lang.String phase)
Examples: titleize("ch 1: Java-ActiveRecordIsFun") ==> "Ch 1: Java Active Record Is Fun"
phase
- the original string
public static java.lang.String humanize(java.lang.String phase)
Examples: humanize("active_record") ==> "Active record" humanize("post_id") ==> "Post"
phase
- the original string
public static java.lang.String tableize(java.lang.String modelClassName)
Examples: tableize("Person") ==> "people" tableize("LineItem") ==> "line_items"
modelClassName
-
public static java.lang.String classify(java.lang.String tableName)
Examples: classify("people") ==> "Person" classify("line_items") ==> "LineItem"
tableName
- java class name of the model
public static java.lang.String ordinalize(int number)
Examples: ordinalize(100) ==> "100th" ordinalize(1003) ==> "1003rd"
number
- the number
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |