@Test void parseAsByteCountShouldThrowOnMissingAmount() { assertThatThrownBy(() -> SizeFormat.parseAsByteCount("KiB")) .isInstanceOf(NumberFormatException.class); }
public static long parseAsByteCount(String bytesWithUnit) { UnitParser.ParsingResult parsingResult = UnitParser.parse(bytesWithUnit); Unit unit = parsingResult.getUnit() .map(rawValue -> Unit.of(rawValue) .orElseThrow(() -> new IllegalArgumentException("Unknown unit " + rawValue))) .orElse(Unit.Byte); return unit.toByteCount(parsingResult.getNumber()); }
SizeFormat { public static long parseAsByteCount(String bytesWithUnit) { UnitParser.ParsingResult parsingResult = UnitParser.parse(bytesWithUnit); Unit unit = parsingResult.getUnit() .map(rawValue -> Unit.of(rawValue) .orElseThrow(() -> new IllegalArgumentException("Unknown unit " + rawValue))) .orElse(Unit.Byte); return unit.toByteCount(parsingResult.getNumber()); } }
SizeFormat { public static long parseAsByteCount(String bytesWithUnit) { UnitParser.ParsingResult parsingResult = UnitParser.parse(bytesWithUnit); Unit unit = parsingResult.getUnit() .map(rawValue -> Unit.of(rawValue) .orElseThrow(() -> new IllegalArgumentException("Unknown unit " + rawValue))) .orElse(Unit.Byte); return unit.toByteCount(parsingResult.getNumber()); }  }
SizeFormat { public static long parseAsByteCount(String bytesWithUnit) { UnitParser.ParsingResult parsingResult = UnitParser.parse(bytesWithUnit); Unit unit = parsingResult.getUnit() .map(rawValue -> Unit.of(rawValue) .orElseThrow(() -> new IllegalArgumentException("Unknown unit " + rawValue))) .orElse(Unit.Byte); return unit.toByteCount(parsingResult.getNumber()); }  static String format(long bytesCount); static long parseAsByteCount(String bytesWithUnit); }
SizeFormat { public static long parseAsByteCount(String bytesWithUnit) { UnitParser.ParsingResult parsingResult = UnitParser.parse(bytesWithUnit); Unit unit = parsingResult.getUnit() .map(rawValue -> Unit.of(rawValue) .orElseThrow(() -> new IllegalArgumentException("Unknown unit " + rawValue))) .orElse(Unit.Byte); return unit.toByteCount(parsingResult.getNumber()); }  static String format(long bytesCount); static long parseAsByteCount(String bytesWithUnit);  }