cast a Object to a long value (primitive value type)

@param o Object to cast
@param defaultValue
@return casted long value
342048
public static long toLongValue(Object o, long defaultValue) {
	if (o instanceof Character) return (((Character) o).charValue());
	else if (o instanceof Boolean) return ((((Boolean) o).booleanValue()) ? 1L : 0L);
	else if (o instanceof Number) return (((Number) o).longValue());
	else if (o instanceof CharSequence) return (long) toDoubleValue(o.toString(), defaultValue);
	else if (o instanceof Castable) {
	    return (long) ((Castable) o).castToDoubleValue(defaultValue);
	}
	else if (o instanceof Character) return (long) (((Character) o).charValue());
	else if (o instanceof ObjectWrap) return toLongValue(((ObjectWrap) o).getEmbededObject(toLong(defaultValue)), defaultValue);

	return defaultValue;
    }
1357756
public float toFloat(float defaultValue) {
		try {
			return Float.parseFloat(sb.toString());
		} catch (java.lang.NumberFormatException e) {
		}
		return defaultValue;
	}
1099709
public static int toIntValue(Object o, int defaultValue) {

	if (o instanceof Number) return ((Number) o).intValue();
	else if (o instanceof Boolean) return ((Boolean) o).booleanValue() ? 1 : 0;
	else if (o instanceof CharSequence) return toIntValue(o.toString().trim(), defaultValue);
	// else if(o instanceof Clob) return toIntValue(toString(o));
	else if (o instanceof Character) return (int) (((Character) o).charValue());
	else if (o instanceof Castable) {
	    return (int) ((Castable) o).castToDoubleValue(defaultValue);

	}
	else if (o instanceof Date) return (int) new DateTimeImpl((Date) o).castToDoubleValue();
	else if (o instanceof ObjectWrap) return toIntValue(((ObjectWrap) o).getEmbededObject(Integer.valueOf(defaultValue)), defaultValue);

	return defaultValue;
    }
244098
public long getLongHeader(String name, long defaultValue) {
        String firstHeader = getHeader(name);
        if (firstHeader == null) {
            return defaultValue;
        }
        try {
            return Long.parseLong(firstHeader.trim());
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }
1170703
public static Float toFloat(Object o, Float defaultValue) {
	if (o instanceof Float) return (Float) o;
	if (defaultValue != null) return new Float(toFloatValue(o, defaultValue.floatValue()));

	float res = toFloatValue(o, Float.MIN_VALUE);
	if (res == Float.MIN_VALUE) return defaultValue;
	return new Float(res);
    }
191158
public static Value convertFromJava(Object o) {
        if (o instanceof Long) {
            return new NumberValue(new BigDecimal((Long) o));
        } else if (o instanceof Integer) {
            return new NumberValue(new BigDecimal((Integer) o));
        } else if (o instanceof Double) {
            return new NumberValue(new BigDecimal((Double) o));
        } else if (o instanceof Float) {
            return new NumberValue(new BigDecimal((Float) o));
        } else if (o instanceof String) {
            return new StringValue((String) o);
        } else if (o instanceof Date) {
            return new DateValue((Date) o);
        } else if (o instanceof Boolean) {
            return BooleanValue.getInstance((Boolean) o);
        } else if (o == null) {
            return NilValue.getInstance();
        }
        throw new CommandExecutionException("Could not convert Java object " + o + " to an equivalent srec value");
    }
944086
public static CellValue fromObject(final Object o) {
		if (o == null)
			return new VoidValue();
		else if (o instanceof String)
			return new StringValue((String) o);
		else if (o instanceof Number) // BigDecimal, Byte, Short, Integer,
										// Long, Float, Double
			return new FloatValue((Number) o);
		else if (o instanceof Boolean)
			return new BooleanValue((Boolean) o);
		else if (o instanceof Date) // java.util.Date & java.sql.Date,
									// java.sql.Time, java.sql.Timestamp
			return new DateValue((Date) o);
		else if (o instanceof Calendar)
			return new DateValue(((Calendar) o).getTime());
		else // Byte[], ...
			return new StringValue(o.toString());
	}
543239
public int toInt(int defaultValue) {
		try {
			return Integer.parseInt(sb.toString());
		} catch (java.lang.NumberFormatException e) {
			e.printStackTrace();
		}
		return defaultValue;
	}
730418
public static Query toQuery(Object o, Query defaultValue) {
	if (o instanceof Query) return (Query) o;
	else if (o instanceof ObjectWrap) {
	    return toQuery(((ObjectWrap) o).getEmbededObject(defaultValue), defaultValue);
	}
	return defaultValue;
    }
481065
public static Object toNull(Object value, Object defaultValue) {
	if (value == null) return null;
	if (value instanceof String && Caster.toString(value, "").trim().length() == 0) return null;
	if (value instanceof Number && ((Number) value).intValue() == 0) return null;
	return defaultValue;
    }
269062
public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) {
		return convert(BigDecimal.class, value, defaultValue);
	}
162993
public Long getParaToLong(String name, Long defaultValue) {
		return toLong(request.getParameter(name), defaultValue);
	}
716534
public Long queryLong(String paramName, Long defaultValue) {
        return this.request.queryLong(paramName, defaultValue);
    }
1139823
@Nullable
  public static <T> T defaultValue(Class<T> type) {
    // Primitives.wrap(type).cast(...) would avoid the warning, but we can't use that from here
    @SuppressWarnings("unchecked") // the put method enforces this key-value relationship
    T t = (T) DEFAULTS.get(checkNotNull(type));
    return t;
  }
990837
public static char toCharValue(Object o, char defaultValue) {
	if (o instanceof Character) return ((Character) o).charValue();
	else if (o instanceof Boolean) return (char) ((((Boolean) o).booleanValue()) ? 1 : 0);
	else if (o instanceof Double) return (char) (((Double) o).doubleValue());
	else if (o instanceof Number) return (char) (((Number) o).doubleValue());
	else if (o instanceof String) {
	    String str = o.toString();
	    if (str.length() > 0) return str.charAt(0);
	    return defaultValue;

	}
	else if (o instanceof ObjectWrap) {
	    return toCharValue(((ObjectWrap) o).getEmbededObject(toCharacter(defaultValue)), defaultValue);
	}
	else if (o == null) return toCharValue("", defaultValue);
	return defaultValue;
    }
1238006
public static long longVal(String val, long defaultValue) {
        try {
            return NumberUtils.createNumber(val).longValue();
        } catch (Exception e) {
            log.warn("longVal(String, int) throw {}, return defaultValue = {}", e, defaultValue);
            return defaultValue;
        }
    }
734798
public static Long readLong(String value, Long defaultValue) {
		if (!StringUtils.hasText(value)) return defaultValue;
		
		return Long.valueOf(value);
	}