添加 OptionalInt、OptionalLong、OptionalDouble 转包装类实例的方法。

feature/net-util
ZhouXY108 2023-06-27 01:32:48 +08:00
parent 3a46e2e60c
commit 759ad5fcbe
1 changed files with 15 additions and 0 deletions

View File

@ -134,6 +134,21 @@ public class OptionalUtil {
return optionalObj.orElse(null); return optionalObj.orElse(null);
} }
@Beta
public static Integer toInteger(OptionalInt optionalObj) {
return optionalObj.isPresent() ? optionalObj.getAsInt() : null;
}
@Beta
public static Long toLong(OptionalLong optionalObj) {
return optionalObj.isPresent() ? optionalObj.getAsLong() : null;
}
@Beta
public static Double toDouble(OptionalDouble optionalObj) {
return optionalObj.isPresent() ? optionalObj.getAsDouble() : null;
}
private OptionalUtil() { private OptionalUtil() {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }