Class NPESilencer<TYPE_ROOT_OBJECT,TYPE_OUTPUT>

java.lang.Object
xyz.ronella.trivial.handy.NPESilencer<TYPE_ROOT_OBJECT,TYPE_OUTPUT>
Type Parameters:
TYPE_ROOT_OBJECT - The type of the root object of the expression.
TYPE_OUTPUT - The type of output that the expression will produce.

public final class NPESilencer<TYPE_ROOT_OBJECT,TYPE_OUTPUT> extends Object
A handy class for silencing the NPE. This means if it detects a NPE was thrown from the expression then the overall expression will be null.
Since:
2.3.0
  • Method Details

    • getBuilder

      public static <TYPE_ROOT_OBJECT, TYPE_OUTPUT> NPESilencer.NPESilencerBuilder<TYPE_ROOT_OBJECT,TYPE_OUTPUT> getBuilder()
      Creates the builder of the NPESilencer.
      Type Parameters:
      TYPE_ROOT_OBJECT - The type of the root object of the expression.
      TYPE_OUTPUT - The type of output that the expression will produce.
      Returns:
      An instance of NPESilencerBuilder
    • evaluate

      public TYPE_OUTPUT evaluate()
      Evaluate all the expressions and detecting NPE.
      Returns:
      The desired output of the last expression.
    • nullable

      public static <TYPE_OUTPUT> TYPE_OUTPUT nullable(Supplier expression)
      A convenience method for evaluating a single expression (i.e. the complexity of the expression depends on how you construct it) that potentially throws an NPE.
      Type Parameters:
      TYPE_OUTPUT - The output expression.
      Parameters:
      expression - An expression that can potentially throws an NPE
      Returns:
      The output of the expression.