Class LordOfTheStrings.TypedReturnBuilder
java.lang.Object
org.springframework.data.javapoet.LordOfTheStrings.ReturnBuilderSupport
org.springframework.data.javapoet.LordOfTheStrings.TypedReturnBuilder
- Enclosing class:
LordOfTheStrings
public static class LordOfTheStrings.TypedReturnBuilder
extends LordOfTheStrings.ReturnBuilderSupport
Builder for constructing return statements based conditionally on the target return type. The resulting
CodeBlock must be added as a CodeBlock.Builder.addStatement(CodeBlock).- Since:
- 4.0
- Author:
- Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptionnonNullableNumber(String resultToReturn) Add return statements for numeric types if the givenresultToReturnpoints to a non-nullableNumber.Add return statements for numeric types if the givenresultToReturnpoints to aNumber.Add a fallback return statement considering that the returned value might be nullable and apply conditionallyOptional.ofNullable(Object)wrapping if the return type isOptional.optional(org.springframework.javapoet.CodeBlock codeBlock) Add a fallback return statement considering that the returned value might be nullable and apply conditionallyOptional.ofNullable(Object)wrapping if the return type isOptional.Add a fallback return statement if no previous return statement was added.otherwise(org.springframework.javapoet.CodeBlock codeBlock) Add a fallback return statement if no previous return statement was added.Add a return statement if the given condition istrue.Add a return statement if the declared return type is assignable from the givenreturnType.whenBoolean(String format, @Nullable Object... args) Add a return statement if the return type is boolean (primitive or box type).Add a return statement if the return type matches the given boxed wrapper type.whenBoxedInteger(String format, @Nullable Object... args) Add a return statement if the return type isInteger(boxedinttype).whenBoxedLong(String format, @Nullable Object... args) Add a return statement if the return type isLong(boxedlongtype).Add a return statement if the return type is a primitiveinttype.Add a return statement if the return type is a primitivelongtype.whenPrimitiveOrBoxed(Class<?> primitiveType, String format, @Nullable Object... args) Add a return statement if the return type matches the given primitive or boxed wrapper type.Methods inherited from class LordOfTheStrings.ReturnBuilderSupport
build
-
Method Details
-
number
Add return statements for numeric types if the givenresultToReturnpoints to aNumber. Considers primitive and boxedintandlongtype return paths and thatresultToReturncan be null.- Parameters:
resultToReturn- the argument or variable name holding the result.- Returns:
thisbuilder.
-
nonNullableNumber
@Contract("_ -> this") public LordOfTheStrings.TypedReturnBuilder nonNullableNumber(String resultToReturn) Add return statements for numeric types if the givenresultToReturnpoints to a non-nullableNumber. Considers all primitive numeric types assuming thatresultToReturnis never null.- Parameters:
resultToReturn- the argument or variable name holding the result.- Returns:
thisbuilder.
-
whenBoolean
@Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenBoolean(String format, @Nullable Object... args) Add a return statement if the return type is boolean (primitive or box type).- Parameters:
format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
whenBoxedLong
@Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenBoxedLong(String format, @Nullable Object... args) Add a return statement if the return type isLong(boxedlongtype).- Parameters:
format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
whenLong
@Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenLong(String format, @Nullable Object... args) Add a return statement if the return type is a primitivelongtype.- Parameters:
format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
whenBoxedInteger
@Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenBoxedInteger(String format, @Nullable Object... args) Add a return statement if the return type isInteger(boxedinttype).- Parameters:
format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
whenInt
@Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenInt(String format, @Nullable Object... args) Add a return statement if the return type is a primitiveinttype.- Parameters:
format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
whenBoxed
@Contract("null, _, _ -> fail; _, _, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenBoxed(Class<?> primitiveOrWrapper, String format, @Nullable Object... args) Add a return statement if the return type matches the given boxed wrapper type.- Parameters:
primitiveOrWrapper- the primitive or wrapper type.format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
whenPrimitiveOrBoxed
@Contract("null, _, _ -> fail; _, _, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenPrimitiveOrBoxed(Class<?> primitiveType, String format, @Nullable Object... args) Add a return statement if the return type matches the given primitive or boxed wrapper type.- Parameters:
primitiveType- the primitive or wrapper type.format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
when
@Contract("null, _, _ -> fail; _, _, _ -> this") public LordOfTheStrings.TypedReturnBuilder when(Class<?> returnType, String format, @Nullable Object... args) Add a return statement if the declared return type is assignable from the givenreturnType.- Parameters:
returnType- the candidate return type.format- the code format string.args- the format arguments- Returns:
thisbuilder.
-
when
@Contract("_, _, _ -> this") public LordOfTheStrings.TypedReturnBuilder when(boolean condition, String format, @Nullable Object... args) Add a return statement if the given condition istrue.- Overrides:
whenin classLordOfTheStrings.ReturnBuilderSupport- Parameters:
condition- the condition to evaluate.format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
optional
@Contract("_ -> this") public LordOfTheStrings.TypedReturnBuilder optional(org.springframework.javapoet.CodeBlock codeBlock) Add a fallback return statement considering that the returned value might be nullable and apply conditionallyOptional.ofNullable(Object)wrapping if the return type isOptional.- Parameters:
codeBlock- the code block result to be returned.- Returns:
thisbuilder.
-
optional
@Contract("null, _ -> fail; _, _ -> this") public LordOfTheStrings.TypedReturnBuilder optional(String format, @Nullable Object... args) Add a fallback return statement considering that the returned value might be nullable and apply conditionallyOptional.ofNullable(Object)wrapping if the return type isOptional.- Parameters:
format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-
otherwise
@Contract("_ -> this") public LordOfTheStrings.TypedReturnBuilder otherwise(org.springframework.javapoet.CodeBlock codeBlock) Add a fallback return statement if no previous return statement was added.- Parameters:
codeBlock- the code block result to be returned.- Returns:
thisbuilder.
-
otherwise
@Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder otherwise(String format, @Nullable Object... args) Add a fallback return statement if no previous return statement was added.- Overrides:
otherwisein classLordOfTheStrings.ReturnBuilderSupport- Parameters:
format- the code format string.args- the format arguments.- Returns:
thisbuilder.
-