Java Type Size sizeOfPrimitive(Object object)

Here you can find the source of sizeOfPrimitive(Object object)

Description

size Of Primitive

License

Open Source License

Declaration


private static long sizeOfPrimitive(Object object) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final Class<?> PRIMITIVE_CLASS[] = new Class[] { Byte.class, Short.class, Integer.class,
            Long.class, Float.class, Double.class, Character.class, Boolean.class };
    private static final int PRIMITIVE_SIZE[] = new int[] { 1, 2, 4, 8, 4, 8, 1, 1 };

    private static long sizeOfPrimitive(Object object) {
        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;
    }//w  w w .  j a  v a2s.c o  m
}

Related

  1. sizeOfEnumValue(T enumValue)
  2. sizeOfFloat(float f)
  3. sizeOfInt()
  4. sizeOfInt(int x)
  5. sizeOfInVarInt32(int length)
  6. sizeOfPrimitiveArray(Object object)
  7. sizeOfTreeMap(int size)
  8. sizeOfVarint(int value)
  9. sizeOfWriteLength(int len)