@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is too large .*") public void testRoundToTooLarge3() { new DataSize(9000 * 1024, PETABYTE).roundTo(KILOBYTE); }
public long roundTo(Unit unit) { double rounded = Math.floor(getValue(unit) + 0.5d); Preconditions.checkArgument(rounded <= Long.MAX_VALUE, "size is too large to be represented in requested unit as a long"); return (long) rounded; }
DataSize implements Comparable<DataSize> { public long roundTo(Unit unit) { double rounded = Math.floor(getValue(unit) + 0.5d); Preconditions.checkArgument(rounded <= Long.MAX_VALUE, "size is too large to be represented in requested unit as a long"); return (long) rounded; } }
DataSize implements Comparable<DataSize> { public long roundTo(Unit unit) { double rounded = Math.floor(getValue(unit) + 0.5d); Preconditions.checkArgument(rounded <= Long.MAX_VALUE, "size is too large to be represented in requested unit as a long"); return (long) rounded; } DataSize(double size, Unit unit); }
DataSize implements Comparable<DataSize> { public long roundTo(Unit unit) { double rounded = Math.floor(getValue(unit) + 0.5d); Preconditions.checkArgument(rounded <= Long.MAX_VALUE, "size is too large to be represented in requested unit as a long"); return (long) rounded; } 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(); }
DataSize implements Comparable<DataSize> { public long roundTo(Unit unit) { double rounded = Math.floor(getValue(unit) + 0.5d); Preconditions.checkArgument(rounded <= Long.MAX_VALUE, "size is too large to be represented in requested unit as a long"); return (long) rounded; } 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();  }