Package org.jivesoftware.util.cache
Class CacheSizes
java.lang.Object
org.jivesoftware.util.cache.CacheSizes
Utility class for determining the sizes in bytes of commonly used objects.
Classes implementing the Cacheable interface should use this class to
determine their size.
- Author:
- Matt Tucker
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
sizeOfAnything
(Object object) Returns the size of an object in bytes.static int
Returns the size in bytes of a primitive boolean.static int
Returns the size in bytes of a primitive char.static int
sizeOfCollection
(Collection list) Returns the size in bytes of a Collection object.static int
Returns the size in bytes of a Date.static int
Returns the size in bytes of a primitive double.static int
Returns the size in bytes of a primitive int.static int
Returns the size in bytes of a primitive long.static int
Returns the size in bytes of a Map object.static int
Returns the size in bytes of a basic Object.static int
sizeOfString
(String string) Returns the size in bytes of a String.
-
Constructor Details
-
CacheSizes
public CacheSizes()
-
-
Method Details
-
sizeOfObject
public static int sizeOfObject()Returns the size in bytes of a basic Object. This method should only be used for actual Object objects and not classes that extend Object.- Returns:
- the size of an Object.
-
sizeOfString
Returns the size in bytes of a String.- Parameters:
string
- the String to determine the size of.- Returns:
- the size of a String.
-
sizeOfInt
public static int sizeOfInt()Returns the size in bytes of a primitive int.- Returns:
- the size of a primitive int.
-
sizeOfChar
public static int sizeOfChar()Returns the size in bytes of a primitive char.- Returns:
- the size of a primitive char.
-
sizeOfBoolean
public static int sizeOfBoolean()Returns the size in bytes of a primitive boolean.- Returns:
- the size of a primitive boolean.
-
sizeOfLong
public static int sizeOfLong()Returns the size in bytes of a primitive long.- Returns:
- the size of a primitive long.
-
sizeOfDouble
public static int sizeOfDouble()Returns the size in bytes of a primitive double.- Returns:
- the size of a primitive double.
-
sizeOfDate
public static int sizeOfDate()Returns the size in bytes of a Date.- Returns:
- the size of a Date.
-
sizeOfMap
Returns the size in bytes of a Map object.- Parameters:
map
- the Map object to determine the size of.- Returns:
- the size of the Map object.
- Throws:
CannotCalculateSizeException
- if the size cannot be calculated
-
sizeOfCollection
Returns the size in bytes of a Collection object. Elements are assumed to beString
s,Long
s orCacheable
objects.- Parameters:
list
- the Collection object to determine the size of.- Returns:
- the size of the Collection object.
- Throws:
CannotCalculateSizeException
- if the size cannot be calculated
-
sizeOfAnything
Returns the size of an object in bytes. Determining size by serialization is only used as a last resort.- Parameters:
object
- the object to calculate the size of- Returns:
- the size of an object in bytes.
- Throws:
CannotCalculateSizeException
- if the size cannot be calculated
-