ehcache

net.sf.ehcache.config
Enum MemoryUnit

java.lang.Object
  extended by java.lang.Enum<MemoryUnit>
      extended by net.sf.ehcache.config.MemoryUnit
All Implemented Interfaces:
Serializable, Comparable<MemoryUnit>

public enum MemoryUnit
extends Enum<MemoryUnit>

Memory unit: byte-based

Author:
Alex Snaps

Enum Constant Summary
BYTES
          BYTES
GIGABYTES
          GIGABYTES (1024 MEGABYTES)
KILOBYTES
          KILOBYTES (1024 BYTES)
MEGABYTES
          MEGABYTES (1024 KILOBYTES)
 
Method Summary
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.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

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(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:
IllegalArgumentException - if this enum type has no constant with the specified name
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 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 IllegalArgumentException
Returns the MemoryUnit instance based on provided char

Parameters:
unit - the unit to look for
Returns:
the MemoryUnit instance matching the unit
Throws:
IllegalArgumentException - if no matching MemoryUnit matching the char

parseUnit

public static MemoryUnit parseUnit(String value)
Parses the unit part of a String, if no unit char available, returns BYTES

Parameters:
value - the String representation of an amount of memory
Returns:
the MemoryUnit instance, or BYTES if none

parseAmount

public static long parseAmount(String value)
                        throws NumberFormatException
Parses 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:
NumberFormatException - if not a number (with potential unit char stripped)

parseSizeInBytes

public static long parseSizeInBytes(String value)
                             throws NumberFormatException,
                                    IllegalArgumentException
Parses 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:
NumberFormatException - if not a number (with potential unit char stripped)
IllegalArgumentException - if no matching MemoryUnit matching the char

ehcache

Copyright 2001-2015, Terracotta, Inc.