Java Utililty Methods Type Coerce

List of utility methods to do Type Coerce

Description

The list of methods to do Type Coerce are organized into topic(s).

Method

IntegercoerceTagValueInt(String tag, Object val)
coerce Tag Value Int
if (val == null)
    return null;
if (val instanceof Integer) {
    return (Integer) val;
if (!(val instanceof Number)) {
    throw new RuntimeException("Value for tag " + tag + " is not Number: " + val.getClass());
final long longVal = ((Number) val).longValue();
if (longVal < Integer.MIN_VALUE || longVal > Integer.MAX_VALUE) {
    throw new RuntimeException("Value for tag " + tag + " is not in Integer range: " + longVal);
return (int) longVal;
doublecoerceToDouble(Object o)
coerce To Double
if (o instanceof Number) {
    return ((Number) o).doubleValue();
} else {
    try {
        return Double.parseDouble(o.toString());
    } catch (NumberFormatException e) {
        return Double.NaN;
StringcoerceToEntrySize(String s)
Coerces a String into a Doom-standard 8-character format.
return coerceToEntry(s).trim();
StringcoerceToString(Object object)
coerce To String
return coerceToString(object, null);
TcoerceToType(Object objectIn, Class clazz)
coerce To Type
return coerceToType(objectIn, clazz, null);
ObjectcoerceTypes(Class clazz, Object value)
Coerce numeric types when mapping properties from nodes to entities.
if (clazz.isPrimitive() && value == null) {
    return defaultForPrimitive(clazz, value);
if (value != null) {
    String className = clazz.getName();
    if ("int".equals(className) || Integer.class.equals(clazz)) {
        if (value.getClass().equals(Long.class)) {
            Long longValue = (Long) value;
...
ObjectcoerceTypes(Class clazz, Object value)
Coerce numeric types when mapping properties from nodes to entities.
if (clazz.isPrimitive() && value == null) {
    return defaultForPrimitive(clazz, value);
if (value != null) {
    String className = clazz.getName();
    if ("int".equals(className) || Integer.class.equals(clazz)) {
        if (value.getClass().equals(Long.class)) {
            Long longValue = (Long) value;
...