Java Utililty Methods Type Size

List of utility methods to do Type Size

Description

The list of methods to do Type Size are organized into topic(s).

Method

intsizeOfBinary(int maximumNumber)
size Of Binary
return (Long.toBinaryString((long) maximumNumber) + "").length();
intsizeOfCompactInt(int i)
size Of Compact Int
i = Math.abs(i);
if (i >= 1 << (6 + 7 + 7 + 7))
    return 5;
else if (i >= 1 << (6 + 7 + 7))
    return 4;
else if (i >= 1 << (6 + 7))
    return 3;
else if (i >= 1 << (6))
...
intsizeOfEnumValue(T enumValue)
size Of Enum Value
return sizeOfString(enumValue.toString());
intsizeOfFloat(float f)
size Of Float
return Float.floatToIntBits(f) / Byte.SIZE;
intsizeOfInt()
size Of Int
return 4;
intsizeOfInt(int x)
calculate the size of an integer number
for (int i = 0;; i++)
    if (x <= SIZE_TABLE[i]) {
        return i + 1;
intsizeOfInVarInt32(int length)
Compute the space needed to encode the length in BER code.
if (length < (1 << 7)) {
    return 1;
if (length < (1 << 14)) {
    return 2;
if (length < (1 << 21)) {
    return 3;
...
longsizeOfPrimitive(Object object)
size Of Primitive
if (object instanceof String)
    return ((String) object).getBytes().length;
for (int i = 0; i < PRIMITIVE_CLASS.length; i++)
    if (object.getClass() == PRIMITIVE_CLASS[i])
        return PRIMITIVE_SIZE[i];
return 0;
longsizeOfPrimitiveArray(Object object)
size Of Primitive Array
long total = 0L;
if (object instanceof Byte[]) {
    for (Byte b : (Byte[]) object)
        if (b != null)
            total += 1;
else if (object instanceof Short[]) {
    for (Short s : (Short[]) object)
...
intsizeOfTreeMap(int size)
size Of Tree Map
return TREE_MAP_SIZE + (OBJECT_SIZE + INT_SIZE + POINTER_SIZE * 5) * size;