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)
This commit is contained in:
parent
7d51bc7834
commit
07f964813c
@ -13,8 +13,8 @@ public final class NumberConversions {
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = Integer.valueOf((String) object);
|
result = Integer.parseInt(object.toString());
|
||||||
} catch (Throwable ex) {}
|
} catch (NumberFormatException ex) {}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -27,8 +27,8 @@ public final class NumberConversions {
|
|||||||
float result = 0;
|
float result = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = Float.valueOf((String) object);
|
result = Float.parseFloat(object.toString());
|
||||||
} catch (Throwable ex) {}
|
} catch (NumberFormatException ex) {}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -41,8 +41,8 @@ public final class NumberConversions {
|
|||||||
double result = 0;
|
double result = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = Double.valueOf((String) object);
|
result = Double.parseDouble(object.toString());
|
||||||
} catch (Throwable ex) {}
|
} catch (NumberFormatException ex) {}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -55,8 +55,8 @@ public final class NumberConversions {
|
|||||||
long result = 0;
|
long result = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = Long.valueOf((String) object);
|
result = Long.parseLong(object.toString());
|
||||||
} catch (Throwable ex) {}
|
} catch (NumberFormatException ex) {}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -69,8 +69,8 @@ public final class NumberConversions {
|
|||||||
short result = 0;
|
short result = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = Short.valueOf((String) object);
|
result = Short.parseShort(object.toString());
|
||||||
} catch (Throwable ex) {}
|
} catch (NumberFormatException ex) {}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -83,8 +83,8 @@ public final class NumberConversions {
|
|||||||
byte result = 0;
|
byte result = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = Byte.valueOf((String) object);
|
result = Byte.parseByte(object.toString());
|
||||||
} catch (Throwable ex) {}
|
} catch (NumberFormatException ex) {}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user