public enum MemoryUnit extends java.lang.Enum<MemoryUnit>
Enum Constant and Description |
---|
BYTES
BYTES
|
GIGABYTES
GIGABYTES (1024 MEGABYTES)
|
KILOBYTES
KILOBYTES (1024 BYTES)
|
MEGABYTES
MEGABYTES (1024 KILOBYTES)
|
Modifier and Type | Field and Description |
---|---|
private int |
offset |
private static int |
OFFSET |
private char |
unit |
Modifier and Type | Method and Description |
---|---|
static MemoryUnit |
forUnit(char unit)
Returns the MemoryUnit instance based on provided char
|
char |
getUnit()
Retrieves the unit character for the MemoryUnit
|
private static boolean |
hasUnit(java.lang.String value) |
static long |
parseAmount(java.lang.String value)
Parses the amount represented by the string, without caring for the unit
|
static long |
parseSizeInBytes(java.lang.String value)
Parses the string for its content, returning the represented value in bytes
|
static MemoryUnit |
parseUnit(java.lang.String value)
Parses the unit part of a String, if no unit char available, returns
BYTES |
private static long |
safeShift(long unit,
long shift) |
abstract long |
toBytes(long amount)
returns the amount in bytes
|
abstract long |
toGigaBytes(long amount)
returns the amount in gigabytes
|
abstract long |
toKiloBytes(long amount)
returns the amount in kilobytes
|
abstract long |
toMegaBytes(long amount)
returns the amount in megabytes
|
java.lang.String |
toString(long amount)
Human readable value, with the added unit character as a suffix
|
static MemoryUnit |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static MemoryUnit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final MemoryUnit BYTES
public static final MemoryUnit KILOBYTES
public static final MemoryUnit MEGABYTES
public static final MemoryUnit GIGABYTES
private static final int OFFSET
private final int offset
private final char unit
public static MemoryUnit[] values()
for (MemoryUnit c : MemoryUnit.values()) System.out.println(c);
public static MemoryUnit valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic char getUnit()
public abstract long toBytes(long amount)
amount
- of the unitpublic abstract long toKiloBytes(long amount)
amount
- of the unitpublic abstract long toMegaBytes(long amount)
amount
- of the unitpublic abstract long toGigaBytes(long amount)
amount
- of the unitpublic java.lang.String toString(long amount)
amount
- the amount to printpublic static MemoryUnit forUnit(char unit) throws java.lang.IllegalArgumentException
unit
- the unit to look forjava.lang.IllegalArgumentException
- if no matching MemoryUnit matching the charpublic static MemoryUnit parseUnit(java.lang.String value)
BYTES
value
- the String representation of an amount of memorypublic static long parseAmount(java.lang.String value) throws java.lang.NumberFormatException
value
- the String representation of an amount of memoryjava.lang.NumberFormatException
- if not a number (with potential unit char stripped)public static long parseSizeInBytes(java.lang.String value) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException
value
- the String representation of an amount of memoryjava.lang.NumberFormatException
- if not a number (with potential unit char stripped)java.lang.IllegalArgumentException
- if no matching MemoryUnit matching the charprivate static boolean hasUnit(java.lang.String value)
private static long safeShift(long unit, long shift)