Nullify
for null representations and assertions of objects.
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.
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);
entity.setValue(Nullify.of(value));
in some cases, you might want to use empty string(""
) instead of null
:
Nullify.toString(value);
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"));
Nullify.isNull(object)
Nullify.isNotNull(object)
<dependency>
<groupId>org.silentsoft</groupId>
<artifactId>nullify</artifactId>
<version>1.0.1</version>
</dependency>
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please note we have a CODE_OF_CONDUCT, please follow it in all your interactions with the project.
Please refer to LICENSE.