@ Override public boolean add ( T elem ) { /* First, check if we're completely out of space. If so, do a resize * to ensure we do indeed have room. */ if ( size ( ) == mArrays . length * mArrays . length ) grow ( ) ; /* Compute the (arr, index) pair for the next position. The next * position is at the location indicated by size(), but we know that * space exists from the previous call. */ final int offset = computeOffset ( size ( ) ) ; final int index = computeIndex ( size ( ) ) ; /* Check if an array exists here. If not, make one up. */ if ( mArrays [ offset ] == null ) mArrays [ offset ] = ( T [ ] ) new Object [ mArrays . length ] ; /* Write the element to its location. */ mArrays [ offset ] [ index ] = elem ; /* Update the element count. */ ++ mSize ; /* Per the Collections contract, return true to signal a successful * add. */ return true ; }
Adds a new element to the HashedArrayTree .