Package net.sf.ehcache.config
Enum MemoryUnit
- java.lang.Object
-
- java.lang.Enum<MemoryUnit>
-
- net.sf.ehcache.config.MemoryUnit
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<MemoryUnit>
public enum MemoryUnit extends java.lang.Enum<MemoryUnit>
Memory unit: byte-based- Author:
- Alex Snaps
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static MemoryUnitforUnit(char unit)Returns the MemoryUnit instance based on provided charchargetUnit()Retrieves the unit character for the MemoryUnitstatic longparseAmount(java.lang.String value)Parses the amount represented by the string, without caring for the unitstatic longparseSizeInBytes(java.lang.String value)Parses the string for its content, returning the represented value in bytesstatic MemoryUnitparseUnit(java.lang.String value)Parses the unit part of a String, if no unit char available, returnsBYTESabstract longtoBytes(long amount)returns the amount in bytesabstract longtoGigaBytes(long amount)returns the amount in gigabytesabstract longtoKiloBytes(long amount)returns the amount in kilobytesabstract longtoMegaBytes(long amount)returns the amount in megabytesjava.lang.StringtoString(long amount)Human readable value, with the added unit character as a suffixstatic MemoryUnitvalueOf(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.
-
-
-
Enum Constant Detail
-
BYTES
public static final MemoryUnit BYTES
BYTES
-
KILOBYTES
public static final MemoryUnit KILOBYTES
KILOBYTES (1024 BYTES)
-
MEGABYTES
public static final MemoryUnit MEGABYTES
MEGABYTES (1024 KILOBYTES)
-
GIGABYTES
public static final MemoryUnit GIGABYTES
GIGABYTES (1024 MEGABYTES)
-
-
Method Detail
-
values
public static MemoryUnit[] 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 (MemoryUnit c : MemoryUnit.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static MemoryUnit 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
-
getUnit
public char getUnit()
Retrieves the unit character for the MemoryUnit- Returns:
- the unit character
-
toBytes
public abstract long toBytes(long amount)
returns the amount in bytes- Parameters:
amount- of the unit- Returns:
- value in bytes
-
toKiloBytes
public abstract long toKiloBytes(long amount)
returns the amount in kilobytes- Parameters:
amount- of the unit- Returns:
- value in kilobytes
-
toMegaBytes
public abstract long toMegaBytes(long amount)
returns the amount in megabytes- Parameters:
amount- of the unit- Returns:
- value in megabytes
-
toGigaBytes
public abstract long toGigaBytes(long amount)
returns the amount in gigabytes- Parameters:
amount- of the unit- Returns:
- value in gigabytes
-
toString
public java.lang.String toString(long amount)
Human readable value, with the added unit character as a suffix- Parameters:
amount- the amount to print- Returns:
- the String representation
-
forUnit
public static MemoryUnit forUnit(char unit) throws java.lang.IllegalArgumentException
Returns the MemoryUnit instance based on provided char- Parameters:
unit- the unit to look for- Returns:
- the MemoryUnit instance matching the unit
- Throws:
java.lang.IllegalArgumentException- if no matching MemoryUnit matching the char
-
parseUnit
public static MemoryUnit parseUnit(java.lang.String value)
Parses the unit part of a String, if no unit char available, returnsBYTES- Parameters:
value- the String representation of an amount of memory- Returns:
- the MemoryUnit instance, or BYTES if none
-
parseAmount
public static long parseAmount(java.lang.String value) throws java.lang.NumberFormatExceptionParses the amount represented by the string, without caring for the unit- Parameters:
value- the String representation of an amount of memory- Returns:
- the amount of mem in the unit represented by the potential unit char
- Throws:
java.lang.NumberFormatException- if not a number (with potential unit char stripped)
-
parseSizeInBytes
public static long parseSizeInBytes(java.lang.String value) throws java.lang.NumberFormatException, java.lang.IllegalArgumentExceptionParses the string for its content, returning the represented value in bytes- Parameters:
value- the String representation of an amount of memory- Returns:
- the amount of bytes represented by the string
- Throws:
java.lang.NumberFormatException- if not a number (with potential unit char stripped)java.lang.IllegalArgumentException- if no matching MemoryUnit matching the char
-
-