Skip to content

Nullify for null representations and assertions of objects.

License

Notifications You must be signed in to change notification settings

silentsoft/nullify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nullify

Maven Central Build Status Quality Gate Status Coverage Hits

Nullify for null representations and assertions of objects.

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)

Maven Central

<dependency>
    <groupId>org.silentsoft</groupId>
    <artifactId>nullify</artifactId>
    <version>1.0.1</version>
</dependency>

Contributing

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.

License

Please refer to LICENSE.

About

Nullify for null representations and assertions of objects.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages