public enum DecimalByteUnit extends Enum<DecimalByteUnit> implements ByteUnit
DecimalByteUnit
represents power-of-ten byte sizes at a given unit of granularity and
provides utility methods to convert across units. A DecimalByteUnit
does not maintain
byte size information, but only helps organize and use byte size representations that may be
maintained separately across various contexts.Enum Constant and Description |
---|
BYTES
Byte unit representing one byte.
|
GIGABYTES
A byte unit representing 1000 megabytes.
|
KILOBYTES
A byte unit representing 1000 bytes.
|
MEGABYTES
A byte unit representing 1000 kilobytes.
|
PETABYTES
A byte unit representing 1000 terabytes.
|
TERABYTES
A byte unit representing 1000 gigabytes.
|
Modifier and Type | Method and Description |
---|---|
long |
convert(long sourceCount,
DecimalByteUnit sourceUnit)
Converts the given size in the given unit to this unit.
|
long |
toGigabytes(long count)
Equivalent to
GIGABYTES.convert(count, this) . |
long |
toKilobytes(long count)
Equivalent to
KILOBYTES.convert(count, this) . |
long |
toMegabytes(long count)
Equivalent to
MEGABYTES.convert(count, this) . |
long |
toPetabytes(long count)
Equivalent to
PETABYTES.convert(count, this) . |
long |
toTerabytes(long count)
Equivalent to
TERABYTES.convert(count, this) . |
static DecimalByteUnit |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static DecimalByteUnit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final DecimalByteUnit BYTES
public static final DecimalByteUnit KILOBYTES
public static final DecimalByteUnit MEGABYTES
public static final DecimalByteUnit GIGABYTES
public static final DecimalByteUnit TERABYTES
public static final DecimalByteUnit PETABYTES
public static DecimalByteUnit[] values()
for (DecimalByteUnit c : DecimalByteUnit.values()) System.out.println(c);
public static DecimalByteUnit 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 convert(long sourceCount, DecimalByteUnit sourceUnit)
999
bytes to
kilobytes results in 0
. Conversions from coarser to finer granularities with arguments
that would numerically overflow saturate to Long.MIN_VALUE
if negative or
Long.MAX_VALUE
if positive.
For example, to convert 10 kilobytes to bytes, use:
ByteUnit.KILOBYTES.convert(10, ByteUnit.BYTES)
sourceCount
- the size in the given sourceUnit
.sourceUnit
- the unit of the sourceCount
argument.Long.MIN_VALUE
if conversion would
negatively overflow, or Long.MAX_VALUE
if it would positively overflow.public long toKilobytes(long count)
KILOBYTES.convert(count, this)
.count
- the bit countLong.MIN_VALUE
if conversion would negatively
overflow, or Long.MAX_VALUE
if it would positively overflow.public long toMegabytes(long count)
MEGABYTES.convert(count, this)
.count
- the bit countLong.MIN_VALUE
if conversion would negatively
overflow, or Long.MAX_VALUE
if it would positively overflow.public long toGigabytes(long count)
GIGABYTES.convert(count, this)
.count
- the bit countLong.MIN_VALUE
if conversion would negatively
overflow, or Long.MAX_VALUE
if it would positively overflow.public long toTerabytes(long count)
TERABYTES.convert(count, this)
.count
- the bit countLong.MIN_VALUE
if conversion would negatively
overflow, or Long.MAX_VALUE
if it would positively overflow.public long toPetabytes(long count)
PETABYTES.convert(count, this)
.count
- the bit countLong.MIN_VALUE
if conversion would negatively
overflow, or Long.MAX_VALUE
if it would positively overflow.Copyright © 2014. All Rights Reserved.