Module xyz.ronella.casual.trivial
Package xyz.ronella.trivial.handy
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.
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe only class that can create NPESilencer. -
Method Summary
Modifier and TypeMethodDescriptionevaluate()Evaluate all the expressions and detecting NPE.static <TYPE_ROOT_OBJECT,TYPE_OUTPUT>
NPESilencer.NPESilencerBuilder<TYPE_ROOT_OBJECT,TYPE_OUTPUT> Creates the builder of the NPESilencer.static <TYPE_OUTPUT>
TYPE_OUTPUTA convenience method for evaluating a single expression (i.e.
-
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
Evaluate all the expressions and detecting NPE.- Returns:
- The desired output of the last expression.
-
nullable
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.
-