-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util-core: Add Java-friendly API for StorageUnit
Problem `StorageUnit` is lacking a non-implicit API for building instances from different units (bytes, kilobytes, megabytes, etc). This makes it quite unusable from the Java side. Solution Add `fromX` method on the companion object so they will compile into static methods hence will be available from Java. RB_ID=864546
- Loading branch information
1 parent
19d7613
commit d0aca38
Showing
4 changed files
with
79 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
util-core/src/test/java/com/twitter/util/StorageUnitCompilationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.twitter.util; | ||
|
||
import org.junit.Test; | ||
|
||
public class StorageUnitCompilationTest { | ||
|
||
@Test | ||
public void testFrom() { | ||
StorageUnit a = StorageUnit.fromBytes(1); | ||
StorageUnit b = StorageUnit.fromKilobytes(1); | ||
StorageUnit c = StorageUnit.fromMegabytes(1); | ||
StorageUnit d = StorageUnit.fromTerabytes(1); | ||
StorageUnit e = StorageUnit.fromPetabytes(1); | ||
StorageUnit f = StorageUnit.fromExabytes(1); | ||
} | ||
|
||
@Test | ||
public void testBinaryOperations() { | ||
StorageUnit a = StorageUnit.fromBytes(1); | ||
StorageUnit b = StorageUnit.fromBytes(1); | ||
|
||
a.plus(b).minus(a).times(1.0).times(1L).divide(1L); | ||
} | ||
} |