Class Null

java.lang.Object
com.ontology2.pidove.util.Null

public class Null extends Object
Functions for handling nulls
  • Constructor Details

    • Null

      public Null()
  • Method Details

    • coalesce

      public static <X> X coalesce(X a, X b)
      Null coalescing operator returns the first argument that isn't null or null if all arguments are null.
      Type Parameters:
      X - the return data type
      Parameters:
      a - a value of type a
      b - a value of type b
      Returns:
      a if a is not null otherwise b
    • coalesce

      public static <X> X coalesce(X a, X b, X c)
    • coalesce

      @SafeVarargs public static <X> X coalesce(X a, X b, X c, X... d)
      Null coalescing operator Since all the values are the same type this can be implemented for an arbitrary number of values with varargs
      Type Parameters:
      X - the returned data type
      Parameters:
      a - first value
      b - second value
      c - third value
      d - more arguments...
      Returns:
      the first non-null value.
    • safe

      public static <X, Y> Y safe(X x, Function<X,Y> f1)
      Safe navigation operator. If x is null returns null, otherwise applies f1 to x. Longer variants apply any functions that occur in later arguments, doing the null check each time.
      Type Parameters:
      X - input type
      Y - output type
      Parameters:
      x - input value
      f1 - function that can be applied to x
      Returns:
      null if x is null, otherwise f(x).
    • safe0

      public static <X> void safe0(X x, Consumer<X> f1)
      Safe navigation operator. If x is null does nothing. If x is not null, makes f1 accept x. Longer variants apply functions in series if the result is not null, finally making the Consumer passed as the last argument accepting that result if it is not null
      Type Parameters:
      X - input type
      Parameters:
      x - input value
      f1 - consumer that can accept x
    • safe

      public static <X, Y, Z> Z safe(X x, Function<X,Y> f1, Function<Y,Z> f2)
    • safe0

      public static <X, Y> void safe0(X x, Function<X,Y> f1, Consumer<Y> c)
    • safe

      public static <X, Y, Z, ZZ> ZZ safe(X x, Function<X,Y> f1, Function<Y,Z> f2, Function<Z,ZZ> f3)
    • safe0

      public static <X, Y, Z> void safe0(X x, Function<X,Y> f1, Function<Y,Z> f2, Consumer<Z> f3)