Top Description Fields Constructors Methods
net.sf.ehcache.config

public sealed Enum MemoryUnit

extends Enum<MemoryUnit>
Class Inheritance

Memory unit: byte-based
Author
Alex Snaps

Field Summary

Modifier and TypeField and Description
public static final MemoryUnit
BYTES

BYTES

public static final MemoryUnit
GIGABYTES

GIGABYTES (1024 MEGABYTES)

public static final MemoryUnit
KILOBYTES

KILOBYTES (1024 BYTES)

public static final MemoryUnit
MEGABYTES

MEGABYTES (1024 KILOBYTES)

private static final int
private final int
private final char

Constructor Summary

AccessConstructor and Description
private
MemoryUnit(final int offset, final char unit)

Method Summary

Modifier and TypeMethod and Description
public static MemoryUnit

Returns:

the MemoryUnit instance matching the unit
forUnit
(final char
the unit to look for
unit
)

Returns the MemoryUnit instance based on provided char

public char

Returns:

the unit character
getUnit
()

Retrieves the unit character for the MemoryUnit

private static boolean
hasUnit(final String value)

public static long

Returns:

the amount of mem in the unit represented by the potential unit char
parseAmount
(final String
the String representation of an amount of memory
value
)

Parses the amount represented by the string, without caring for the unit

public static long

Returns:

the amount of bytes represented by the string
parseSizeInBytes
(final String
the String representation of an amount of memory
value
)

Parses the string for its content, returning the represented value in bytes

public static MemoryUnit

Returns:

the MemoryUnit instance, or BYTES if none
parseUnit
(final String
the String representation of an amount of memory
value
)

Parses the unit part of a String, if no unit char available, returns MemoryUnit#BYTES

private static long
safeShift(final long unit, final long shift)

public abstract long

Returns:

value in bytes
toBytes
(long
of the unit
amount
)

returns the amount in bytes

public abstract long

Returns:

value in gigabytes
toGigaBytes
(long
of the unit
amount
)

returns the amount in gigabytes

public abstract long

Returns:

value in kilobytes
toKiloBytes
(long
of the unit
amount
)

returns the amount in kilobytes

public abstract long

Returns:

value in megabytes
toMegaBytes
(long
of the unit
amount
)

returns the amount in megabytes

public String

Returns:

the String representation
toString
(final long
the amount to print
amount
)

Human readable value, with the added unit character as a suffix

public static MemoryUnit
public static MemoryUnit[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BYTESback to summary
public static final MemoryUnit BYTES

BYTES

GIGABYTESback to summary
public static final MemoryUnit GIGABYTES

GIGABYTES (1024 MEGABYTES)

KILOBYTESback to summary
public static final MemoryUnit KILOBYTES

KILOBYTES (1024 BYTES)

MEGABYTESback to summary
public static final MemoryUnit MEGABYTES

MEGABYTES (1024 KILOBYTES)

OFFSETback to summary
private static final int OFFSET
offsetback to summary
private final int offset
unitback to summary
private final char unit

Constructor Detail

MemoryUnitback to summary
private MemoryUnit(final int offset, final char unit)

Method Detail

forUnitback to summary
public static MemoryUnit forUnit(final char unit) throws IllegalArgumentException

Returns the MemoryUnit instance based on provided char

Parameters
unit:char

the unit to look for

Returns:MemoryUnit

the MemoryUnit instance matching the unit

Exceptions
IllegalArgumentException:
if no matching MemoryUnit matching the char
getUnitback to summary
public char getUnit()

Retrieves the unit character for the MemoryUnit

Returns:char

the unit character

hasUnitback to summary
private static boolean hasUnit(final String value)
parseAmountback to summary
public static long parseAmount(final String value) throws NumberFormatException

Parses the amount represented by the string, without caring for the unit

Parameters
value:String

the String representation of an amount of memory

Returns:long

the amount of mem in the unit represented by the potential unit char

Exceptions
NumberFormatException:
if not a number (with potential unit char stripped)
parseSizeInBytesback to summary
public static long parseSizeInBytes(final String value) throws NumberFormatException, IllegalArgumentException

Parses the string for its content, returning the represented value in bytes

Parameters
value:String

the String representation of an amount of memory

Returns:long

the amount of bytes represented by the string

Exceptions
NumberFormatException:
if not a number (with potential unit char stripped)
IllegalArgumentException:
if no matching MemoryUnit matching the char
parseUnitback to summary
public static MemoryUnit parseUnit(final String value)

Parses the unit part of a String, if no unit char available, returns MemoryUnit#BYTES

Parameters
value:String

the String representation of an amount of memory

Returns:MemoryUnit

the MemoryUnit instance, or BYTES if none

safeShiftback to summary
private static long safeShift(final long unit, final long shift)
toBytesback to summary
public abstract long toBytes(long amount)

returns the amount in bytes

Parameters
amount:long

of the unit

Returns:long

value in bytes

toGigaBytesback to summary
public abstract long toGigaBytes(long amount)

returns the amount in gigabytes

Parameters
amount:long

of the unit

Returns:long

value in gigabytes

toKiloBytesback to summary
public abstract long toKiloBytes(long amount)

returns the amount in kilobytes

Parameters
amount:long

of the unit

Returns:long

value in kilobytes

toMegaBytesback to summary
public abstract long toMegaBytes(long amount)

returns the amount in megabytes

Parameters
amount:long

of the unit

Returns:long

value in megabytes

toStringback to summary
public String toString(final long amount)

Human readable value, with the added unit character as a suffix

Parameters
amount:long

the amount to print

Returns:String

the String representation

valueOfback to summary
public static MemoryUnit valueOf(String name)
valuesback to summary
public static MemoryUnit[] values()