Package org.openjdk.jmc.common.unit
Enum BinaryPrefix
- java.lang.Object
-
- java.lang.Enum<BinaryPrefix>
-
- org.openjdk.jmc.common.unit.BinaryPrefix
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<BinaryPrefix>
,IPrefix<BinaryPrefix>
public enum BinaryPrefix extends java.lang.Enum<BinaryPrefix> implements IPrefix<BinaryPrefix>
Binary prefixes, as standardized by IEC. The corresponding SI prefixes are also provided to reflect common usage. (JEDEC defines these to be used for powers of 1024 as well, except that they too capitalize "k".) Extend functionality as needed, perhaps likeTimeUnit
.
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
englishName
java.lang.String
localizedName
private static BinaryPrefix[]
PREFIXES
DecimalPrefix
prefixSI
Deprecated.Accept that kilobytes and kibibytes are different units.private BinaryScaleFactor
scaleFactor
private int
shift
java.lang.String
symbolIEC
java.lang.String
symbolJEDEC
java.lang.String
symbolSI
-
Constructor Summary
Constructors Modifier Constructor Description private
BinaryPrefix()
private
BinaryPrefix(int powerOf1024, char charSI)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
altSymbol()
An alternative symbol.java.lang.StringBuilder
asExponentialStringBuilder(boolean multiplicationSign)
double
convertTo(double value)
float
convertTo(float value)
long
convertTo(long value)
LinearKindOfQuantity.LinearUnitSelector
createUnitSelector(LinearKindOfQuantity kindOfQuantity, java.lang.Iterable<BinaryPrefix> prefixes)
private static int
floorDiv10(int value)
static int
getAlignmentLog1024(double value)
The base 1024 logarithm of the binary alignment ofvalue
.static int
getAlignmentLog1024(long value)
The base 1024 logarithm of the binary alignment ofvalue
.static int
getAlignmentLog2(double value)
The base 2 logarithm of the binary alignment ofvalue
.static int
getAlignmentLog2(long value)
The base 2 logarithm of the binary alignment ofvalue
.static int
getFloorLog1024(double value)
The base 1024 logarithm.static int
getFloorLog1024(long value)
The base 1024 logarithm.static int
getFloorLog2(double value)
The base 2 logarithm.static int
getFloorLog2(long value)
The base 2 logarithm.static BinaryPrefix
getFloorPrefix(double value)
static BinaryPrefix
getFloorPrefix(long value)
java.lang.String
identifier()
java.lang.String
localizedName()
int
log1024()
BinaryScaleFactor
scaleFactor()
int
shift()
java.lang.String
symbol()
BinaryScaleFactor
valueFactorTo(BinaryPrefix targetPrefix)
static BinaryPrefix
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static BinaryPrefix[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
NOBI
public static final BinaryPrefix NOBI
-
KIBI
public static final BinaryPrefix KIBI
-
MEBI
public static final BinaryPrefix MEBI
-
GIBI
public static final BinaryPrefix GIBI
-
TEBI
public static final BinaryPrefix TEBI
-
PEBI
public static final BinaryPrefix PEBI
-
EXBI
public static final BinaryPrefix EXBI
-
ZEBI
public static final BinaryPrefix ZEBI
-
YOBI
public static final BinaryPrefix YOBI
-
-
Field Detail
-
PREFIXES
private static BinaryPrefix[] PREFIXES
-
shift
private final int shift
-
scaleFactor
private final BinaryScaleFactor scaleFactor
-
prefixSI
@Deprecated public final DecimalPrefix prefixSI
Deprecated.Accept that kilobytes and kibibytes are different units.Temporary reference to the corresponding decimal prefix to get the full name, only to be used during the transition phase where JMC hasn't been completely converted to use quantities. Do not rely on this.
-
symbolSI
public final java.lang.String symbolSI
-
symbolJEDEC
public final java.lang.String symbolJEDEC
-
symbolIEC
public final java.lang.String symbolIEC
-
englishName
public final java.lang.String englishName
-
localizedName
public final java.lang.String localizedName
-
-
Method Detail
-
values
public static BinaryPrefix[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (BinaryPrefix c : BinaryPrefix.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static BinaryPrefix valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
shift
public int shift()
-
log1024
public int log1024()
-
convertTo
public long convertTo(long value)
-
convertTo
public float convertTo(float value)
-
convertTo
public double convertTo(double value)
-
getFloorLog2
public static int getFloorLog2(long value)
The base 2 logarithm. Note that for the value 0, 0 is returned in order to be consistent withMath.floor(double)
.- Returns:
- the floor of the base 2 logarithm of the absolute value of
value
-
getFloorLog1024
public static int getFloorLog1024(long value)
The base 1024 logarithm. Note that for the value 0, 0 is returned in order to be consistent withMath.floor(double)
.- Returns:
- the floor of the base 1024 logarithm of the absolute value of
value
-
getFloorPrefix
public static BinaryPrefix getFloorPrefix(long value)
-
getAlignmentLog2
public static int getAlignmentLog2(long value)
The base 2 logarithm of the binary alignment ofvalue
. Note that for the value 0, the return value is undefined.- Returns:
- the base 2 logarithm of the alignment of
value
-
getAlignmentLog1024
public static int getAlignmentLog1024(long value)
The base 1024 logarithm of the binary alignment ofvalue
. Note that for the value 0, the return value is undefined.- Returns:
- the base 1024 logarithm of the alignment of
value
-
getFloorLog2
public static int getFloorLog2(double value)
The base 2 logarithm. Note that for the value 0, 0 is returned, in order to be consistent withMath.floor(double)
.- Returns:
- the floor of the base 2 logarithm of the absolute value of
value
-
floorDiv10
private static int floorDiv10(int value)
-
getFloorLog1024
public static int getFloorLog1024(double value)
The base 1024 logarithm. Note that for the value 0, 0 is returned in order to be consistent withMath.floor(double)
.- Returns:
- the floor of the base 1024 logarithm of the absolute value of
value
-
getFloorPrefix
public static BinaryPrefix getFloorPrefix(double value)
-
getAlignmentLog2
public static int getAlignmentLog2(double value)
The base 2 logarithm of the binary alignment ofvalue
. Note that for zero, infinity, NaN, and denormalized values, the return value is currently undefined.- Returns:
- the base 2 logarithm of the alignment of
value
-
getAlignmentLog1024
public static int getAlignmentLog1024(double value)
The base 1024 logarithm of the binary alignment ofvalue
. Note that for zero, infinity, NaN, and denormalized values, the return value is currently undefined.- Returns:
- the base 1024 logarithm of the alignment of
value
-
identifier
public java.lang.String identifier()
- Specified by:
identifier
in interfaceIPrefix<BinaryPrefix>
- Returns:
- identifier usable for constructing persistable identifiers for units.
-
symbol
public java.lang.String symbol()
- Specified by:
symbol
in interfaceIPrefix<BinaryPrefix>
- Returns:
- the symbol normally used to present this prefix in a GUI.
-
altSymbol
public java.lang.String altSymbol()
Description copied from interface:IPrefix
An alternative symbol. Intended to be used for interactive parsing where entering the micron character may be cumbersome, or catching typing of MB when intending MiB. (These are very different cases, and should ideally not be handled by the same mechanism. However, a single mechanism seems to work right now.)- Specified by:
altSymbol
in interfaceIPrefix<BinaryPrefix>
- Returns:
- alternative symbol, or
null
if no other representation is available
-
localizedName
public java.lang.String localizedName()
- Specified by:
localizedName
in interfaceIPrefix<BinaryPrefix>
-
asExponentialStringBuilder
public java.lang.StringBuilder asExponentialStringBuilder(boolean multiplicationSign)
- Specified by:
asExponentialStringBuilder
in interfaceIPrefix<BinaryPrefix>
-
scaleFactor
public BinaryScaleFactor scaleFactor()
- Specified by:
scaleFactor
in interfaceIPrefix<BinaryPrefix>
-
valueFactorTo
public BinaryScaleFactor valueFactorTo(BinaryPrefix targetPrefix)
- Specified by:
valueFactorTo
in interfaceIPrefix<BinaryPrefix>
-
createUnitSelector
public LinearKindOfQuantity.LinearUnitSelector createUnitSelector(LinearKindOfQuantity kindOfQuantity, java.lang.Iterable<BinaryPrefix> prefixes)
- Specified by:
createUnitSelector
in interfaceIPrefix<BinaryPrefix>
-
-