Package org.pipservices3.commons.convert
Class LongConverter
java.lang.Object
org.pipservices3.commons.convert.LongConverter
Converts arbitrary values into longs.
Converts using extended conversion rules:
- Strings are converted to floats, then to longs
- DateTime: total number of milliseconds since unix epoсh
- Boolean: 1 for true and 0 for false
### Example ###
long value1 = LongConverter.toNullableLong("ABC"); // Result: null
long value2 = LongConverter.toNullableLong("123.456"); // Result: 123
long value3 = LongConverter.toNullableLong(true); // Result: 1
long value4 = LongConverter.toNullableLong(new Date()); // Result: current milliseconds
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
Converts value into long or returns 0 when conversion is not possible.static long
toLongWithDefault
(Object value, long defaultValue) Converts value into integer or returns default when conversion is not possible.static Long
toNullableLong
(Object value) Converts value into long or returns null when conversion is not possible.
-
Constructor Details
-
LongConverter
public LongConverter()
-
-
Method Details
-
toNullableLong
Converts value into long or returns null when conversion is not possible.- Parameters:
value
- the value to convert.- Returns:
- long value or null when conversion is not supported.
-
toLong
Converts value into long or returns 0 when conversion is not possible.- Parameters:
value
- the value to convert.- Returns:
- long value or 0 when conversion is not supported.
- See Also:
-
toLongWithDefault
Converts value into integer or returns default when conversion is not possible.- Parameters:
value
- the value to convert.defaultValue
- the default value.- Returns:
- long value or default when conversion is not supported
- See Also:
-