Skip to content

Commit 246a60b

Browse files
authored
Simplify conversions & casts (#388)
1 parent d58084f commit 246a60b

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

human-readable-types/src/main/java/com/palantir/humanreadabletypes/HumanReadableByteCount.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ public String toString() {
302302
public enum ByteUnit {
303303
BYTE(1, "bytes"),
304304
KiB(1024L, "kibibytes"),
305-
MiB((long) Math.pow((double) 1024L, (double) 2L), "mebibytes"),
306-
GiB((long) Math.pow((double) 1024L, (double) 3L), "gibibytes"),
307-
TiB((long) Math.pow((double) 1024L, (double) 4L), "tebibytes"),
308-
PiB((long) Math.pow((double) 1024L, (double) 5L), "pebibytes");
305+
MiB((long) Math.pow(1024.0, 2.0), "mebibytes"),
306+
GiB((long) Math.pow(1024.0, 3.0), "gibibytes"),
307+
TiB((long) Math.pow(1024.0, 4.0), "tebibytes"),
308+
PiB((long) Math.pow(1024.0, 5.0), "pebibytes");
309309

310310
private final long multiplier;
311311
private final String suffix;

human-readable-types/src/test/java/com/palantir/humanreadabletypes/HumanReadableByteCountTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,28 @@ public void testParseKibiBytes() {
4444

4545
@Test
4646
public void testParseMibiBytes() {
47-
assertStringsEqualToBytes((long) (Math.pow(1024.0, 2.0) * 10.0), "10m", "10mb", "10 mibibyte", "10 mibibytes");
47+
assertStringsEqualToBytes(10L * 1024L * 1024L, "10m", "10mb", "10 mibibyte", "10 " + "mibibytes");
4848
}
4949

5050
@Test
5151
public void testParseMebiBytes() {
52-
assertStringsEqualToBytes((long) (Math.pow(1024.0, 2.0) * 10.0), "10m", "10mb", "10 mebibyte", "10 mebibytes");
52+
assertStringsEqualToBytes(10L * 1024L * 1024L, "10m", "10mb", "10 mebibyte", "10 mebibytes");
5353
}
5454

5555
@Test
5656
public void testParseGibiBytes() {
57-
assertStringsEqualToBytes((long) (Math.pow(1024.0, 3.0) * 10.0), "10g", "10gb", "10 gibibyte", "10 gibibytes");
57+
assertStringsEqualToBytes(10L * 1024L * 1024L * 1024L, "10g", "10gb", "10 gibibyte", "10 gibibytes");
5858
}
5959

6060
@Test
6161
public void testParseTebiBytes() {
62-
assertStringsEqualToBytes((long) (Math.pow(1024.0, 4.0) * 10.0), "10t", "10tb", "10 tebibyte", "10 tebibytes");
62+
assertStringsEqualToBytes(10L * 1024L * 1024L * 1024L * 1024L, "10t", "10tb", "10 tebibyte", "10 tebibytes");
6363
}
6464

6565
@Test
6666
public void testParsePebiBytes() {
67-
assertStringsEqualToBytes((long) (Math.pow(1024.0, 5.0) * 10.0), "10p", "10pb", "10 pebibyte", "10 pebibytes");
67+
assertStringsEqualToBytes(
68+
10L * 1024L * 1024L * 1024L * 1024L * 1024L, "10p", "10pb", "10 pebibyte", "10 " + "pebibytes");
6869
}
6970

7071
@Test

0 commit comments

Comments
 (0)