Class CacheSizes

java.lang.Object
org.jivesoftware.util.cache.CacheSizes

public class CacheSizes extends Object
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 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

      public static int sizeOfString(String string)
      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

      public static int sizeOfMap(Map<?,?> map) throws CannotCalculateSizeException
      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

      public static int sizeOfCollection(Collection list) throws CannotCalculateSizeException
      Returns the size in bytes of a Collection object. Elements are assumed to be Strings, Longs or Cacheable 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

      public static int sizeOfAnything(Object object) throws CannotCalculateSizeException
      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