@ SuppressWarnings ( "unchecked" ) public < T extends Value > T getField ( final int fieldNum , final Class < T > type ) { // range check if ( fieldNum < 0 || fieldNum >= this . numFields ) { throw new IndexOutOfBoundsException ( fieldNum + " for range [0.." + ( this . numFields - 1 ) + "]" ) ; } // get offset and check for null final int offset = this . offsets [ fieldNum ] ; if ( offset == NULL_INDICATOR_OFFSET ) { return null ; } else if ( offset == MODIFIED_INDICATOR_OFFSET ) { // value that has been set is new or modified return ( T ) this . writeFields [ fieldNum ] ; } final int limit = offset + this . lengths [ fieldNum ] ; // get an instance, either from the instance cache or create a new one final Value oldField = this . readFields [ fieldNum ] ; final T field ; if ( oldField != null && oldField . getClass ( ) == type ) { field = ( T ) oldField ; } else { field = InstantiationUtil . instantiate ( type , Value . class ) ; this . readFields [ fieldNum ] = field ; } // deserialize deserialize ( field , offset , limit , fieldNum ) ; return field ; }
Gets the field at the given position from the record . This method checks internally if this instance of the record has previously returned a value for this field . If so it reuses the object if not it creates one from the supplied class .