java.lang.Object | |
↳ | humanize.Humanize |
Facility for adding a "human touch" to data. It is thread-safe and supports per-thread internationalization. Additionally provides a concise facade for access to Standard i18n Java APIs.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Converts a given number to a string preceded by the corresponding binary International System of Units (SI) prefix. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Makes a phrase camel case. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Capitalizes the given text smartly. | |||||||||||
Returns a SimpleDateFormat instance for the current thread. | |||||||||||
Same as | |||||||||||
Converts a camel case string into a human-readable name. | |||||||||||
Same as | |||||||||||
Returns a DecimalFormat instance for the current thread. | |||||||||||
Same as | |||||||||||
Formats a number of seconds as hours, minutes and seconds. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Formats a number of seconds as hours, minutes and seconds. | |||||||||||
Pads or truncates a string to a specified length. | |||||||||||
Pads or truncates a string to a specified length. | |||||||||||
Same as #format(String, Object...) for the specified locale. | |||||||||||
Gets an ExtendedMessageFormat instance for the current thread with the given pattern and uses it to format a message with the specified arguments. | |||||||||||
Same as | |||||||||||
Smartly formats the given number as a monetary amount. | |||||||||||
Formats a date according to the given pattern. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Formats the given date with the specified style. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Formats the given date/time with the specified styles. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Formats the given date/time with SHORT style. | |||||||||||
Formats the given number to the standard decimal format for the default locale. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
Formats the given ratio as a percentage. | |||||||||||
Same as | |||||||||||
Locale-sensitive string comparison for primary differences. | |||||||||||
Formats the given text with the mask specified. | |||||||||||
Returns a | |||||||||||
Same as | |||||||||||
Returns a MessageFormat instance for the current thread. | |||||||||||
Converts a given number to a string preceded by the corresponding decimal multiplicative prefix. | |||||||||||
Same as | |||||||||||
Formats a number of nanoseconds as the proper ten power unit. | |||||||||||
Same as | |||||||||||
Same as
naturalDay(int, Date) with the given locale. | |||||||||||
Same as
naturalDay(Date) with the given locale. | |||||||||||
For dates that are the current day or within one day, return 'today',
'tomorrow' or 'yesterday', as appropriate.
| |||||||||||
Same as
naturalDay(int, Date) with DateFormat.SHORT style. | |||||||||||
Same as
naturalTime(Date, long, Locale) . | |||||||||||
Same as
naturalTime(Date, Date) for the specified locale. | |||||||||||
Computes both past and future relative dates with arbitrary precision.
| |||||||||||
Same as
naturalTime(Date, Date) with current date as reference. | |||||||||||
Same as
naturalTime(Date, long) for the specified locale. | |||||||||||
Same as
naturalTime(Date, long) . | |||||||||||
Computes both past and future relative dates.
| |||||||||||
Same as
naturalTime(Date, Date, long) with current date as
reference. | |||||||||||
Same as
naturalTime(Date) for the specified locale. | |||||||||||
Same as
naturalTime(Date, Date, long) for the specified locale. | |||||||||||
Same as
naturalTime(Date, Date, long) . | |||||||||||
Converts a number to its ordinal as a string.
| |||||||||||
Same as
ordinal(Number) for the specified locale. | |||||||||||
Same as
oxford(Object[], int, String) for the specified locale. | |||||||||||
Converts a list of items to a human readable string. | |||||||||||
Converts a list of items to a human readable string with an optional limit. | |||||||||||
Same as
oxford(Object[]) for the specified locale. | |||||||||||
Same as
oxford(Object[]) for the specified locale. | |||||||||||
Converts a list of items to a human readable string. | |||||||||||
Converts a list of items to a human readable string with an optional limit. | |||||||||||
Matches a pace (value and interval) with a logical time frame.
| |||||||||||
Matches a pace (value and interval) with a logical time frame.
| |||||||||||
Matches a pace (value and interval) with a logical time frame.
| |||||||||||
Same as
paceFormat(Number, long) for a target locale. | |||||||||||
Same as
paceFormat(Number, long, String, String, String) for a
target locale. | |||||||||||
Converts the string argument into an array of bytes.
| |||||||||||
Converts the string argumento into a Date value.
| |||||||||||
Converts the string argumento into a Date value.
| |||||||||||
Converts the string argumento into a Date value.
| |||||||||||
Same as #parseSmartDateWithSeparator(String, String, String...) but with "[\\D-_\\s]+" as the default separator. | |||||||||||
Tries to parse a date string applying an array of non lenient format patterns. | |||||||||||
Same as #pluralize(String, String, Number, Object...) for the target locale. | |||||||||||
Same as #pluralize(String, String, String, Number, Object...) for the target locale. | |||||||||||
Applies the proper format for a given plural state. | |||||||||||
Applies the proper format for a given plural state. | |||||||||||
Same as | |||||||||||
Constructs a message with pluralization logic by the means of ChoiceFormat. | |||||||||||
Constructs a message with pluralization logic from the given template. | |||||||||||
Returns a thread-safe | |||||||||||
Same as | |||||||||||
Replaces characters outside the Basic Multilingual Plane with their name. | |||||||||||
Rounds a number to significant figures. | |||||||||||
Sort of poor man's transliteration, i.e. | |||||||||||
Transforms a text into a representation suitable to be used in an URL. | |||||||||||
Converts a big number to a friendly text representation. | |||||||||||
Same as | |||||||||||
Same as | |||||||||||
For decimal digits [0-9], returns the number spelled out. | |||||||||||
Same as
times(Number) for the specified locale. | |||||||||||
Interprets numbers as occurrences.
| |||||||||||
Converts the given text to title case smartly. | |||||||||||
Converts the given text to title case smartly. | |||||||||||
Makes a phrase underscored instead of spaced. | |||||||||||
Parses the given text with the mask specified. | |||||||||||
Truncate a string to the closest word boundary after a number of characters. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Converts a given number to a string preceded by the corresponding binary International System of Units (SI) prefix.
Input | Output |
---|---|
2 | "2 bytes" |
1536 | "1.5 kB" |
5242880 | "5.00 MB" |
1325899906842624L | "1.18 PB" |
value | Number to be converted |
---|
Same as binaryPrefix(Number)
for the specified locale.
value | Number to be converted |
---|---|
locale | Target locale |
Same as camelize(String)
for the specified locale.
text | String to be camelized |
---|---|
locale | Target locale |
Makes a phrase camel case. Spaces, hyphens, underscores and dots will be removed.
text | String to be camelized |
---|---|
capitalizeFirstChar | true makes the first letter uppercase |
Same as camelize(String, boolean)
with capitalize to false.
text | String to be camelized |
---|
Same as camelize(String, boolean)
for the specified locale.
text | String to be camelized |
---|---|
capitalizeFirstChar | true makes the first letter uppercase |
Same as capitalize(String)
for the specified locale.
text | String to be capitalized |
---|---|
locale | Target locale |
Capitalizes the given text smartly.
text | String to be capitalized |
---|
Returns a SimpleDateFormat instance for the current thread.
Date and time formats are specified by date and time pattern
strings. Within date and time pattern strings, unquoted letters from
'A'
to 'Z'
and from 'a'
to
'z'
are interpreted as pattern letters representing the
components of a date or time string. Text can be quoted using single
quotes ('
) to avoid interpretation. "''"
represents a single quote. All other characters are not interpreted;
they're simply copied into the output string during formatting or matched
against the input string during parsing.
The following pattern letters are defined (all other characters from
'A'
to 'Z'
and from 'a'
to
'z'
are reserved):
Pattern letters are usually repeated, as their number determines the exact presentation:
Letter Date or Time Component Presentation Examples G
Era designator Text AD
y
Year Year 1996
;96
M
Month in year Month July
;Jul
;07
w
Week in year Number 27
W
Week in month Number 2
D
Day in year Number 189
d
Day in month Number 10
F
Day of week in month Number 2
E
Day in week Text Tuesday
;Tue
a
Am/pm marker Text PM
H
Hour in day (0-23) Number 0
k
Hour in day (1-24) Number 24
K
Hour in am/pm (0-11) Number 0
h
Hour in am/pm (1-12) Number 12
m
Minute in hour Number 30
s
Second in minute Number 55
S
Millisecond Number 978
z
Time zone General time zone Pacific Standard Time
;PST
;GMT-08:00
Z
Time zone RFC 822 time zone -0800
SimpleDateFormat
must interpret the abbreviated year
relative to some century. It does this by adjusting dates to be within 80
years before and 20 years after the time the
SimpleDateFormat
instance is created. For example, using a
pattern of "MM/dd/yy" and a SimpleDateFormat
instance
created on Jan 1, 1997, the string "01/11/12" would be interpreted as Jan
11, 2012 while the string "05/04/64" would be interpreted as May 4, 1964.
During parsing, only strings consisting of exactly two digits, as defined
by isDigit(char)
, will be parsed into the default
century. Any other numeric string, such as a one digit string, a three or
more digit string, or a two digit string that isn't all digits (for
example, "-1"), is interpreted literally. So "01/02/3" or "01/02/003" are
parsed, using the same pattern, as Jan 2, 3 AD. Likewise, "01/02/-3" is
parsed as Jan 2, 4 BC.
long form
is used.
Otherwise, a calendar specific short or
abbreviated form
is used.
GMTOffsetTimeZone:Hours must be between 0 and 23, and Minutes must be between 00 and 59. The format is locale independent and digits must be taken from the Basic Latin block of the Unicode standard.GMT
Sign Hours:
Minutes Sign: one of+ -
Hours: Digit Digit Digit Minutes: Digit Digit Digit: one of0 1 2 3 4 5 6 7 8 9
For parsing, RFC 822 time zones are also accepted.
RFC822TimeZone: Sign TwoDigitHours Minutes TwoDigitHours: Digit DigitTwoDigitHours must be between 00 and 23. Other definitions are as for general time zones.
For parsing, general time zones are also accepted.
SimpleDateFormat
also supports localized date and time
pattern strings. In these strings, the pattern letters described
above may be replaced with other, locale dependent, pattern letters.
SimpleDateFormat
does not deal with the localization of text
other than the pattern letters; that's up to the client of the class.
Date and Time Pattern Result "yyyy.MM.dd G 'at' HH:mm:ss z"
2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"
Wed, Jul 4, '01
"h:mm a"
12:08 PM
"hh 'o''clock' a, zzzz"
12 o'clock PM, Pacific Daylight Time
"K:mm a, z"
0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa"
02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z"
Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ"
010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
2001-07-04T12:08:56.235-0700
pattern | Format pattern that follows the conventions of java.text.SimpleDateFormat SimpleDateFormat |
---|
Same as dateFormat(String)
for the specified locale.
pattern | Format pattern that follows the conventions of java.text.SimpleDateFormat SimpleDateFormat |
---|---|
locale | Target locale |
Converts a camel case string into a human-readable name.
Example assuming SPACE as replacement:
Input | Output |
---|---|
"MyClass" | "My Class" |
"GL11Version" | "GL 11 Version" |
"AString" | "A String" |
"SimpleXMLParser" | "Simple XML Parser" |
words | String to be converted |
---|---|
replacement | String to be interpolated |
Same as decamelize(String)
defaulting to SPACE for
replacement
words | String to be converted |
---|
Returns a DecimalFormat instance for the current thread.
pattern | Format pattern that follows the conventions of
DecimalFormat |
---|
Same as decimalFormat(String)
for the specified locale.
pattern | Format pattern that follows the conventions of
DecimalFormat |
---|---|
locale | Target locale |
Formats a number of seconds as hours, minutes and seconds.
seconds | Number of seconds |
---|---|
style | Time style |
Same as duration(Number, TimeStyle)
for the specified locale.
seconds | Number of seconds |
---|---|
style | Time style |
locale | Target locale |
Same as duration(Number)
for the specified locale.
seconds | Number of seconds |
---|---|
locale | Target locale |
Formats a number of seconds as hours, minutes and seconds. Defaults to STANDARD time style.
seconds | Number of seconds |
---|
Pads or truncates a string to a specified length.
text | String to be fixed |
---|---|
charsNum | The fixed length in number of chars |
paddingChar | The padding character |
left | true for left padding |
Pads or truncates a string to a specified length.
text | String to be fixed |
---|---|
charsNum | The fixed length in number of chars |
paddingChar | The padding character |
Same as #format(String, Object...) for the specified locale.
locale | The target locale |
---|---|
pattern | Format pattern that follows the conventions of
MessageFormat |
args | Arguments |
Gets an ExtendedMessageFormat instance for the current thread with the given pattern and uses it to format a message with the specified arguments.
pattern | Format pattern that follows the conventions of
MessageFormat |
---|---|
args | Arguments |
Same as formatCurrency(Number)
for the specified locale.
value | Number to be formatted |
---|---|
locale | Target locale |
Smartly formats the given number as a monetary amount.
For en_GB:
Input | Output |
---|---|
34 | "£34" |
1000 | "£1,000" |
12.5 | "£12.50" |
value | Number to be formatted |
---|
Formats a date according to the given pattern.
value | Date to be formatted |
---|---|
pattern | The pattern. |
Same as formatDate(Date)
for the specified locale.
value | Date to be formatted |
---|---|
locale | Target locale |
Same as formatDate(int, Date)
with SHORT style.
value | Date to be formatted |
---|
Formats the given date with the specified style.
style | DateFormat style |
---|---|
value | Date to be formatted |
Same as formatDate(Date, String)
for the specified locale.
value | Date to be formatted |
---|---|
pattern | The pattern. |
locale | Target locale |
Same as formatDate(int, Date)
for the specified locale.
style | DateFormat style |
---|---|
value | Date to be formatted |
locale | Target locale |
Formats the given date/time with the specified styles.
dateStyle | Date style |
---|---|
timeStyle | Time style |
value | Date to be formatted |
Same as formatDateTime(int, int, Date)
for the specified locale.
dateStyle | Date style |
---|---|
timeStyle | Time style |
value | Date to be formatted |
locale | Target locale |
Same as formatDateTime(Date)
for the specified locale.
value | Date to be formatted |
---|---|
locale | Target locale |
Formats the given date/time with SHORT style.
value | Date to be formatted |
---|
Formats the given number to the standard decimal format for the default locale.
value | Number to be formatted |
---|
Same as formatDecimal(Number)
for the specified locale.
value | Number to be formatted |
---|---|
locale | Target locale |
Same as formatPercent(Number)
for the specified locale.
value | Ratio to be converted |
---|---|
locale | Target locale |
Formats the given ratio as a percentage.
Input | Output |
---|---|
0.5 | "50%" |
1 | "100%" |
0.564 | "56%" |
value | Ratio to be converted |
---|
Same as lossyEquals(String, String)
for the specified locale.
locale | The target locale |
---|---|
source | The source string to be compared |
target | The target string to be compared |
Locale-sensitive string comparison for primary differences.
loosyEquals("Aáà-aa", "aaaaa") // == true
loosyEquals("abc", "cba") // == false
source | The source string to be compared |
---|---|
target | The target string to be compared |
Formats the given text with the mask specified.
mask | The pattern mask. |
---|---|
value | The text to be masked |
Returns a MaskFormat
instance for the current thread.
mask | The pattern mask |
---|
MaskFormat
instance
Same as messageFormat(String)
for the specified locale.
pattern | Format pattern that follows the conventions of java.text.MessageFormat MessageFormat |
---|---|
locale | Target locale |
Returns a MessageFormat instance for the current thread.
pattern | Format pattern that follows the conventions of java.text.MessageFormat MessageFormat |
---|
Converts a given number to a string preceded by the corresponding decimal multiplicative prefix.
Input | Output |
---|---|
200 | "200" |
1000 | "1k" |
3500000 | "3.5M" |
value | Number to be converted |
---|
Same as metricPrefix(Number)
for the specified locale.
value | Number to be converted |
---|---|
locale | Target locale |
Formats a number of nanoseconds as the proper ten power unit.
value | Number of nanoseconds |
---|
Same as nanoTime(Number)
for the specified locale.
value | Number of nanoseconds |
---|---|
locale | Target locale |
Same as naturalDay(int, Date)
with the given locale.
style | The style of the Date |
---|---|
then | The date (GMT) |
locale | Target locale |
Same as naturalDay(Date)
with the given locale.
then | The date |
---|---|
locale | Target locale |
For dates that are the current day or within one day, return 'today', 'tomorrow' or 'yesterday', as appropriate. Otherwise, returns a string formatted according to a locale sensitive DateFormat.
style | The style of the Date |
---|---|
then | The date (GMT) |
Same as naturalDay(int, Date)
with DateFormat.SHORT style.
then | The date |
---|
Same as naturalTime(Date, long, Locale)
.
duration | The duration |
---|---|
precision | The precesion to retain in milliseconds |
locale | The locale |
Same as naturalTime(Date, Date)
for the specified locale.
reference | The reference |
---|---|
duration | The duration |
locale | The locale |
Computes both past and future relative dates with arbitrary precision.
duration | The duration |
---|---|
precision | The precision to retain in milliseconds |
reference | The reference |
---|---|
duration | The duration |
precision | The precesion to retain in milliseconds |
locale | The locale |
Same as naturalTime(Date, Date)
with current date as reference.
duration | The duration |
---|
Same as naturalTime(Date, long)
for the specified locale.
duration | The duration |
---|---|
precision | The precesion to retain in milliseconds |
locale | The locale |
Same as naturalTime(Date, long)
.
duration | The duration |
---|---|
precision | The precision to retain in milliseconds |
Computes both past and future relative dates.
E.g. 'one day ago', 'one day from now', '10 years ago', '3 minutes from now', 'right now' and so on.
reference | The reference |
---|---|
duration | The duration |
Same as naturalTime(Date, Date, long)
with current date as
reference.
duration | The duration |
---|---|
precision | The precision to retain in milliseconds |
Same as naturalTime(Date)
for the specified locale.
duration | The duration |
---|---|
locale | The locale |
Same as naturalTime(Date, Date, long)
for the specified locale.
reference | The reference |
---|---|
duration | The duration |
precision | The precesion to retain in milliseconds |
locale | The locale |
Same as naturalTime(Date, Date, long)
.
duration | The duration |
---|---|
precision | The precision to retain in milliseconds |
Converts a number to its ordinal as a string.
E.g. 1 becomes '1st', 2 becomes '2nd', 3 becomes '3rd', etc.
value | The number to convert |
---|
Same as ordinal(Number)
for the specified locale.
value | The number to convert |
---|---|
locale | The locale |
Same as oxford(Object[], int, String)
for the specified locale.
items | The items array |
---|---|
limit | The number of items to print. -1 for unbounded. |
limitStr | The string to be appended after extra items. Null or "" for default. |
locale | Target locale |
Converts a list of items to a human readable string.
items | The items array |
---|
Converts a list of items to a human readable string with an optional limit.
items | The items collection |
---|---|
limit | The number of items to print. -1 for unbounded. |
limitStr | The string to be appended after extra items. Null or "" for default. |
Same as oxford(Object[])
for the specified locale.
items | The items collection |
---|---|
locale | Target locale |
Same as oxford(Object[])
for the specified locale.
items | The items array |
---|---|
locale | Target locale |
Converts a list of items to a human readable string.
items | The items collection |
---|
Converts a list of items to a human readable string with an optional limit.
items | The items array |
---|---|
limit | The number of items to print. -1 for unbounded. |
limitStr | The string to be appended after extra items. Null or "" for default. |
Matches a pace (value and interval) with a logical time frame. Very useful for slow paces.
Examples:
// 3 occurrences within a 3000ms interval
pace(3, 3000); // => ~1/sec.
// 200 occurrences within a 70000ms interval
pace(200, 70000); // => ~3/sec.
// 10 occurrences within a 70000ms interval
pace(10, 70000); // => ~9/min.
// 14 occurrences within a 31557600000ms interval (a year)
pace(14, 31557600000L); // => ~1/month
// 25 occurrences within a 31557600000ms interval
pace(25, 31557600000L); // => ~2/month
// 9 occurrences within a 31557600000ms interval
pace(9, 31557600000L); // => >1/month (less than one per month)
value | The number of occurrences within the specified interval |
---|---|
interval | The interval in milliseconds |
Matches a pace (value and interval) with a logical time frame. Very useful for slow paces.
value | The number of occurrences within the specified interval |
---|---|
interval | The interval in milliseconds |
one | The message format for one time occurrences |
many | The message format for multiple times occurrences |
none | The message format for no occurrence |
Matches a pace (value and interval) with a logical time frame. Very useful for slow paces. e.g. heartbeats, ingested calories, hyperglycemic crises.
value | The number of occurrences within the specified interval |
---|---|
interval | The interval in milliseconds |
Same as paceFormat(Number, long)
for a target locale.
locale | The target locale |
---|---|
value | The number of occurrences within the specified interval |
interval | The interval in milliseconds |
Same as paceFormat(Number, long, String, String, String)
for a
target locale.
locale | The target locale |
---|---|
value | The number of occurrences within the specified interval |
interval | The interval in milliseconds |
one | The message format for one time occurrences |
many | The message format for multiple times occurrences |
none | The message format for no occurrence |
Converts the string argument into an array of bytes.
base64str | The Base64 encoded string |
---|
Converts the string argumento into a Date value.
dateStr | The ISO8601 date string |
---|
Converts the string argumento into a Date value.
dateStr | The ISO8601 date string |
---|
Converts the string argumento into a Date value.
timeStr | The ISO8601 time string |
---|
Same as #parseSmartDateWithSeparator(String, String, String...) but with "[\\D-_\\s]+" as the default separator.
Example:Date target = newDate(2012, 1, 1, 0, 0, 0); String dates[] = new String[] { "1.2.12", "01.02.2012", "2012.02.01", "01-02-12", "1 2 2012" }; for (String ds : dates) { Date date = Humanize.parseSmartDate(ds, "dd/MM/yy", "yyyy/MM/dd", "dd/MM/yyyy"); Assert.assertEquals(date, target); }
dateStr | The date string |
---|---|
fmts | An array of formats |
Tries to parse a date string applying an array of non lenient format patterns. The formats are automatically cached.
dateStr | The date string |
---|---|
separator | The separator regexp |
fmts | An array of formats |
Same as #pluralize(String, String, Number, Object...) for the target locale.
locale | Target locale |
---|---|
one | Format for single element |
many | Format for many elements |
n | The number that triggers the plural state |
exts | Extended parameters for the specified formats |
Same as #pluralize(String, String, String, Number, Object...) for the target locale.
locale | Target locale |
---|---|
one | Format for single element |
many | Format for many elements |
none | Format for no element |
n | The number that triggers the plural state |
exts | Extended parameters for the specified formats |
Applies the proper format for a given plural state.
Example:pluralize("There is one file on {1}.", "There are {0} files on {1}.", "There are no files on {1}.", 1, "disk"); // == There is one file on disk. pluralize("There is one file on {1}.", "There are {0} files on {1}.", "There are no files on {1}.", 2, "disk"); // == There are 2 files on disk. pluralize("There is one file on {1}.", "There are {0} files on {1}.", "There are no files on {1}.", 0, "disk"); // == There are no files on disk. pluralize("one", "{0}", "none", 1); // = "one" pluralize("one", "{0}", "none", 2); // = "2"
one | Format for single element |
---|---|
many | Format for many elements |
none | Format for no element |
n | The number that triggers the plural state |
exts | Extended parameters for the specified formats |
Applies the proper format for a given plural state.
Example:pluralize("There is one file on {1}.", "There are {0} files on {1}.", 1, "disk"); // == There is one file on disk. pluralize("There is one file on {1}.", "There are {0} files on {1}.", 2, "disk"); // == There are 2 files on disk.
one | Format for single element |
---|---|
many | Format for many elements |
n | The number that triggers the plural state |
exts | Extended parameters for the specified formats |
Same as pluralizeFormat(String)
for the specified locale.
template | String of tokens delimited by '::' |
---|---|
locale | Target locale |
Constructs a message with pluralization logic by the means of ChoiceFormat.
pattern | Base pattern |
---|---|
choices | Values that match the pattern |
Constructs a message with pluralization logic from the given template.
MessageFormat msg = pluralize("There {0} on {1}.::are no files::is one file::are {2} files"); msg.render(0, "disk"); // == "There are no files on disk." msg.render(1, "disk"); // == "There is one file on disk." msg.render(1000, "disk"); // == "There are 1,000 files on disk."
MessageFormat msg = pluralize("nothing::one thing::{0} things"); msg.render(-1); // == "nothing" msg.render(0); // == "nothing" msg.render(1); // == "one thing" msg.render(2); // == "2 things"
MessageFormat msg = pluralize("one thing::{0} things"); msg.render(-1); // == "-1 things" msg.render(0); // == "0 things" msg.render(1); // == "one thing" msg.render(2); // == "2 things"
template | String of tokens delimited by '::' |
---|
Same as prettyTimeFormat()
for the specified locale.
locale | Target locale |
---|
Replaces characters outside the Basic Multilingual Plane with their name.
value | The text to be matched |
---|
Rounds a number to significant figures.
num | The number to be rounded |
---|---|
precision | The number of significant digits |
Sort of poor man's transliteration, i.e. normalizes and strips diacritical marks.
Input | Output |
---|---|
"J'étudie le français" | "J'etudie le francais" |
"Lo siento, no hablo español." | "Lo siento, no hablo espanol." |
text | The text to be simplified. |
---|
Transforms a text into a representation suitable to be used in an URL.
Input | Output |
---|---|
"J'étudie le français" | "jetudie-le-francais" |
"Lo siento, no hablo español." | "lo-siento-no-hablo-espanol" |
text | The text to be slugified |
---|
Converts a big number to a friendly text representation. Accepts values ranging from thousands to googols. Uses BigDecimal.
value | Number to be converted |
---|
Same as spellBigNumber(Number)
for the specified locale.
value | Number to be converted |
---|---|
locale | Target locale |
Same as spellDigit(Number)
for the specified locale.
value | Decimal digit |
---|---|
locale | Target locale |
For decimal digits [0-9], returns the number spelled out. Otherwise, returns the number as string.
Input | Output |
---|---|
1 | "one" |
2 | "two" |
10 | "10" |
value | Decimal digit |
---|
Same as times(Number)
for the specified locale.
num | The number of occurrences |
---|---|
locale | Target locale |
Interprets numbers as occurrences.
num | The number of occurrences |
---|
Converts the given text to title case smartly.
Known limitations:text | Text to be converted |
---|
Converts the given text to title case smartly.
text | Text to be converted |
---|---|
intCaps | An internal capitalized word list |
Makes a phrase underscored instead of spaced.
text | Phrase to underscore |
---|
Parses the given text with the mask specified.
mask | The pattern mask. |
---|---|
value | The text to be parsed |
ParseException | |
ParseException |
Truncate a string to the closest word boundary after a number of characters.
value | Text to be truncated |
---|---|
len | Number of characters |