code: public int toInteger(Object val) {
      if (val == null) {
        return 0;
      }
      else if (val instanceof Double) {
        if (!Double.isNaN(((Double) val).doubleValue())) {
          return 0;
        }
        else {
          return ((Double) val).intValue();
        }
      }
      else if (val instanceof Number) {
        return ((Number) val).intValue();
      }
      else if (val instanceof String) {
        if ("".equals(val)) {
          return 0;
        }
        return Integer.parseInt((String) val);
      }
      else if (val instanceof Boolean) {
        return ((Boolean) val).booleanValue() ? 1 : 0;
      }
      else if (val instanceof Character) {
        return ((Character) val).charValue();
      }
  
      throw new ArithmeticException("Integer coercion: " + val.getClass().getName() + ":(" + val + ")");
    }
docs: Coerce to a int.
  
  @param val
  Object to be coerced.
  @return The int coerced value.