no.motif.f.base.NullIfEitherArgIsNull Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of motif Show documentation
Show all versions of motif Show documentation
A library helping you to compose behavior from smaller parts.
The newest version!
package no.motif.f.base;
import no.motif.f.Fn2;
/**
* A convenient base implementation of {@link Fn2} which yields
* null
if one or both arguments is null
.
* When both arguments are non-null, they are passed to
* {@link #orElse(Object, Object)}, which
* can be implemented without any regard to possible null-pointers.
*
* @see Fn2
*/
public abstract class NullIfEitherArgIsNull implements Fn2 {
@Override
public final O $(I1 first, I2 second) {
return (first == null || second == null) ? null : orElse(first, second);
}
/**
* The function implementation.
* @param first the first function argument, guarantied not to be null
.
* @param second the second function argument, guarantied not to be null
.
* @return the function result.
*/
protected abstract O orElse(I1 first, I2 second);
}