question: public static MediaSizeName findMedia ( Media [ ] media , float x , float y , int units ) { if ( x <= 0.0f || y <= 0.0f || units < 1 ) { throw new IllegalArgumentException ( "args must be +ve values" ) ; } if ( media == null || media . length == 0 ) { throw new IllegalArgumentException ( "args must have valid array of media" ) ; } int size = 0 ; MediaSizeName [ ] msn = new MediaSizeName [ media . length ] ; for ( int i = 0 ; i < media . length ; i ++ ) { if ( media [ i ] instanceof MediaSizeName ) { msn [ size ++ ] = ( MediaSizeName ) media [ i ] ; } } if ( size == 0 ) { return null ; } int match = 0 ; double ls = x * x + y * y ; double tmp_ls ; float [ ] dim ; float diffx = x ; float diffy = y ; for ( int i = 0 ; i < size ; i ++ ) { MediaSize mediaSize = MediaSize . getMediaSizeForName ( msn [ i ] ) ; if ( mediaSize == null ) { continue ; } dim = mediaSize . getSize ( units ) ; if ( x == dim [ 0 ] && y == dim [ 1 ] ) { match = i ; break ; } else { diffx = x - dim [ 0 ] ; diffy = y - dim [ 1 ] ; tmp_ls = diffx * diffx + diffy * diffy ; if ( tmp_ls < ls ) { ls = tmp_ls ; match = i ; } } } return msn [ match ] ; }
target:  Returns closest matching MediaSizeName among given array of Media