Class SafeKit
java.lang.Object
com.iohao.net.common.kit.SafeKit
Null-safe value retrieval utilities. Guarantees non-null return values by providing defaults.
- Author:
- 渔民小镇
- date:
- 2021-12-20
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleangetBoolean(Boolean value) Return the boolean value, orfalseifvalueis null.static booleangetBoolean(Boolean value, boolean defaultValue) Return the boolean value, ordefaultValueifvalueis null.static intReturn the int value, or 0 ifvalueis null.static intReturn the int value, ordefaultValueifvalueis null.static intParse the string as an int, or returndefaultValueon failure.static longReturn the long value, or 0 ifvalueis null.static longReturn the long value, ordefaultValueifvalueis null.static longParse the string as a long, or returndefaultValueon failure.static StringReturn the string value, ordefaultValueif it is null or empty.static intReturn the size of the list, or 0 if the list is null.
-
Method Details
-
getInt
Return the int value, or 0 ifvalueis null.- Parameters:
value- the nullable Integer- Returns:
- the unboxed int, or 0
-
getInt
Return the int value, ordefaultValueifvalueis null.- Parameters:
value- the nullable IntegerdefaultValue- the fallback value- Returns:
- the unboxed int, or
defaultValue
-
getInt
Parse the string as an int, or returndefaultValueon failure.- Parameters:
value- the string to parsedefaultValue- the fallback value- Returns:
- the parsed int, or
defaultValueif parsing fails
-
getLong
Return the long value, or 0 ifvalueis null.- Parameters:
value- the nullable Long- Returns:
- the unboxed long, or 0
-
getLong
Return the long value, ordefaultValueifvalueis null.- Parameters:
value- the nullable LongdefaultValue- the fallback value- Returns:
- the unboxed long, or
defaultValue
-
getLong
Parse the string as a long, or returndefaultValueon failure.- Parameters:
value- the string to parsedefaultValue- the fallback value- Returns:
- the parsed long, or
defaultValueif parsing fails
-
getBoolean
Return the boolean value, orfalseifvalueis null.- Parameters:
value- the nullable Boolean- Returns:
- the unboxed boolean, or
false
-
getBoolean
Return the boolean value, ordefaultValueifvalueis null.- Parameters:
value- the nullable BooleandefaultValue- the fallback value- Returns:
- the unboxed boolean, or
defaultValue
-
getString
-
size
Return the size of the list, or 0 if the list is null.- Parameters:
list- the nullable list- Returns:
- the list size, or 0
-