DataSize implements Comparable<DataSize> { public DataSize convertToMostSuccinctDataSize() { Unit unitToUse = Unit.BYTE; for (Unit unitToTest : DATASIZE_UNITS) { if (getValue(unitToTest) >= 1.0) { unitToUse = unitToTest; } else { break; } } return convertTo(unitToUse); } DataSize(double size, Unit unit); static DataSize succinctBytes(long bytes); static DataSize succinctDataSize(double size, Unit unit); long toBytes(); double getValue(); Unit getUnit(); double getValue(Unit unit); long roundTo(Unit unit); DataSize convertTo(Unit unit); DataSize convertToMostSuccinctDataSize(); @JsonValue @Override String toString(); @JsonCreator static DataSize valueOf(String size); @Override int compareTo(DataSize o); @Override boolean equals(Object o); @Override int hashCode();  }
@Test(dataProvider = "conversions") public void testConvertToMostSuccinctDataSize(DataSize.Unit unit, DataSize.Unit toUnit, double factor) { DataSize size = new DataSize(factor, toUnit); DataSize actual = size.convertToMostSuccinctDataSize(); assertThat(actual).isEqualTo(new DataSize(1, unit)); assertThat(actual.getValue(unit)).isCloseTo(1.0, offset(0.001)); assertThat(actual.getUnit()).isEqualTo(unit); }