package org.apache.wicket.util.string;
Holds an immutable String value and optionally a Locale, with methods to convert to various
types. Also provides some handy parsing methods and a variety of static factory methods.
Objects can be constructed directly from Strings or by using the valueOf() static factory
methods. The repeat() static factory methods provide a way of generating a String value that
repeats a given char or String a number of times.
Conversions to a wide variety of types can be found in the to*() methods. A generic conversion
can be achieved with to(Class).
The beforeFirst(), afterFirst(), beforeLast() and afterLast() methods are handy for parsing
things like paths and filenames.
Locale to be used for formatting and parsing.
- Parameters:
times
Number of times to repeat characterc
Character to repeat- Returns:
- Repeated character string
for (int i = 0; i < times; i++)
- Parameters:
times
Number of times to repeat strings
String to repeat- Returns:
- Repeated character string
for (int i = 0; i < times; i++)
Converts the given input to an instance of StringValue.
- Parameters:
value
Double precision value- Returns:
- String value formatted with one place after decimal
Converts the given input to an instance of StringValue.
- Parameters:
value
Double precision valueplaces
Number of places after decimallocale
Locale to be used for formatting- Returns:
- String value formatted with the given number of places after decimal
Converts the given input to an instance of StringValue.
- Parameters:
value
Double precision valuelocale
Locale to be used for formatting- Returns:
- String value formatted with one place after decimal
Converts the given input to an instance of StringValue.
- Parameters:
object
An object- Returns:
- String value for object
Converts the given input to an instance of StringValue.
- Parameters:
object
An objectlocale
Locale to be used for formatting- Returns:
- String value for object
Converts the given input to an instance of StringValue.
- Parameters:
string
A string- Returns:
- String value for string
Converts the given input to an instance of StringValue.
- Parameters:
string
A stringlocale
Locale to be used for formatting- Returns:
- String value for string
Converts the given input to an instance of StringValue.
- Parameters:
buffer
A string buffer- Returns:
- String value
Private constructor to force use of static factory methods.
- Parameters:
text
The text for this string value
Private constructor to force use of static factory methods.
- Parameters:
text
The text for this string valuelocale
the locale for formatting and parsing
Gets the substring after the first occurrence given char.
- Parameters:
c
char to scan for- Returns:
- the substring
Gets the substring after the last occurrence given char.
- Parameters:
c
char to scan for- Returns:
- the substring
Gets the substring before the first occurrence given char.
- Parameters:
c
char to scan for- Returns:
- the substring
Gets the substring before the last occurrence given char.
- Parameters:
c
char to scan for- Returns:
- the substring
Replaces on this text.
- Parameters:
searchFor
What to search forreplaceWith
What to replace with- Returns:
- This string value with searchFor replaces with replaceWith
Converts this StringValue to a given type.
Convert this text to a boolean.
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
- Throws:
StringValueConversionException
public final boolean toBoolean(final boolean defaultValue)
Convert this text to a boolean.
Convert this text to a char.
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
- Throws:
StringValueConversionException
Convert this text to a Character.
Convert this text to a double.
"' to a double value", e);
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
- Throws:
StringValueConversionException
Convert this text to a Double.
Convert this text to a Duration instance.
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
- Throws:
StringValueConversionException
Convert this text to an int.
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
- Throws:
StringValueConversionException
return (text == null) ? defaultValue : toInt();
Convert this text to an Integer.
"' to an Integer value", e);
Convert this text to a long.
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
- Throws:
StringValueConversionException
Convert this text to a Long.
Convert to object types, returning null if text is null.
Convert to object types, returning null if text is null.
Convert to object types, returning null if text is null.
Convert to object types, returning null if text is null.
Convert to object types, returning null if text is null.
Convert to object types, returning null if text is null.
Convert to object types, returning null if text is null.
Convert to object types, returning null if text is null.
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
return (text == null) ? defaultValue : text;
Convert this text to a time instance.
Convert to primitive types, returning default value if text is null.
- Parameters:
defaultValue
the default value to return of text is null- Returns:
- the converted text as a primitive or the default if text is null
- Throws:
StringValueConversionException
Returns whether the text is null.
- Returns:
true if the text is null, false
otherwise.
Returns whether the text is null or empty
- Returns:
true if the text is null or
.trim().length()==0, false otherwise.