public enum BitUnit extends Enum<BitUnit> implements ByteUnit
BitUnit
represents bit size at a given unit of granularity and provides utility
methods to convert across units. A BitUnit
does not maintain bit size information,
but only helps organize and use bit size representations that may be maintained separately
across various contexts.Enum Constant and Description |
---|
BITS
Bit unit representing one bit.
|
GIGABITS
A bit unit representing 1000 megabits.
|
KILOBITS
A bit unit representing 1000 bits.
|
MEGABITS
A bit unit representing 1000 kilobits.
|
PETABITS
A bit unit representing 1000 terabits.
|
TERABITS
A bit unit representing 1000 gigabits.
|
Modifier and Type | Method and Description |
---|---|
long |
convert(long sourceCount,
BitUnit sourceUnit)
Converts the given size in the given unit to this unit.
|
long |
toBits(long count)
Equivalent to
BITS.convert(count, this) . |
long |
toGigabits(long count)
Equivalent to
GIGABITS.convert(count, this) . |
long |
toKilobits(long count)
Equivalent to
KILOBITS.convert(count, this) . |
long |
toMegabits(long count)
Equivalent to
MEGABITS.convert(count, this) . |
long |
toPetabits(long count)
Equivalent to
PETABITS.convert(count, this) . |
long |
toTerabits(long count)
Equivalent to
TERABITS.convert(count, this) . |
static BitUnit |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static BitUnit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final BitUnit BITS
public static final BitUnit KILOBITS
public static final BitUnit MEGABITS
public static final BitUnit GIGABITS
public static final BitUnit TERABITS
public static final BitUnit PETABITS
public static BitUnit[] values()
for (BitUnit c : BitUnit.values()) System.out.println(c);
public static BitUnit 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, BitUnit sourceUnit)
999
bit to
kilobits 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.KILOBITS.convert(10, ByteUnit.BITS)
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 toBits(long count)
BITS.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 toKilobits(long count)
KILOBITS.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 toMegabits(long count)
MEGABITS.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 toGigabits(long count)
GIGABITS.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 toTerabits(long count)
TERABITS.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 toPetabits(long count)
PETABITS.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.