private int getSize ( final String fieldType , final Object fieldValue ) { Integer fieldSize = SIMPLE_SIZES . get ( fieldType ) ; if ( fieldSize != null ) { if ( PRIMITIVE_TYPES . contains ( fieldType ) ) { return fieldSize ; } return OBJREF_SIZE + fieldSize ; } else if ( fieldValue instanceof String ) { return ( OBJREF_SIZE + OBJECT_SHELL_SIZE ) * 2 // One for the String Object itself, and one for the char[] value + INT_FIELD_SIZE * 3 // offset, count, hash + ( ( String ) fieldValue ) . length ( ) * CHAR_FIELD_SIZE ; } else if ( fieldValue != null ) { return OBJECT_SHELL_SIZE + OBJREF_SIZE ; // plus the size of any nested nodes. } else { // Null return OBJREF_SIZE ; } }
Calculates the size of a field value obtained using the reflection API .