Skip to content

Latest commit

 

History

History
68 lines (54 loc) · 1.67 KB

CHANGELOG.md

File metadata and controls

68 lines (54 loc) · 1.67 KB

1.0.1 (20 Jan 2022)

Enhancements

  • Add JavaDoc comments

1.0.0 (19 Jan 2022)

Philosophy

A semantic emptiness is a key concept used to indicate the absence of a value. Even if an object is not actually referenced as null, it can be considered null if it is semantically filled with empty values.

In the beginning there was...

You had to convert an empty value to null to persist it in a database. Also you had to convert null to an empty string to display it in a GUI or something elsewhere like Stream or Writer. If you don't want to use null at all, you had to write a code to getting default value/object. like this:

if (value != null && value.length() <= 0) {
    entity.setValue(null);
} else {
    entity.setValue(value);
}

or

entity.setValue(value == null || value.length() <= 0 ? null : value);

Okay, That's totally fine. But how about this?

entity.setValue(Nullify.of(value));

in some cases, you might want to use empty string("") instead of null:

Nullify.toString(value);

Further, checking for semantically empty

if (collection == null || collection.size() <= 0) {
    collection = Arrays.asList("default_value");
} else {
    boolean isSemanticallyEmpty = true;
    for (String value : collection) {
        if (value != null && value.length() > 0) {
            isSemanticallyEmpty = false;
            break;
        }
    }
    if (isSemanticallyEmpty) {
        collection = Arrays.asList("default_value");
    }
}

above code can also be replaced with:

Nullify.of(collection, Arrays.asList("default_value"));

Predicates

  • Nullify.isNull(object)
  • Nullify.isNotNull(object)