All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.motif.f.base.NullIfEitherArgIsNull Maven / Gradle / Ivy

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);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy