public class ParseUtils extends Object
The ParseUtils
class provides parsing methods for various types.
Modifier and Type | Method and Description |
---|---|
static Object |
castTo(Object value,
Class type)
Checks whether
Object value is a type of
Class type . |
static String |
format(double d)
Formats the
double d with the actual language
setting and returns it as String . |
static String |
format(double d,
String pattern)
Formates the number
l to a String with the help
of the format . |
static String |
format(long l)
Formats the
long l with the actual language
setting and returns it as String . |
static String |
format(long l,
String pattern)
Formates the number
l to a String with the help
of the format . |
static String |
formatAsCurrency(double d)
Formates the
double d as currency with the
actual language setting and returns it as String . |
static String |
formatAsCurrency(long l)
Formates the
long l as currency with the actual
language setting and returns it as String . |
static boolean |
isAlphaNumeric(String value,
int min,
int max)
Checks if the variable
String is not a number and is it has
a length between minLen and maxLen . |
static boolean |
isBoolean(Object value)
Checks if the variable
value is type of boolean
. |
static boolean |
isDecimal(Object value)
Checks if the
Object value is a decimal or can
parsed to. |
static boolean |
isEmail(String value)
Checks if the variable
String is a valid Email address. |
static boolean |
isInteger(Object value)
Checks if the
Object value is an integer. |
static boolean |
isLong(Object value)
Checks if the
Object value is an integer. |
static boolean |
isNumeric(Object value,
double min,
double max)
* Checks if the variable
value is a value between
min and max . |
static boolean |
isNumeric(Object value,
long min,
long max)
Checks if the variable
value is a value between
min and max . |
static boolean |
isType(Object value,
Class type)
Checks whether
Object value is a type of
Class type . |
static boolean |
isType(Object value,
String className)
Checks whether
Object value is a type of
Class className . |
static Number |
parse(Object value)
Parse the variable
value to an Number . |
static Number |
parse(Object value,
String pattern)
Parse the variable
value to an Number with the
help of of the format . |
static boolean |
parseBoolean(Object value)
Deprecated.
|
static byte |
parseByte(Object value)
Deprecated.
|
static byte |
parseByte(Object value,
String pattern)
Parse the variable
value to a byte with the
help of of the format . |
static XdevDate |
parseDate(Object value)
Deprecated.
|
static XdevDate |
parseDate(Object value,
String pattern)
Ckecks whether
Object value is a
XdevDate . |
static double |
parseDouble(Object value)
Deprecated.
|
static double |
parseDouble(Object value,
String pattern)
Parse the variable
value to a double with the
help of of the format . |
static double |
parseDoubleAsCurrency(Object value)
Parse the variable
value to an double . |
static double |
parseDoubleAsCurrency(Object value,
String pattern)
Parse the variable
value to a double with the
help of of the format . |
static XdevFile |
parseFile(Object value)
Deprecated.
|
static float |
parseFloat(Object value)
Deprecated.
|
static float |
parseFloat(Object value,
String pattern)
Parse the variable
value to a float with the
help of of the format . |
static XdevHashtable |
parseHashtable(Object value)
Deprecated.
|
static XdevImage |
parseImage(Object value)
Deprecated.
|
static int |
parseInt(Object value)
Deprecated.
|
static int |
parseInt(Object value,
String pattern)
Parse the variable
value to a int with the help
of of the format . |
static XdevList |
parseList(Object value)
Deprecated.
|
static long |
parseLong(Object value)
Deprecated.
|
static long |
parseLong(Object value,
String pattern)
Parse the variable
value to a long with the
help of of the format . |
static short |
parseShort(Object value)
Deprecated.
|
static short |
parseShort(Object value,
String pattern)
Parse the variable
value to a short with the
help of of the format . |
static Date |
parseUtilDate(Object value)
Deprecated.
|
static String |
toBinaryString(int i)
Parse the variable
i to BinaryString . |
static String |
toBinaryString(long l)
Parse the variable
l to BinaryString . |
static String |
toHexString(int i)
Parse the variable
i to HexString . |
static String |
toHexString(long l)
Parse the variable
l to HexString . |
static String |
toOctalString(int i)
Parse the variable
i to OctalString . |
static String |
toOctalString(long l)
Parse the variable
l to OctalString . |
@Deprecated public static byte parseByte(Object value) throws NumberFormatException
ConversionUtils.tobyte(Object)
value
to a byte
.
ParseUtils.parseByte(7895); returns -44 ParseUtils.parseByte(-64568); returns -56
value
- the value which will be parsed to byte
byte
parsed from the value
, if
possible.NumberFormatException
- if value could not be parsed to byte
parseByte(Object, String)
,
parseDouble(Object)
public static byte parseByte(Object value, String pattern) throws ParseException
value
to a byte
with the
help of of the format
. The format of the current language
setting will be considered.
ParseUtils.parseByte(589, "XDEV"); returns 77 ParseUtils.parseByte(-3695, "XDEV"); returns -111
value
- the value which will be parsed to byte
pattern
- the format with which the value
should be parsedbyte
parsed from the value
, if
possible.ParseException
- if value could not be parsed to byte
parse(Object, String)
@Deprecated public static short parseShort(Object value) throws NumberFormatException
ConversionUtils.toshort(Object)
value
to a short
.The format
of the current language setting will be considered.
ExamplesParseUtils.parseShort(2561); returns 2561 ParseUtils.parseShort(-25615); returns -25615
value
- the value which will be parsed to short
short
parsed from the value
, if
possible.NumberFormatException
- if value could not be parsed to short
parseShort(Object, String)
,
parseDouble(Object)
public static short parseShort(Object value, String pattern) throws ParseException
value
to a short
with the
help of of the format
. The format of the current language
setting will be considered.
ExamplesParseUtils.parseShort("0032767", "##0000"); returns 32767 ParseUtils.parseShort("235.123", "###"); returns 235
value
- the value which will be parsed to short
pattern
- the format with which the value
should be parsedshort
parsed from the value
, if
possible.ParseException
- if value could not be parsed to short
parse(Object, String)
@Deprecated public static int parseInt(Object value) throws NumberFormatException
ConversionUtils.toint(Object)
value
to an int
. The format
of the current language setting will be considered.
ExamplesParseUtils.parseInt(56); returns 56 ParseUtils.parseInt(-268); returns -268
value
- the value which will be parsed to int
int
parsed from the value
, if
possible.
Warning: The value has to be between
-2.147.483.648 and 2.147.483.647. Beyond that use
parseDouble(Object)
.
NumberFormatException
- if value could not be parsed to int
parseInt(Object, String)
,
parseDouble(Object)
,
parseDouble(Object, String)
,
isInteger(Object)
,
parseLong(Object)
,
parseLong(Object, String)
public static int parseInt(Object value, String pattern) throws ParseException
value
to a int
with the help
of of the format
. The format of the current language setting
will be considered.
Examples
ParseUtils.parseInt("12.356", "##"); returns 12 ParseUtils.parseInt("12", "##"); returns 12
value
- the value which will be parsed to int
pattern
- the format with which the value
should be parsedint
parsed from the value
, if
possible.
Warning: The value has to be between
-2.147.483.648 and 2.147.483.647. Beyond that use
parseDouble(Object, String)
.
ParseException
- if value could not be parsed to int
parse(Object, String)
@Deprecated public static long parseLong(Object value) throws NumberFormatException
ConversionUtils.tolong(Object)
value
to an long
. The format
of the current language setting will be considered.
Examples
ParseUtils.parseLong(223545854); returns 223545854 ParseUtils.parseLong(-545845854); returns -545845854
value
- the value which will be parsed to long
long
parsed from the value
, if
possible.NumberFormatException
- if value could not be parsed to long
parseInt(Object)
,
parseDouble(Object)
,
parseDouble(Object)
,
isLong(Object)
,
parseInt(Object, String)
,
parseLong(Object, String)
,
parseDouble(Object, String)
public static long parseLong(Object value, String pattern) throws ParseException
value
to a long
with the
help of of the format
. The format of the current language
setting will be considered.
ExamplesParseUtils.parseLong("546545,64121.385", ",######"); returns 546545 ParseUtils.parseLong("546872313", "########"); returns 546872313
value
- the value which will be parsed to long
pattern
- the format with which the value
should be parsedlong
parsed from the value
, if
possible.ParseException
- if value could not be parsed to long
parse(Object, String)
@Deprecated public static float parseFloat(Object value) throws NumberFormatException
ConversionUtils.tofloat(Object)
value
to an float
. The
format of the current language setting will be considered.
ExamplesParseUtils.parseFloat(545687453); returns 545687453 ParseUtils.parseFloat(-564868745); returns -564868745
value
- the value which will be parsed to long
float
parsed from the value
, if
possible.NumberFormatException
- if value could not be parsed to float
parseInt(Object)
,
parseDouble(Object)
,
parseDouble(Object)
,
parseInt(Object, String)
,
parseLong(Object, String)
,
parseDouble(Object, String)
public static float parseFloat(Object value, String pattern) throws ParseException
value
to a float
with the
help of of the format
. The format of the current language
setting will be considered.
ExamplesParseUtils.parseFloat("00003456", "000000"); returns 3456 ParseUtils.parseFloat("0000014", "000000"); returns 14
value
- the value which will be parsed to float
pattern
- the format with which the value
should be parsedfloat
parsed from the value
, if
possible.ParseException
- if value could not be parsed to float
parse(Object, String)
@Deprecated public static double parseDouble(Object value) throws NumberFormatException
ConversionUtils.todouble(Object)
value
to an double
. The
format of the current language setting will be considered.ParseUtils.parseDouble(5.20); returns 5.20 ParseUtils.parseDouble(-175.28); returns -175.28
value
- the value which will be parsed to double
double
parsed from the value
, if
possible.NumberFormatException
- if value could not be parsed to double
parseInt(Object, String)
,
parseDouble(Object)
,
parseDouble(Object, String)
,
isDecimal(Object)
,
parseLong(Object)
,
parseLong(Object, String)
public static double parseDouble(Object value, String pattern) throws ParseException
value
to a double
with the
help of of the format
. The format of the current language
setting will be considered.
ExamplesParseUtils.parseDouble(",35", ".00"); returns 0.35 ParseUtils.parseDouble("12,340000","#.00"); returns 12.34
value
- the value which will be parsed to double
pattern
- the format with which the value
should be parseddouble
parsed from the value
, if
possible.ParseException
- if value could not be parsed to double
parse(Object, String)
public static double parseDoubleAsCurrency(Object value)
value
to an double
.
Additional characters behind the value
will be
considered.ExampleParseUtils.parseDouble(2587.6998); returns 2587.6998 ParseUtils.parseDouble(-5697.6237); returns -5697.6237HintCan be used as inverse function toHintformatAsCurrency(double)
If you don't need the extra function to accepted additional characters behind the number you should useparseDouble(Object)
instead. Because fewer mistakes could be slipped in. AndparseDouble(Object)
has more performance because fewer cases has to be checked.
value
- the value which will be parsed to double
double
parsed from the value
, if
possible.formatAsCurrency(double)
,
parseDoubleAsCurrency(Object, String)
,
parseDouble(Object)
,
parseDouble(Object, String)
public static double parseDoubleAsCurrency(Object value, String pattern) throws ParseException
value
to a double
with the
help of of the format
. The format of the current language
setting will be considered.
Example
ParseUtils.parseDoubleAsCurrency("12,350000", "#.000000"); returns 12.35 ParseUtils.parseDoubleAsCurrency("12.345,679", ",###"); returns 12345.679
value
- the value which will be parsed to double
pattern
- the format with which the value
should be parseddouble
parsed from the value
, if
possible.ParseException
- if value could not be parsed to double
parse(Object, String)
,
parseDouble(Object, String)
public static Number parse(Object value) throws ParseException
value
to an Number
.
ExamplesParseUtils.parse(78); return 78 ParseUtils.parse(-256); return -256
value
- the value which will be parsed to Number
Number
parsed from the value
, if
possible.ParseException
- if value could not be parsed to Number
public static Number parse(Object value, String pattern) throws ParseException
value
to an Number
with the
help of of the format
. The format of the current language
setting will be considered.
ExamplesParseUtils.parse("00000014", "00000000"); returns 14 ParseUtils.parse("0014000", "0000000"); returns 14000The following Symbols will be supported:
Symbol
Meaning
0
Represent a digit - is the position empty, will be shown a zero.
#
Represent a digit - is the position empty it stays empty, with that leading zero and unnecessary zeros after the decimal point will be avoided.
.
Decimal separator. Separates external and internal decimal places.
,
Groups the digits (a group is as big as the distance from "," to ".").
;
Delimiter. On the left of it is the pattern for the positive, on the right the format for the negative numbers
-
The standardsymbol for the negativeprefix
%
The number will be multiply with 100 and declared as a percent value
%%
The same as %, only with per mill.
¤ (¤)
National currency sign (&eur; for Germany)
¤¤ (¤¤)
Internationale currency sign (EUR for Germany)
X
All other symbols X can be used as normal.
'
to mask special symbols in prefix or suffix
Format
Intake Number
Result
0000
12
0012
0000
12,5
0012
0000
1234567
1234567
##
12
12
##
12.3456
12
##
123456
123456
.00
12.3456
12,35
.00
.3456
,35
0.00
.789
0,79
#.000000
12.34
12,340000
,###
12345678.901
12.345.679
#.#;(#.#)
12345678.901
12345678,9
#.#;(#.#)
-12345678.901
(12345678,9)
,###.## ¤
12345.6789
12.345,68 i
,#00.00 ¤¤
-12345678.9
-12.345.678,90 EUR
,#00.00 ¤¤
0.1
00,10 EUR
value
- the value which will be parsed to Number
pattern
- the format with which the value
should be parsedNumber
parsed from the value
, if
possible.ParseException
- if value
could not be parsed to
Number
parse(Object)
,
parseInt(Object)
,
parseInt(Object, String)
,
isDecimal(Object)
@Deprecated public static boolean parseBoolean(Object value)
ConversionUtils.toboolean(Object)
value
to boolean
.ExampleReturnstrue
for the following cases:
- Boolean true
- Number != 0
String
"true" (not case sensitive)
All others cases !=null
returnfalse
ParseUtils.parseBoolean(232); return true ParseUtils.parseBoolean(-232); return true ParseUtils.parseBoolean("hello"); return false
Warning: Instead of parseInt(Object)
and parseDouble(Object)
this methode will never throw
a NumberFormatException
value
- the value which will be parsed to boolean
.true
if the value
is a
boolean
, else false
isBoolean(Object)
,
parseInt(Object)
,
parseDouble(Object)
@Deprecated public static XdevDate parseDate(Object value)
ConversionUtils.toXdevDate(Object)
Object
value
is a
XdevDate
. If yes it returns a XdevDate
else
null
.value
- Object
which will be parsed to
XdevDate
.XdevDate
if value
is a
XdevDate
. Else null
.parseDate(Object, String)
,
parseUtilDate(Object)
public static XdevDate parseDate(Object value, String pattern)
Object
value
is a
XdevDate
. If yes it returns a XdevDate
else
null
.
ExamplesParseUtils.parseDate("10.01.2010", "dd.MM.yyyy"); returns 10.01.2010HintFor valid patterns seeSimpleDateFormat
value
- Object
which will be parsed to
XdevDate
.pattern
- the format with which the value
should be parsed.XdevDate
if value
is a
XdevDate
. Else null
.parseDate(Object)
,
parseUtilDate(Object)
@Deprecated public static Date parseUtilDate(Object value)
ConversionUtils.toDate(Object)
Object
value
is a
Date
. If yes it returns a Date
else
null
.value
- Object
which will be parsed to Date
.XdevDate
if value
is a
Date
. Else null
.parseDate(Object, String)
,
parseDate(Object)
@Deprecated public static XdevList parseList(Object value)
ConversionUtils.toXdevList(Object)
Object
value
is a
XdevList
. If yes it returns a XdevList
else
null
.value
- Object
which will be parsed to
XdevList
.XdevDate
if value
is a
XdevList
. Else null
.@Deprecated public static XdevHashtable parseHashtable(Object value)
ConversionUtils.toXdevHashtable(Object)
Object
value
is a
XdevHashtable
. If yes it returns a
XdevHashtable
else null
.value
- Object
which will be parsed to
XdevHashtable
.XdevHashtable
if value
is a
XdevHashtable
. Else null
.@Deprecated public static XdevFile parseFile(Object value)
ConversionUtils.toXdevFile(Object)
Object
value
is a
XdevFile
. If yes it returns a XdevFile
else
null
.value
- Object
which will be parsed to
XdevFile
.XdevFile
if value
is a
XdevFile
. Else null
.@Deprecated public static XdevImage parseImage(Object value)
ConversionUtils.toXdevImage(Object)
Object
value
is a
XdevImage
. If yes it returns a XdevImage
else
null
.value
- Object
which will be parsed to
XdevImage
.XdevImage
if value
is a
XdevImage
. Else null
.public static String toHexString(int i)
i
to HexString
. ExamplesParseUtils.toHexString(25); returns 19 ParseUtils.toHexString(-62); returns ffffffc2
i
- int
which will be parsed to
HexString
i
Integer.toHexString(int)
public static String toHexString(long l)
l
to HexString
.
ExamplesParseUtils.toHexString(-25897); returns ffff9ad7 ParseUtils.toHexString(2589); returns a1d
l
- long
which will be parsed to
HexString
l
Long.toHexString(long)
public static String toOctalString(int i)
i
to OctalString
.
ExamplesParseUtils.toOctalString(597632); returns 2217200 ParseUtils.toOctalString(-1025897); returns 37774054227
i
- int
which will be parsed to
OctalString
i
Integer.toOctalString(int)
public static String toOctalString(long l)
l
to OctalString
.
ExamplesParseUtils.toOctalString(1025856889); returns 7511252571 ParseUtils.toOctalString(-589789567); returns 33466103201
l
- long
which will be parsed to
OctalString
l
Long.toOctalString(long)
public static String toBinaryString(int i)
i
to BinaryString
.
ExamplesParseUtils.toBinaryString(-589789567); returns 11011100110110001000011010000001 ParseUtils.toBinaryString(897898967); returns 110101100001001101100111010111
i
- int
which will be parsed to
BinaryString
i
Integer.toBinaryString(int)
public static String toBinaryString(long l)
l
to BinaryString
.
ExamplesParseUtils.toBinaryString(897295967); returns 110101011110111010011001011111 ParseUtils.toBinaryString(-831878067); returns 11001110011010101000110001001101
l
- long
which will be parsed to
BinaryString
l
Long.toBinaryString(long)
public static boolean isNumeric(Object value, long min, long max)
value
is a value between
min
and max
. With the condition:
min
<= value
<= max
.
ExamplesParseUtils.isNumeric(489999995, 12000, 698777); returns false ParseUtils.isNumeric(5000, 5000, 5000); returns true
value
- the value which will be checkedmin
- the(inclusive)lower border for value
max
- the(inclusive)upper border for value
min
<= value
<=
max
isAlphaNumeric(String, int, int)
,
isNumeric(Object, double, double)
public static boolean isNumeric(Object value, double min, double max)
value
is a value between
min
and max
. With the condition:
min
<= value
<= max
.
ExamplesParseUtils.isNumeric(5600.80, 500.20, 4000.90); returns false ParseUtils.isNumeric(-5000.90, -489.25, -800.65); returns false ParseUtils.isNumeric(-5000.90, -5000.90, -5000.90); returns true
value
- the value which will be checkedmin
- the(inclusive)lower border for value
max
- the(inclusive)upper border for value
min
<= value
<=
max
isAlphaNumeric(String, int, int)
,
isNumeric(Object, long, long)
public static boolean isAlphaNumeric(String value, int min, int max)
String
is not a number and is it has
a length between minLen
and maxLen
.
If this applies it returns true
, else false
.
ExampleParseUtils.isAlphaNumeric("Hello10", 2, 30); returns true ParseUtils.isAlphaNumeric("Hello-15", -40, 30); returns true ParseUtils.isAlphaNumeric("Hello XDEV3", -40, -15); returns false
value
- the String
which length will be checkedmin
- the(inclusive)minimum length for value
max
- the(inclusive)maximum length for value
minLen
<= value.length
<=
maxLen
isNumeric(Object, double, double)
,
isNumeric(Object, long, long)
public static boolean isEmail(String value)
String
is a valid Email address.
ExampleHintParseUtils.isEmail("[email protected]"); returns true ParseUtils.isEmail(" "); returns false
It can only be checked whether the String has the right format for an email address, not whether this email address truely exists.
value
- the String
which format will be checkedisNumeric(Object, double, double)
,
isNumeric(Object, long, long)
public static String format(long l)
long
l
with the actual language
setting and returns it as String
.
ExampleParseUtils.format(894302256); returns 894.302.256 ParseUtils.format(-789602314); returns -789.602.314
The german standard setting for decimals is:
l
- the long
which will be formated.long
in format of the actual language setting.format(double)
,
format(long, String)
public static String format(long l, String pattern)
l
to a String
with the help
of the format
.
ExampleHintParseUtils.format(789302125, "Lange Zahl "); returns Lange Zahl 789302125 ParseUtils.format(-569780212, "Negative Zahl "); returns -Negative Zahl 569780212
for valid patterns see parse(Object, String)
l
- the long
which will be formated.pattern
- the String
with which l
will be
formated.l
formated with pattern pattern
.format(long)
,
format(double, String)
public static String format(double d)
double
d
with the actual language
setting and returns it as String
.
ExampleParseUtils.format(2000.3505); returns 2.000,35 ParseUtils.format(-23205.3589705); returns -23.205,359
The german standard setting for decimals is:
d
- the double
which will be formated.double
in format of the actual language setting.format(long)
,
format(double, String)
public static String format(double d, String pattern)
l
to a String
with the help
of the format
.
Example
ParseUtils.format(-7892.0365478, "Euro"); returns -Euro7892 ParseUtils.format(25897.6321, "hello"); returns hello25898
d
- the long
which will be formated.pattern
- the String
with which l
will be
formated.l
formated with pattern pattern
.format(long, String)
,
format(double)
public static String formatAsCurrency(long l)
long
l
as currency with the actual
language setting and returns it as String
.
ExampleHintParseUtils.formatAsCurrency(897565258); returns 897.565.258,00 € ParseUtils.formatAsCurrency(-45752378); returns -45.752.378,00 €
The german default setting for currency is:
l
- the long
which will be formated as currencylong
formated as currency with the actual
language setting.format(double)
,
format(long, String)
,
parseDouble(Object)
,
parseDouble(Object, String)
public static String formatAsCurrency(double d)
double
d
as currency with the
actual language setting and returns it as String
.
ExampleHintParseUtils.formatAsCurrency(78963.256); returns 78.963,26 € ParseUtils.formatAsCurrency(-458.256); returns -458,26 €
The german default setting for currency is:
d
- the double
which will be formated as currencydouble
formated as currency with the actual
language setting.format(double)
,
format(long, String)
,
parseDouble(Object)
,
parseDouble(Object, String)
public static Object castTo(Object value, Class type)
Object
value
is a type of
Class
type
. If yes it returns
value
else ClassCastException
.value
- Object
which type will be checkedtype
- Class
of which Object
will be
checked.value
if value
is type of
type
. Else ClassCastException
.isType(Object, String)
,
isType(Object, Class)
public static boolean isType(Object value, Class type)
Object
value
is a type of
Class
type
. If yes it returns true
else false
.value
- Object
which type will be checkedtype
- Class
of which Object
will be
checked.Object
is type of type
. Else
false
.isType(Object, String)
public static boolean isType(Object value, String className)
Object
value
is a type of
Class
className
. If yes it returns
true
else false
.
Example
ParseUtils.isType(65, "double"); returns false
value
- Object
which type will be checkedclassName
- className
of which Object
will be
checked.Object
is type of className
.
Else false
.isType(Object, Class)
public static boolean isInteger(Object value)
Object
value
is an integer. That
means whether value
can be parsed to an integer without
losing information.
ExampleParseUtils.isInteger(20); returns true ParseUtils.isInteger(null); returns false
The number range of Integer
is between -2.147.483.648 and 2.147.483.647 .
value
- the Object
value
which will be
checkedvalue
is an integer or can be parsed to
without losing informationisInteger(Object)
,
isDecimal(Object)
,
isBoolean(Object)
,
parseLong(Object)
,
parseLong(Object, String)
public static boolean isLong(Object value)
Object
value
is an integer. That
means whether value
can be parsed to an integer without
losing information.
Example ParseUtils.isLong(20875884855699l); returns true ParseUtils.isLong(null); returns false
The number range of long
is between -9.223.372.036.854.775.808 and 9.223.372.036.854.775.807 .
value
- the Object
value
which will be
checkedvalue
is an integer or can be parsed to
without losing informationisLong(Object)
,
isDecimal(Object)
,
isBoolean(Object)
,
parseLong(Object)
,
parseLong(Object, String)
public static boolean isDecimal(Object value)
Object
value
is a decimal or can
parsed to.
1. GeneralHintisDecimal("3.14") returns2. Integertrue
isDecimal("5") returns3. Zerotrue
.isDecimal("0") returns4. Exponent spelling 1true
.isDecimal("1E3") returns5. Exponent spelling 2true
. (1E3 = 1 * 103 = 1000)isDecimal(1E-3) returns6. Not a numbertrue
. (1E3 = 1 * 10-3 = 0,001)isDecimal("NaN") returns7. Minus infinitytrue
.isDecimal("Infinity") returns8. Minus infinitytrue
.isDecimal("-Infinity") returnstrue
.
The check wil be made with the regular expression: ^[a-zA-Z0-9._%-]+@[a-zA-ZÄÖÜäöü0-9._%-]+\\.[a-zA-Z]{2,4}$Hint
"NaN", "Infinity" and "-Infinity" are case sensitive. That means "NAN", "nan", "infinity", "INFINITY", etc can't be recognized. Also "Negative Infinity" or something like that can't be recognized. For the exponent notation can instead of "E" also "e" be used. Likewise, "5E09", "0E4" or "6.5E12" can be used too. Is not possible to use e.g. "E3" or "5E9.1"Hint
This methode has approximately the same performance asparseDouble(Object)
. That means ifObject
value
will be used as decimal, after this methode, it is convenient to write:
ParseUtils.isDecimal(200.05); returns true ParseUtils.isDecimal(null); returns false
With this the check will be made only once.
value
- the Object
value
which will be
checkedvalue
is a decimal or can be parsed to.isInteger(Object)
,
isNumeric(Object, double, double)
,
parseDouble(Object)
public static boolean isBoolean(Object value)
value
is type of boolean
.*simple ParseUtils.isBoolean(true
) ParseUtils.isBoolean(false
) Returnstrue
. other Value isBoolean("true") isBoolean(5) isBoolean("alles andere") Returnsfalse
. (also "true" isnt a Boolean, because the type is aString
)
Warning: While parseBoolean(Object)
trys to parse a given value to boolean
, checks this methode
not if a given value can be parsed to boolean
, but if a
given value is type of boolean
.
To check if a value (like the String
"true") can be
interprete as boolean
can be used the following Code:
ParseUtils.isBoolean(null); returns false
ParseUtils.isBoolean(150); returns false
value
- the value which will be checked if its is a
boolean
.true
if the value
is a
boolean
, else false
parseBoolean(Object)
,
isInteger(Object)
,
isDecimal(Object)
,
isLong(Object)
Copyright © 2003–2022 XDEV Software. All rights reserved.