mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-24 01:06:01 +01:00
Reduced excessive exception handling in NumberConversions. Addresses BUKKIT-825
This also allows, for instance, to parse complex numbers with imaginary part=0, if the according toString method omits zero components. This also saves some unboxing (Foo.valueOf returns a wrapper, while Foo.parseFoo returns a primitive) By: TomyLobo <tomylobo@nurfuerspam.de>
This commit is contained in:
parent
445baa7607
commit
4c1a926d66
1 changed files with 12 additions and 12 deletions
|
@ -13,8 +13,8 @@ public final class NumberConversions {
|
|||
int result = 0;
|
||||
|
||||
try {
|
||||
result = Integer.valueOf((String) object);
|
||||
} catch (Throwable ex) {}
|
||||
result = Integer.parseInt(object.toString());
|
||||
} catch (NumberFormatException ex) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ public final class NumberConversions {
|
|||
float result = 0;
|
||||
|
||||
try {
|
||||
result = Float.valueOf((String) object);
|
||||
} catch (Throwable ex) {}
|
||||
result = Float.parseFloat(object.toString());
|
||||
} catch (NumberFormatException ex) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ public final class NumberConversions {
|
|||
double result = 0;
|
||||
|
||||
try {
|
||||
result = Double.valueOf((String) object);
|
||||
} catch (Throwable ex) {}
|
||||
result = Double.parseDouble(object.toString());
|
||||
} catch (NumberFormatException ex) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ public final class NumberConversions {
|
|||
long result = 0;
|
||||
|
||||
try {
|
||||
result = Long.valueOf((String) object);
|
||||
} catch (Throwable ex) {}
|
||||
result = Long.parseLong(object.toString());
|
||||
} catch (NumberFormatException ex) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -69,8 +69,8 @@ public final class NumberConversions {
|
|||
short result = 0;
|
||||
|
||||
try {
|
||||
result = Short.valueOf((String) object);
|
||||
} catch (Throwable ex) {}
|
||||
result = Short.parseShort(object.toString());
|
||||
} catch (NumberFormatException ex) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ public final class NumberConversions {
|
|||
byte result = 0;
|
||||
|
||||
try {
|
||||
result = Byte.valueOf((String) object);
|
||||
} catch (Throwable ex) {}
|
||||
result = Byte.parseByte(object.toString());
|
||||
} catch (NumberFormatException ex) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue