public enum MemoryUnit extends Enum<MemoryUnit>
Enum Constant and Description |
---|
BYTES
BYTES
|
GIGABYTES
GIGABYTES (1024 MEGABYTES)
|
KILOBYTES
KILOBYTES (1024 BYTES)
|
MEGABYTES
MEGABYTES (1024 KILOBYTES)
|
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
|
static long |
parseAmount(String value)
Parses the amount represented by the string, without caring for the unit
|
static long |
parseSizeInBytes(String value)
Parses the string for its content, returning the represented value in bytes
|
static MemoryUnit |
parseUnit(String value)
Parses the unit part of a String, if no unit char available, returns
BYTES |
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
|
String |
toString(long amount)
Human readable value, with the added unit character as a suffix
|
static MemoryUnit |
valueOf(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
public static MemoryUnit[] values()
for (MemoryUnit c : MemoryUnit.values()) System.out.println(c);
public static MemoryUnit 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 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 String toString(long amount)
amount
- the amount to printpublic static MemoryUnit forUnit(char unit) throws IllegalArgumentException
unit
- the unit to look forIllegalArgumentException
- if no matching MemoryUnit matching the charpublic static MemoryUnit parseUnit(String value)
BYTES
value
- the String representation of an amount of memorypublic static long parseAmount(String value) throws NumberFormatException
value
- the String representation of an amount of memoryNumberFormatException
- if not a number (with potential unit char stripped)public static long parseSizeInBytes(String value) throws NumberFormatException, IllegalArgumentException
value
- the String representation of an amount of memoryNumberFormatException
- if not a number (with potential unit char stripped)IllegalArgumentException
- if no matching MemoryUnit matching the charCopyright © 2003–2016 Terracotta, Inc.. All rights reserved.