public static MediaSizeName findMedia(float x,float y,int units){
  MediaSize match=MediaSize.ISO.A4;
  if (x <= 0.0f || y <= 0.0f || units < 1) {
    throw new IllegalArgumentException("args must be +ve values");
  }
  double ls=x * x + y * y;
  double tmp_ls;
  float[] dim;
  float diffx=x;
  float diffy=y;
  for (int i=0; i < sizeVector.size(); i++) {
    MediaSize mediaSize=(MediaSize)sizeVector.elementAt(i);
    dim=mediaSize.getSize(units);
    if (x == dim[0] && y == dim[1]) {
      match=mediaSize;
      break;
    }
 else {
      diffx=x - dim[0];
      diffy=y - dim[1];
      tmp_ls=diffx * diffx + diffy * diffy;
      if (tmp_ls < ls) {
        ls=tmp_ls;
        match=mediaSize;
      }
    }
  }
  return match.getMediaSizeName();
}

public static MediaSizeName findMedia ( float x , float y , int units ) { MediaSize match = MediaSize . ISO . A4 ; if ( x <= 0.0f || y <= 0.0f || units < 1 ) { throw new IllegalArgumentException ( "args must be +ve values" ) ; } double ls = x * x + y * y ; double tmp_ls ; float [ ] dim ; float diffx = x ; float diffy = y ; for ( int i = 0 ; i < sizeVector . size ( ) ; i ++ ) { MediaSize mediaSize = ( MediaSize ) sizeVector . elementAt ( i ) ; dim = mediaSize . getSize ( units ) ; if ( x == dim [ 0 ] && y == dim [ 1 ] ) { match = mediaSize ; break ; } else { diffx = x - dim [ 0 ] ; diffy = y - dim [ 1 ] ; tmp_ls = diffx * diffx + diffy * diffy ; if ( tmp_ls < ls ) { ls = tmp_ls ; match = mediaSize ; } } } return match . getMediaSizeName ( ) ; }
the specified dimensions are used to locate a matching mediasize instance from amongst all the standard mediasize instances . if there is no exact match , the closest match is used . < p > the mediasize is in turn used to locate the mediasizename object . this method may return null if the closest matching mediasize has no corresponding media instance . < p > this method is useful for clients which have only dimensions and want to find a media which corresponds to the dimensions .
