public static int sizeOfCollection(Collection list) 
            throws CannotCalculateSizeException {
        if (list == null) {
            return 0;
        }
        // Base list object (approximate)
        int size = 36;
        // Add in size of each value
        Object[] values = list.toArray();
        for (int i = 0; i < values.length; i++) {
            size += sizeOfAnything(values[i]);
        }
        return size;
    }
Returns the size in bytes of a Collection object. Elements are assumed to be
{@code String}s, {@code Long}s or {@code Cacheable} objects.

@param list the Collection object to determine the size of.
@return the size of the Collection object.
@throws CannotCalculateSizeException if the size cannot be calculated
xmppserver/src/main/java/org/jivesoftware/util/cache/CacheSizes.java