Class LordOfTheStrings.StatementBuilder

java.lang.Object
org.springframework.data.javapoet.LordOfTheStrings.StatementBuilder
Enclosing class:
LordOfTheStrings

public static class LordOfTheStrings.StatementBuilder extends Object
Builder for creating statements including conditional and concatenated variants.

This builder allows for the creation of complex statements with conditional logic and concatenated elements. It is designed to simplify the construction of dynamic code blocks.

Use this builder to handle conditional inclusion in a structured and fluent manner instead of excessive conditional nesting that would be required otherwise in the calling code.

  • Method Details

    • isEmpty

      public boolean isEmpty()
      Determine whether this builder is empty.
      Returns:
      true if the builder is empty; false otherwise.
    • when

      Add a conditional statement to the builder if the condition is met.
      Parameters:
      state - the condition to evaluate.
      Returns:
      a LordOfTheStrings.StatementBuilder.ConditionalStatementStep for further configuration.
    • whenNot

      Add a conditional statement to the builder if the condition is not met.
      Parameters:
      state - the condition to evaluate.
      Returns:
      a LordOfTheStrings.StatementBuilder.ConditionalStatementStep for further configuration.
    • add

      @Contract("_, _ -> this") public LordOfTheStrings.StatementBuilder add(String format, @Nullable Object... args)
      Add a formatted statement to the builder.
      Parameters:
      format - the format string.
      args - the arguments for the format string.
      Returns:
      this builder.
    • add

      @Contract("null -> fail; _ -> this") public LordOfTheStrings.StatementBuilder add(org.springframework.javapoet.CodeBlock codeBlock)
      Add a CodeBlock to the statement builder.
      Parameters:
      codeBlock - the code block to add.
      Returns:
      this builder.
    • addAll

      @Contract("null, _ -> fail; _, _ -> this") public <T> LordOfTheStrings.StatementBuilder addAll(Iterable<? extends T> elements, String delim, Function<? super T,org.springframework.javapoet.CodeBlock> mapper)
      Concatenate elements into the builder with a delimiter.
      Type Parameters:
      T - the type of the elements.
      Parameters:
      elements - the elements to concatenate.
      delim - the delimiter to use between elements.
      mapper - the mapping function to apply to each element returning a CodeBlock to add.
      Returns:
      this builder.
    • addAll

      @Contract("null, _, _ -> fail; _, _, _ -> this") public <T> LordOfTheStrings.StatementBuilder addAll(Iterable<? extends T> elements, Function<? super T,String> delim, Function<? super T,org.springframework.javapoet.CodeBlock> mapper)
      Concatenate elements into the builder with a custom delimiter function.
      Type Parameters:
      T - the type of the elements.
      Parameters:
      elements - the elements to concatenate.
      delim - the function to determine the delimiter for each element. Delimiters are applied beginning with the second iteration element and obtain from the current element.
      mapper - the mapping function to apply to each element returning a CodeBlock to add.
      Returns:
      this builder.