code: public static int toInt(Object val) {
          if (val == null) { return 0; }
          if (val instanceof Number) {
              return ((Number) val).intValue();
          }
          if (val instanceof String) {
              return Integer.parseInt((String) val);
          }
          
          throw new IllegalArgumentException("Cannot convert " + val);
      }
docs: Converts the parameter to an integer value, if possible.
  Throws an IllegalArgumentException if the parameter cannot be converted to an integer.
  
  @param val the parameter to be converted. May be a String, a number or null. Everything else causes an {@link IllegalArgumentException} to be thrown.
  @return the integer value. 0 if the parameter is null.