@@ -70,6 +70,66 @@ public static Optional<Long> toLong(@Nullable Object object) {
70
70
return object == null ? Optional .empty () : MiscUtility .handleException (() -> Long .parseLong (object .toString ()), NumberFormatException .class );
71
71
}
72
72
73
+ /**
74
+ * Converts an {@link Object} to a {@link Float}
75
+ *
76
+ * @param object the {@link Object} to convert
77
+ *
78
+ * @return the {@link Float} or {@link Optional#empty()}
79
+ */
80
+ @ NotNull
81
+ public static Optional <Float > toFloat (@ Nullable Object object ) {
82
+ return object == null ? Optional .empty () : MiscUtility .handleException (() -> Float .parseFloat (object .toString ()), NumberFormatException .class );
83
+ }
84
+
85
+ /**
86
+ * Converts an {@link Object} to a {@link Short}
87
+ *
88
+ * @param object the {@link Object} to convert
89
+ *
90
+ * @return the {@link Short} or {@link Optional#empty()}
91
+ */
92
+ @ NotNull
93
+ public static Optional <Short > toShort (@ Nullable Object object ) {
94
+ return object == null ? Optional .empty () : MiscUtility .handleException (() -> Short .parseShort (object .toString ()), NumberFormatException .class );
95
+ }
96
+
97
+ /**
98
+ * Converts an {@link Object} to a {@link Byte}
99
+ *
100
+ * @param object the {@link Object} to convert
101
+ *
102
+ * @return the {@link Byte} or {@link Optional#empty()}
103
+ */
104
+ @ NotNull
105
+ public static Optional <Byte > toByte (@ Nullable Object object ) {
106
+ return object == null ? Optional .empty () : MiscUtility .handleException (() -> Byte .parseByte (object .toString ()), NumberFormatException .class );
107
+ }
108
+
109
+ /**
110
+ * Converts an {@link Object} to a {@link BigInteger}
111
+ *
112
+ * @param object the {@link Object} to convert
113
+ *
114
+ * @return the {@link BigInteger} or {@link Optional#empty()}
115
+ */
116
+ @ NotNull
117
+ public static Optional <BigInteger > toBigInteger (@ Nullable Object object ) {
118
+ return object == null ? Optional .empty () : MiscUtility .handleException (() -> new BigInteger (object .toString ()), NumberFormatException .class );
119
+ }
120
+
121
+ /**
122
+ * Converts an {@link Object} to a {@link BigDecimal}
123
+ *
124
+ * @param object the {@link Object} to convert
125
+ *
126
+ * @return the {@link BigDecimal} or {@link Optional#empty()}
127
+ */
128
+ @ NotNull
129
+ public static Optional <BigDecimal > toBigDecimal (@ Nullable Object object ) {
130
+ return object == null ? Optional .empty () : MiscUtility .handleException (() -> new BigDecimal (object .toString ()), NumberFormatException .class );
131
+ }
132
+
73
133
/**
74
134
* Converts an {@link Object} to a {@link UUID}
75
135
*
0 commit comments