@@ -858,10 +858,37 @@ public static class TypedReturnBuilder extends ReturnBuilderSupport {
858
858
*/
859
859
@ Contract ("_ -> this" )
860
860
public TypedReturnBuilder number (String resultToReturn ) {
861
+
861
862
return whenBoxedLong ("$1L != null ? $1L.longValue() : null" , resultToReturn )
862
863
.whenLong ("$1L != null ? $1L.longValue() : 0L" , resultToReturn )
863
864
.whenBoxedInteger ("$1L != null ? $1L.intValue() : null" , resultToReturn )
864
- .whenInt ("$1L != null ? $1L.intValue() : 0" , resultToReturn );
865
+ .whenInt ("$1L != null ? $1L.intValue() : 0" , resultToReturn )
866
+ .whenBoxed (Byte .class , "$1L != null ? $1L.byteValue() : null" , resultToReturn )
867
+ .when (byte .class , "$1L != null ? $1L.byteValue() : 0" , resultToReturn )
868
+ .whenBoxed (Short .class , "$1L != null ? $1L.shortValue() : null" , resultToReturn )
869
+ .when (short .class , "$1L != null ? $1L.shortValue() : 0" , resultToReturn )
870
+ .whenBoxed (Double .class , "$1L != null ? $1L.doubleValue() : null" , resultToReturn )
871
+ .when (double .class , "$1L != null ? $1L.doubleValue() : 0" , resultToReturn )
872
+ .whenBoxed (Float .class , "$1L != null ? $1L.floatValue() : null" , resultToReturn )
873
+ .when (float .class , "$1L != null ? $1L.floatValue() : 0f" , resultToReturn );
874
+ }
875
+
876
+ /**
877
+ * Add return statements for numeric types if the given {@code resultToReturn} points to a non-nullable
878
+ * {@link Number}. Considers all primitive numeric types assuming that {@code resultToReturn} is never
879
+ * {@literal null}.
880
+ *
881
+ * @param resultToReturn the argument or variable name holding the result.
882
+ * @return {@code this} builder.
883
+ */
884
+ @ Contract ("_ -> this" )
885
+ public TypedReturnBuilder nonNullableNumber (String resultToReturn ) {
886
+ return whenPrimitiveOrBoxed (long .class , "$1L.longValue()" , resultToReturn )
887
+ .whenPrimitiveOrBoxed (int .class , "$1L.intValue()" , resultToReturn )
888
+ .whenPrimitiveOrBoxed (short .class , "$1L.shortValue()" , resultToReturn )
889
+ .whenPrimitiveOrBoxed (byte .class , "$1L.byteValue()" , resultToReturn )
890
+ .whenPrimitiveOrBoxed (float .class , "$1L.floatValue()" , resultToReturn )
891
+ .whenPrimitiveOrBoxed (double .class , "$1L.doubleValue()" , resultToReturn );
865
892
}
866
893
867
894
/**
0 commit comments