@Test public void testConvertToCapacityOnDefaultValue() { final Object[][] testParameters = new Object[][] {{"1k", 0L, 1000L}, {"1m", 1L, 1000000L}, {"1g", 2L, 1000000000L}, {"12K", 0L, 12000L}, {"34M", 1L, 34000000L}, {"56G", 2L, 56000000000L}}; assertEquals(0L, ParsingUtils.convertToCapacity(null, 0L)); assertEquals(1L, ParsingUtils.convertToCapacity(null, 1L)); for (final Object[] testParameter : testParameters) { long expected = (Long) testParameter[2]; String str = (String) testParameter[0]; long defaultValue = (Long) testParameter[1]; assertEquals(expected, ParsingUtils.convertToCapacity(str, defaultValue)); } }
public static long convertToCapacity( final String str, final long defaultValue) { if (null == str) { return defaultValue; } String safe = str.trim(); char unit = safe.charAt(safe.length() - 1); String valuePart = safe.substring(0, safe.length() - 1); long value = Long.parseLong(valuePart); if ('k' == toLowerCase(unit)) { return 1000 * value; } else if ('m' == toLowerCase(unit)) { return 1000000 * value; } else if ('g' == toLowerCase(unit)) { return 1000000000 * value; } return value; }
ParsingUtils { public static long convertToCapacity( final String str, final long defaultValue) { if (null == str) { return defaultValue; } String safe = str.trim(); char unit = safe.charAt(safe.length() - 1); String valuePart = safe.substring(0, safe.length() - 1); long value = Long.parseLong(valuePart); if ('k' == toLowerCase(unit)) { return 1000 * value; } else if ('m' == toLowerCase(unit)) { return 1000000 * value; } else if ('g' == toLowerCase(unit)) { return 1000000000 * value; } return value; } }
ParsingUtils { public static long convertToCapacity( final String str, final long defaultValue) { if (null == str) { return defaultValue; } String safe = str.trim(); char unit = safe.charAt(safe.length() - 1); String valuePart = safe.substring(0, safe.length() - 1); long value = Long.parseLong(valuePart); if ('k' == toLowerCase(unit)) { return 1000 * value; } else if ('m' == toLowerCase(unit)) { return 1000000 * value; } else if ('g' == toLowerCase(unit)) { return 1000000000 * value; } return value; }  }
ParsingUtils { public static long convertToCapacity( final String str, final long defaultValue) { if (null == str) { return defaultValue; } String safe = str.trim(); char unit = safe.charAt(safe.length() - 1); String valuePart = safe.substring(0, safe.length() - 1); long value = Long.parseLong(valuePart); if ('k' == toLowerCase(unit)) { return 1000 * value; } else if ('m' == toLowerCase(unit)) { return 1000000 * value; } else if ('g' == toLowerCase(unit)) { return 1000000000 * value; } return value; }  static boolean convertToBoolean(final String str, final boolean defaultValueIsTrue); static boolean convertToBoolean(final String val); static int convertToInt(final String val); static int convertToInt(final String val, final int defaultValue); static long convertToLong(final String val); static long convertToLong(final String val, final int defaultValue); static long convertToLong(final String val, final long defaultValue); static double convertToDouble(final String val); static double convertToDouble(final String val, final double defaultValue); static long convertToCapacity(
      final String str,
      final long defaultValue); static long convertToTime(final String val); static long parse(
      final String val,
      final TimeUnit unit); }
ParsingUtils { public static long convertToCapacity( final String str, final long defaultValue) { if (null == str) { return defaultValue; } String safe = str.trim(); char unit = safe.charAt(safe.length() - 1); String valuePart = safe.substring(0, safe.length() - 1); long value = Long.parseLong(valuePart); if ('k' == toLowerCase(unit)) { return 1000 * value; } else if ('m' == toLowerCase(unit)) { return 1000000 * value; } else if ('g' == toLowerCase(unit)) { return 1000000000 * value; } return value; }  static boolean convertToBoolean(final String str, final boolean defaultValueIsTrue); static boolean convertToBoolean(final String val); static int convertToInt(final String val); static int convertToInt(final String val, final int defaultValue); static long convertToLong(final String val); static long convertToLong(final String val, final int defaultValue); static long convertToLong(final String val, final long defaultValue); static double convertToDouble(final String val); static double convertToDouble(final String val, final double defaultValue); static long convertToCapacity(
      final String str,
      final long defaultValue); static long convertToTime(final String val); static long parse(
      final String val,
      final TimeUnit unit); static final List<ScaleUnit> INTERVALS; }