public enum StorageUnit extends Enum<StorageUnit>
getISOUnit() method (which returns the short-form ISO unit - eg. "KiB" for KILOBYTES, "KB" for DECIMAL_KILOBYTES
and "Kb" for KILOBIT)| Enum Constant and Description |
|---|
BITS
One bit (4 bits)
|
BYTES
One byte (8 bits)
|
DECIMAL_EXABYTES
One decimal Exabyte (ISO: EB).
|
DECIMAL_GIGABYTES
One decimal gigabyte (ISO: GB).
|
DECIMAL_KILOBYTES
One decimal kilobyte (ISO: KB).
|
DECIMAL_MEGABYTES
One decimal megabyte (ISO: MB).
|
DECIMAL_PETABYTES
One decimal Petabyte (ISO: PB).
|
DECIMAL_TERABYTES
One decimal terabyte (ISO: TB).
|
DECIMAL_YOTTABYTES
One decimal yottabyte (ISO YB).
|
DECIMAL_ZETTABYTES
One decimal zettabyte (ISO ZB).
|
EXABITS
One Exabit (ISO: Eb).
|
EXABYTES
One Exabyte (ISO: EiB)
The ISO long form name for this unit is Exbibibyte (which we avoid using as the enum name to avoid confusion) |
GIGABITS
One Gigabit (ISO: Gb).
|
GIGABYTES
One Gigabyte (ISO: GiB)
The ISO long form name for this unit is Gibibyte (which we avoid using as the enum name to avoid confusion) |
KILOBITS
One Kilobit (ISO: Kb).
|
KILOBYTES
One Kilobyte (ISO: KiB).
|
MEGABITS
One Megabit (ISO: Mb).
|
MEGABYTES
One Megabyte (ISO: MiB)
The ISO long form name for this unit is Mebibyte (which we avoid using as the enum name to avoid confusion) |
NIBBLES
One nibble (4 bits)
|
PETABITS
One Petabit (ISO: Pb).
|
PETABYTES
One Petabyte (ISO: PiB)
The ISO long form name for this unit is Pebibyte (which we avoid using as the enum name to avoid confusion) |
TERABITS
One Terabit (ISO: Tb).
|
TERABYTES
One Terabyte (ISO: TiB)
The ISO long form name for this unit is Tebibyte (which we avoid using as the enum name to avoid confusion) |
YOTTABITS
One yottabit (ISO Yb).
|
YOTTABYTES
One yottabyte (ISO YiB)
The ISO long form name for this unit is Yobibyte (which we avoid using as the enum name to avoid confusion) |
ZETTABITS
One zettabit (ISO Zb).
|
ZETTABYTES
One zettabyte (ISO ZiB)
The ISO long form name for this unit is Zebibyte (which we avoid using as the enum name to avoid confusion) |
| Modifier and Type | Field and Description |
|---|---|
static StorageUnit[] |
BINARY_QUANTIFIERS
The range of quantifiers for binary units (bytes to terabytes (ISO: B to TiB))
|
static StorageUnit[] |
COMPSCI_BINARY |
static StorageUnit[] |
DECIMAL_QUANTIFIERS
The range of quantifiers for ISO decimal units (bytes to terabytes (ISO: B to TB))
|
static StorageUnit[] |
NETWORK_DECIMAL |
static int |
ROUNDING_MODE
The rounding mode this class uses; this is, by default,
BigDecimal.ROUND_HALF_UP |
static StorageUnit[] |
STORAGE_DECIMAL |
| Modifier and Type | Method and Description |
|---|---|
BigDecimal |
convert(BigDecimal amount,
StorageUnit unit) |
BigInteger |
convert(BigInteger amount,
StorageUnit unit) |
long |
convert(long amount,
StorageUnit unit) |
BigDecimal |
fromBits(BigDecimal bits) |
BigInteger |
fromBits(BigInteger bits) |
static StorageUnit |
getAppropriateBinaryUnit(BigInteger amount,
StorageUnit sourceUnit)
Attempts to locate the most appropriate binary unit (binary units are what everyone but the ISO and the storage industry
mean by "KB", "MB", etc.
|
static StorageUnit |
getAppropriateDecimalUnit(BigInteger amount,
StorageUnit sourceUnit)
Attempts to locate the most appropriate decimal unit (decimal units are what the ISO and the storage industry (but nobody
else) mean by "KB", "MB", etc.
|
static StorageUnit |
getAppropriateUnit(BigInteger amount,
StorageUnit sourceUnit,
StorageUnit[] options)
Attempts to locate the most appropriate of the provided units to express the provided amount in for human use (balancing
precision and sensible expression)
|
String |
getISOUnit()
Return the ISO unit for this storage unit.
for MEGABYTE this will return MiB (to avoid further confusion) |
String |
getPlural()
Get the plural version of this unit (e.g.
|
String |
getSingular()
Get the singular version of this unit (e.g.
|
static StorageUnit |
largest(StorageUnit unit,
StorageUnit unit2)
Returns the the larger unit of
unit and unit2 |
static StorageUnit |
parse(String original)
Parse the non-ISO abbreviation: MiB and MB both -> MEGABYTE (which is technically a "Mebibyte")
|
static StorageUnit |
parseISO(String toParse)
Parse the ISO abbreviation: (e.g.
|
static StorageUnit |
smallest(StorageUnit unit,
StorageUnit unit2)
Returns the the most diminutive unit of
unit and unit2 |
BigDecimal |
toBits(BigDecimal amount) |
BigInteger |
toBits(BigInteger amount) |
BigDecimal |
toBytes(BigDecimal amount) |
BigInteger |
toBytes(BigInteger amount) |
long |
toBytes(long amount) |
String |
toString(BigDecimal amount) |
String |
toString(BigDecimal amount,
boolean shortType) |
String |
toString(BigInteger amount) |
String |
toString(BigInteger amount,
boolean shortType) |
String |
toString(long amount) |
String |
toString(long amount,
boolean shortType) |
static StorageUnit |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static StorageUnit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final StorageUnit BITS
public static final StorageUnit NIBBLES
public static final StorageUnit BYTES
public static final StorageUnit KILOBYTES
public static final StorageUnit MEGABYTES
public static final StorageUnit GIGABYTES
public static final StorageUnit TERABYTES
public static final StorageUnit PETABYTES
public static final StorageUnit EXABYTES
public static final StorageUnit ZETTABYTES
public static final StorageUnit YOTTABYTES
public static final StorageUnit DECIMAL_KILOBYTES
public static final StorageUnit DECIMAL_MEGABYTES
public static final StorageUnit DECIMAL_GIGABYTES
public static final StorageUnit DECIMAL_TERABYTES
public static final StorageUnit DECIMAL_PETABYTES
public static final StorageUnit DECIMAL_EXABYTES
public static final StorageUnit DECIMAL_ZETTABYTES
public static final StorageUnit DECIMAL_YOTTABYTES
public static final StorageUnit KILOBITS
public static final StorageUnit MEGABITS
public static final StorageUnit GIGABITS
public static final StorageUnit TERABITS
public static final StorageUnit PETABITS
public static final StorageUnit EXABITS
public static final StorageUnit ZETTABITS
public static final StorageUnit YOTTABITS
public static final StorageUnit[] NETWORK_DECIMAL
public static final StorageUnit[] STORAGE_DECIMAL
public static final StorageUnit[] COMPSCI_BINARY
public static final StorageUnit[] DECIMAL_QUANTIFIERS
public static final StorageUnit[] BINARY_QUANTIFIERS
public static final int ROUNDING_MODE
BigDecimal.ROUND_HALF_UPpublic static StorageUnit[] values()
for (StorageUnit c : StorageUnit.values()) System.out.println(c);
public static StorageUnit valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic String getISOUnit()
public String getPlural()
public String getSingular()
public long convert(long amount,
StorageUnit unit)
public BigInteger convert(BigInteger amount, StorageUnit unit)
public BigDecimal convert(BigDecimal amount, StorageUnit unit)
public BigInteger toBits(BigInteger amount)
public BigDecimal toBits(BigDecimal amount)
public BigInteger fromBits(BigInteger bits)
public BigDecimal fromBits(BigDecimal bits)
public long toBytes(long amount)
public BigDecimal toBytes(BigDecimal amount)
public BigInteger toBytes(BigInteger amount)
public String toString(long amount)
public String toString(BigInteger amount)
public String toString(BigDecimal amount)
public String toString(long amount, boolean shortType)
public String toString(BigInteger amount, boolean shortType)
public String toString(BigDecimal amount, boolean shortType)
public static StorageUnit getAppropriateBinaryUnit(BigInteger amount, StorageUnit sourceUnit)
amount - the amountsourceUnit - the unit the amount is expressed inpublic static StorageUnit getAppropriateDecimalUnit(BigInteger amount, StorageUnit sourceUnit)
amount - the amountsourceUnit - the unit the amount is expressed inpublic static StorageUnit getAppropriateUnit(BigInteger amount, StorageUnit sourceUnit, StorageUnit[] options)
amount - the amountsourceUnit - the unit the amount is expressed inoptions - the storage units which may be usedpublic static StorageUnit smallest(StorageUnit unit, StorageUnit unit2)
unit and unit2unit - a unit (should not be null)unit2 - a unit (should not be null)unit and unit2 (or null if both units were null)NullPointerException - if one unit is nullpublic static StorageUnit largest(StorageUnit unit, StorageUnit unit2)
unit and unit2unit - a unit (should not be null)unit2 - a unit (should not be null)unit and unit2 (or null if both units were null)NullPointerException - if one unit is nullpublic static StorageUnit parseISO(String toParse)
unit - public static StorageUnit parse(String original)
toParse - StorageUnit.MEGABYTES)Copyright © 2016. All rights reserved.