class 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;
  }

}