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 Details

    • number

      @Contract("_ -> this") public LordOfTheStrings.TypedReturnBuilder number(String resultToReturn)
      Add return statements for numeric types if the given resultToReturn points to a Number. Considers primitive and boxed int and long type return paths and that resultToReturn can be null.
      Parameters:
      resultToReturn - the argument or variable name holding the result.
      Returns:
      this builder.
    • nonNullableNumber

      @Contract("_ -> this") public LordOfTheStrings.TypedReturnBuilder nonNullableNumber(String resultToReturn)
      Add return statements for numeric types if the given resultToReturn points to a non-nullable Number. Considers all primitive numeric types assuming that resultToReturn is never null.
      Parameters:
      resultToReturn - the argument or variable name holding the result.
      Returns:
      this builder.
    • 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:
      this builder.
    • whenBoxedLong

      @Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenBoxedLong(String format, @Nullable Object... args)
      Add a return statement if the return type is Long (boxed long type).
      Parameters:
      format - the code format string.
      args - the format arguments.
      Returns:
      this builder.
    • whenLong

      @Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenLong(String format, @Nullable Object... args)
      Add a return statement if the return type is a primitive long type.
      Parameters:
      format - the code format string.
      args - the format arguments.
      Returns:
      this builder.
    • whenBoxedInteger

      @Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenBoxedInteger(String format, @Nullable Object... args)
      Add a return statement if the return type is Integer (boxed int type).
      Parameters:
      format - the code format string.
      args - the format arguments.
      Returns:
      this builder.
    • whenInt

      @Contract("_, _ -> this") public LordOfTheStrings.TypedReturnBuilder whenInt(String format, @Nullable Object... args)
      Add a return statement if the return type is a primitive int type.
      Parameters:
      format - the code format string.
      args - the format arguments.
      Returns:
      this builder.
    • 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:
      this builder.
    • 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:
      this builder.
    • 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 given returnType.
      Parameters:
      returnType - the candidate return type.
      format - the code format string.
      args - the format arguments
      Returns:
      this builder.
    • when

      @Contract("_, _, _ -> this") public LordOfTheStrings.TypedReturnBuilder when(boolean condition, String format, @Nullable Object... args)
      Add a return statement if the given condition is true.
      Overrides:
      when in class LordOfTheStrings.ReturnBuilderSupport
      Parameters:
      condition - the condition to evaluate.
      format - the code format string.
      args - the format arguments.
      Returns:
      this builder.
    • 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 conditionally Optional.ofNullable(Object) wrapping if the return type is Optional.
      Parameters:
      codeBlock - the code block result to be returned.
      Returns:
      this builder.
    • 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 conditionally Optional.ofNullable(Object) wrapping if the return type is Optional.
      Parameters:
      format - the code format string.
      args - the format arguments.
      Returns:
      this builder.
    • 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:
      this builder.
    • 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:
      otherwise in class LordOfTheStrings.ReturnBuilderSupport
      Parameters:
      format - the code format string.
      args - the format arguments.
      Returns:
      this builder.