/**
   * 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.
   *
   * @param x - X dimension
   * @param y - Y dimension.
   * @param units Unit conversion factor, e.g. <CODE>Size2DSyntax.INCH</CODE> or <CODE>
   *     Size2DSyntax.MM</CODE>
   * @return MediaSizeName matching these dimensions, or null.
   * @exception IllegalArgumentException if x <= 0, y <= 0, or units < 1
   */
  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();
  }