Java Utililty Methods Null Value Convert

List of utility methods to do Null Value Convert

Description

The list of methods to do Null Value Convert are organized into topic(s).

Method

BooleanconvertNullToFalse(Boolean b)
convert Null To False
if (b == null) {
    return Boolean.FALSE;
return b;
intconvertNullToInteger(Object orgStr, int convertStr)
: convertNullToInt
if (orgStr == null) {
    return convertStr;
} else {
    return Integer.valueOf(orgStr.toString());
LongconvertNullToLong(Object orgStr, Long convertStr)
: convertNulg
if (orgStr == null || Long.parseLong(orgStr.toString()) == 0) {
    return convertStr;
} else {
    return Long.valueOf(orgStr.toString());
IntegerconvertNullToOne(final Object value)
Converts value, if null returns one
if (value == null) {
    return 1;
if (value instanceof Integer) {
    return (Integer) value;
return Integer.valueOf(value.toString());
ObjectconvertNullToSolrValue(String fieldName)
convert Null To Solr Value
Object convertedFieldValue = null;
if (isSingleValueStringOrText(fieldName)) {
    convertedFieldValue = null;
} else if (fieldName.endsWith("_dt") || fieldName.endsWith("_da")) {
    convertedFieldValue = null;
} else if (fieldName.endsWith("_d")) {
    convertedFieldValue = null;
} else if (isMultiValueStringOrText(fieldName)) {
...
StringconvertNullToString(final String str)
convert Null To String
if (str == null) {
    return "";
} else {
    final int len = str.length();
    for (int i = 0; i < len; i++) {
        if (str.charAt(i) != ' ')
            break;
    return str.trim();
ObjectconvertNullValue(final Class convertType)
convert Null Value
if ("byte".equals(convertType.getName())) {
    return (byte) 0;
} else if ("short".equals(convertType.getName())) {
    return (short) 0;
} else if ("int".equals(convertType.getName())) {
    return 0;
} else if ("long".equals(convertType.getName())) {
    return 0L;
...
Stringnull2blank(String prnStr)
nullblank
if (prnStr == null)
    return "";
else
    return prnStr;
Stringnull2blank(String source)
nullblank
return source == null ? "" : source;
booleannull2Boolean(Object expression, boolean defValue)
null Boolean
try {
    return Boolean.parseBoolean(null2String(expression));
} catch (Exception e) {
    return defValue;