public enum DataUnit extends Enum<DataUnit>
A DataUnit is mainly used to inform data-based methods how a given data parameter should be interpreted. For example:
// how many kilobytes in a gigabyte amount long kb = DataUnit.GB.toKilobytes(3); // results = 3072 // how many megabyte in a kilobyte amount long mb = DataUnit.KB.toMegabytes(2500); // results = 2 // convert with dynamic units DataUnit targetUnit = // any unit long value = 1024; DataUnit kb = DataUnit.KB; long convertedValue = targetUnit.convert(1024, kb);
DataUnitFormatter
Enum Constant and Description |
---|
B
Byte.
|
GB
Gigabyte.
|
KB
Kilobyte.
|
MB
Megabyte.
|
PB
Petabyte.
|
TB
Terabyte.
|
Modifier and Type | Method and Description |
---|---|
long |
convert(long sourceAmount,
DataUnit sourceUnit)
Converts a given source data amount and type to this type.
|
long |
toBytes(long amount) |
long |
toGigabytes(long amount) |
long |
toKilobytes(long amount) |
long |
toMegabytes(long amount) |
long |
toPetabytes(long amount) |
long |
toTerabytes(long amount) |
static DataUnit |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static DataUnit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final DataUnit B
public static final DataUnit KB
public static final DataUnit MB
public static final DataUnit GB
public static final DataUnit TB
public static final DataUnit PB
public static DataUnit[] values()
for (DataUnit c : DataUnit.values()) System.out.println(c);
public static DataUnit 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 long toBytes(long amount)
public long toKilobytes(long amount)
public long toMegabytes(long amount)
public long toGigabytes(long amount)
public long toTerabytes(long amount)
public long toPetabytes(long amount)
public long convert(long sourceAmount, DataUnit sourceUnit)
sourceAmount
- source data amountsourceUnit
- source data unitCopyright © 2008–2021 Norconex Inc.. All rights reserved.