public class Storage
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Storage.Unit |
| Constructor and Description |
|---|
Storage(long amount) |
Storage(long amount,
Storage.Unit unit) |
| Modifier and Type | Method and Description |
|---|---|
Storage |
deepCopy() |
boolean |
equals(java.lang.Object other) |
Storage.Unit |
getAppropriateUnits()
Finds the largest
Storage.Unit which can display the storage value as a positive integer with
no loss of accuracy. |
Storage.Unit |
getLargestReasonableUnits()
Finds the largest
Storage.Unit which can display the storage value with non-zero integer
part. |
double |
getPreciseSizeAsUnit(Storage.Unit unit)
Returns the amount of storage represented by the instance in the given unit as a double to
get a more precise result
|
long |
getSize()
Returns the amount of storage represented, in Bytes
|
long |
getSizeAsUnit(Storage.Unit unit)
Return the amount of storage represented by the instance in the given unit
|
static Storage |
getStorageFromString(java.lang.String storageString)
Decodes the given string and returns a
Storage of the corresponding size. |
int |
hashCode() |
boolean |
lessThan(java.lang.Object other) |
java.lang.String |
toIniString()
Represents a
Storage as a string suitable
for use in an INI file. |
java.lang.String |
toString() |
java.lang.String |
toUiString()
Represents a
Storage as a string suitable for displaying in the UI. |
java.lang.String |
toUiString(int precision)
Represents a
Storage as a string suitable for displaying in the UI. |
public Storage(long amount,
Storage.Unit unit)
public Storage(long amount)
public long getSize()
@NonNull public Storage deepCopy()
public long getSizeAsUnit(@NonNull
Storage.Unit unit)
unit - The unit of the result.public double getPreciseSizeAsUnit(@NonNull
Storage.Unit unit)
unit - The unit of the result.@Nullable public static Storage getStorageFromString(@Nullable java.lang.String storageString)
Storage of the corresponding size. The input
string can look like these:
"2" "2B" "2MB" "2 M" "2 MB"
But NOT like these:
"2m" "2.6" "2 MiB"public boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic boolean lessThan(java.lang.Object other)
public int hashCode()
hashCode in class java.lang.Object@NonNull public Storage.Unit getAppropriateUnits()
Storage.Unit which can display the storage value as a positive integer with
no loss of accuracy.Storage.Unit.#getLargestReasonableUnits()}@NonNull public Storage.Unit getLargestReasonableUnits()
Storage.Unit which can display the storage value with non-zero integer
part. This might be useful for displaying in user interface where full precision is not
critical and can be sacrificed in favor of better UX.Storage.Unit such that getSize()/Unit.getNumberOfBytes() is not zero.#getAppropriateUnits()}@NonNull public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toUiString()
Storage as a string suitable for displaying in the UI.#getLargestReasonableUnits()}public java.lang.String toUiString(int precision)
Storage as a string suitable for displaying in the UI.precision - The number of digits after decimal point to display.#getLargestReasonableUnits()}@NonNull public java.lang.String toIniString()
Storage as a string suitable
for use in an INI file.