Class LongConverter

java.lang.Object
org.pipservices3.commons.convert.LongConverter

public class LongConverter extends Object
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 Details

    • LongConverter

      public LongConverter()
  • Method Details

    • toNullableLong

      public static Long toNullableLong(Object value)
      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

      public static long toLong(Object value)
      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

      public static long toLongWithDefault(Object value, long defaultValue)
      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: