28
28
import java .util .stream .Collectors ;
29
29
30
30
/**
31
- * @author Despical
31
+ * This class is a part of Despical's Commons library.
32
32
* <p>
33
33
* Created at 30.05.2020
34
34
*
35
- * This class is a part of Despical's Commons library.
35
+ * @author Despical
36
36
*/
37
37
@ ApiStatus .Internal
38
38
public class Utils {
@@ -48,11 +48,9 @@ private Utils() {
48
48
* @return the int represented by the string, or zero if conversion fails
49
49
*/
50
50
public static int getInt (String string ) {
51
- if (string == null ) return 0 ;
52
-
53
51
try {
54
52
return Integer .parseInt (string );
55
- } catch (NumberFormatException ignored ) {
53
+ } catch (NumberFormatException | NullPointerException ignored ) {
56
54
return 0 ;
57
55
}
58
56
}
@@ -65,11 +63,9 @@ public static int getInt(String string) {
65
63
* @return the double represented by the string, or zero if conversion fails
66
64
*/
67
65
public static double getDouble (String string ) {
68
- if (string == null ) return 0d ;
69
-
70
66
try {
71
67
return Double .parseDouble (string );
72
- } catch (NumberFormatException ignored ) {
68
+ } catch (NumberFormatException | NullPointerException ignored ) {
73
69
return 0d ;
74
70
}
75
71
}
@@ -82,11 +78,9 @@ public static double getDouble(String string) {
82
78
* @return the long represented by the string, or zero if conversion fails
83
79
*/
84
80
public static long getLong (String string ) {
85
- if (string == null ) return 0L ;
86
-
87
81
try {
88
82
return Long .parseLong (string );
89
- } catch (NumberFormatException ignored ) {
83
+ } catch (NumberFormatException | NullPointerException ignored ) {
90
84
return 0L ;
91
85
}
92
86
}
@@ -99,11 +93,9 @@ public static long getLong(String string) {
99
93
* @return the float represented by the string, or zero if conversion fails
100
94
*/
101
95
public static float getFloat (String string ) {
102
- if (string == null ) return 0F ;
103
-
104
96
try {
105
97
return Float .parseFloat (string );
106
- } catch (NumberFormatException ignored ) {
98
+ } catch (NumberFormatException | NullPointerException ignored ) {
107
99
return 0F ;
108
100
}
109
101
}
0 commit comments