|
SoftNet-Consult Java Utility Library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.softnetConsult.utils.string.StringTools
public final class StringTools
Defines static utility methods for string processing.
This product includes software developed by the
SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.
File: StringTools.java
Library API version: "2.02"
Java compliance version: "1.5"
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library
project and its contributors.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Field Summary | |
---|---|
private static java.text.NumberFormat |
singeltonNumberFormatter
An internal singelton instance of a default number formatter. |
Constructor Summary | |
---|---|
private |
StringTools()
Prevents instances of this class from being created as this class contains only static utility methods. |
Method Summary | |
---|---|
static void |
enforceNumberFormatterReset()
Resets the internal number formatter such that next time it is required (e.g. |
static java.lang.String |
ensureMinLength(java.lang.String str,
int length)
Ensures that the specified string is not shorter than the specified length by prefixing it with a white spaces. |
static java.lang.String |
ensureMinLength(java.lang.String str,
int length,
char fill)
Ensures that the specified string is not shorter than the specified length by prefixing it with the specified character as necessary. |
private static java.text.NumberFormat |
getSingeltonNumberFormatter()
Used internally to access a singelton instance of a default number formatter. |
static byte |
parseByte(java.lang.String str)
Parses a string to a byte -number using the current default locale.This is equivalent to parseNumber(str).byteValue() .Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static double |
parseDouble(java.lang.String str)
Parses a string to a double -number using the current default locale.This is equivalent to parseNumber(str).doubleValue() .Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static float |
parseFloat(java.lang.String str)
Parses a string to a float -number using the current default locale.This is equivalent to parseNumber(str).floatValue() .Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static int |
parseInt(java.lang.String str)
Parses a string to a int -number using the current default locale.This is equivalent to parseNumber(str).intValue() .Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static long |
parseLong(java.lang.String str)
Parses a string to a long -number using the current default locale.This is equivalent to parseNumber(str).longValue() .Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static java.lang.Number |
parseNumber(java.lang.String str)
Parses a string to a number using the current default locale. Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static short |
parseShort(java.lang.String str)
Parses a string to a short -number using the current default locale.This is equivalent to parseNumber(str).shortValue() .Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static java.lang.String |
toString(byte val)
Formats a byte -value to a String using the current default locale.Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static java.lang.String |
toString(double val)
Formats a double -value to a String using the current default locale.Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static java.lang.String |
toString(float val)
Formats a float -value to a String using the current default locale.Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static java.lang.String |
toString(int val)
Formats a int -value to a String using the current default locale.Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static java.lang.String |
toString(long val)
Formats a long -value to a String using the current default locale.Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
static java.lang.String |
toString(short val)
Formats a short -value to a String using the current default locale.Note that the current locale is determined only once at the time when any of this class' methods parseXXXX(String) or
toString(xxxx) is called for the first time. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.text.NumberFormat singeltonNumberFormatter
Constructor Detail |
---|
private StringTools()
Method Detail |
---|
private static java.text.NumberFormat getSingeltonNumberFormatter()
public static void enforceNumberFormatterReset()
parseXXXX(String)
and toString(xxxx)
)
a new formatter is re-created using the current default locale.
This method may be useful after the system default locale has been changed by the user
in order to update the state of this class' formatter.
public static java.lang.String ensureMinLength(java.lang.String str, int length)
ensureMinLength(str, length, ' ')
.
str
- A string (null
-strings are converted to the string "null"
).length
- The required minimum length for the string.
public static java.lang.String ensureMinLength(java.lang.String str, int length, char fill)
str
- A string (null
-strings are converted to the string "null"
).length
- The required minimum length for the string.fill
- The character to use for the prefix.
public static java.lang.Number parseNumber(java.lang.String str) throws java.lang.NumberFormatException
parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
str
- A string.
java.lang.NumberFormatException
- If the specified string is null
or
if the beginning of the specified string cannot be parsed; in the latter
case the thrown exception encapsulates the ParseException
raised
by the formatter as its cause.NumberFormat.parse(String)
public static byte parseByte(java.lang.String str) throws java.lang.NumberFormatException
byte
-number using the current default locale.parseNumber(str).byteValue()
.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
str
- A string.
java.lang.NumberFormatException
- If the specified string is null
or
if the beginning of the specified string cannot be parsed; in the latter
case the thrown exception encapsulates the ParseException
raised
by the formatter as its cause.NumberFormat.parse(String)
public static short parseShort(java.lang.String str) throws java.lang.NumberFormatException
short
-number using the current default locale.parseNumber(str).shortValue()
.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
str
- A string.
java.lang.NumberFormatException
- If the specified string is null
or
if the beginning of the specified string cannot be parsed; in the latter
case the thrown exception encapsulates the ParseException
raised
by the formatter as its cause.NumberFormat.parse(String)
public static int parseInt(java.lang.String str) throws java.lang.NumberFormatException
int
-number using the current default locale.parseNumber(str).intValue()
.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
str
- A string.
java.lang.NumberFormatException
- If the specified string is null
or
if the beginning of the specified string cannot be parsed; in the latter
case the thrown exception encapsulates the ParseException
raised
by the formatter as its cause.NumberFormat.parse(String)
public static long parseLong(java.lang.String str) throws java.lang.NumberFormatException
long
-number using the current default locale.parseNumber(str).longValue()
.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
str
- A string.
java.lang.NumberFormatException
- If the specified string is null
or
if the beginning of the specified string cannot be parsed; in the latter
case the thrown exception encapsulates the ParseException
raised
by the formatter as its cause.NumberFormat.parse(String)
public static float parseFloat(java.lang.String str) throws java.lang.NumberFormatException
float
-number using the current default locale.parseNumber(str).floatValue()
.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
str
- A string.
java.lang.NumberFormatException
- If the specified string is null
or
if the beginning of the specified string cannot be parsed; in the latter
case the thrown exception encapsulates the ParseException
raised
by the formatter as its cause.NumberFormat.parse(String)
public static double parseDouble(java.lang.String str) throws java.lang.NumberFormatException
double
-number using the current default locale.parseNumber(str).doubleValue()
.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
str
- A string.
java.lang.NumberFormatException
- If the specified string is null
or
if the beginning of the specified string cannot be parsed; in the latter
case the thrown exception encapsulates the ParseException
raised
by the formatter as its cause.NumberFormat.parse(String)
public static java.lang.String toString(byte val)
byte
-value to a String
using the current default locale.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
val
- A value to be formatted as a string.
public static java.lang.String toString(short val)
short
-value to a String
using the current default locale.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
val
- A value to be formatted as a string.
public static java.lang.String toString(int val)
int
-value to a String
using the current default locale.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
val
- A value to be formatted as a string.
public static java.lang.String toString(long val)
long
-value to a String
using the current default locale.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
val
- A value to be formatted as a string.
public static java.lang.String toString(float val)
float
-value to a String
using the current default locale.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
val
- A value to be formatted as a string.
public static java.lang.String toString(double val)
double
-value to a String
using the current default locale.parseXXXX(String)
or
toString(xxxx)
is called for the first time. The same
locale is then always reused, even if the default system locale is
changed. In order to enforce the creation of a new formatter, use
the method enforceNumberFormatterReset()
.
val
- A value to be formatted as a string.
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |