NullSafe

Null safe flow for Java and Android

License

License

GroupId

GroupId

ru.noties
ArtifactId

ArtifactId

nullsafe
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

NullSafe
Null safe flow for Java and Android
Project URL

Project URL

https://github.com/noties/NullSafe
Source Code Management

Source Code Management

https://github.com/noties/NullSafe

Download nullsafe

How to add to project

<!-- https://jarcasting.com/artifacts/ru.noties/nullsafe/ -->
<dependency>
    <groupId>ru.noties</groupId>
    <artifactId>nullsafe</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/ru.noties/nullsafe/
implementation 'ru.noties:nullsafe:1.0.0'
// https://jarcasting.com/artifacts/ru.noties/nullsafe/
implementation ("ru.noties:nullsafe:1.0.0")
'ru.noties:nullsafe:jar:1.0.0'
<dependency org="ru.noties" name="nullsafe" rev="1.0.0">
  <artifact name="nullsafe" type="jar" />
</dependency>
@Grapes(
@Grab(group='ru.noties', module='nullsafe', version='1.0.0')
)
libraryDependencies += "ru.noties" % "nullsafe" % "1.0.0"
[ru.noties/nullsafe "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.android.support » support-annotations jar 26.0.2

Project Modules

There are no modules declared in this project.

NullSafe

Maven Central

Null safe flow for Java.

Java8:

// `country` can be null, meaning that no mapping will occur and "Unknown" will be returned
final String name = NullSafe.create(country)
        .map(Country::city) // map function will never call Supplier with null argument
        .map(City::street)
        .map(Street::name)
        .get("Unknown");
final City capitalCity = capitalCity();

final String name = NullSafe.create(country)
        .map(capitalCity, Country::city) // allows to specify def values (cannot be null)
        .map(City::street)
        .map(Street::name)
        .get("Unknown");
// NullSafe instance can be used to split the flow (safe to reference intermediate state)

final NullSafe<City> nullSafe = NullSafe.create(country)
        .map(capitalCity, Country::city);

final String name = nullSafe
        .map(City::street)
        .map(Street::name)
        .get(); // <- returns nullable if no def value was specified

final House house = nullSafe
        .map(City::street)
        .map(Street::house)
        .get();

This utility class is not thread-safe

Versions

Version
1.0.0