code: public long toLong(Object val) {
      if (val == null) {
        return 0L;
      }
      else if (val instanceof Double) {
        if (!Double.isNaN(((Double) val).doubleValue())) {
          return 0;
        }
        else {
          return ((Double) val).longValue();
        }
      }
      else if (val instanceof Number) {
        return ((Number) val).longValue();
      }
      else if (val instanceof String) {
        if ("".equals(val)) {
          return 0;
        }
        else {
          return Long.parseLong((String) val);
        }
      }
      else if (val instanceof Boolean) {
        return ((Boolean) val).booleanValue() ? 1L : 0L;
      }
      else if (val instanceof Character) {
        return ((Character) val).charValue();
      }
  
      throw new ArithmeticException("Long coercion: " + val.getClass().getName() + ":(" + val + ")");
    }
docs: Coerce to a long (not a java.lang.Long).
  
  @param val
  Object to be coerced.
  @return The long coerced value.