Class LordOfTheStrings.StatementBuilder
java.lang.Object
org.springframework.data.javapoet.LordOfTheStrings.StatementBuilder
- Enclosing class:
- LordOfTheStrings
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for conditional statement steps. -
Method Summary
Modifier and TypeMethodDescriptionAdd a formatted statement to the builder.add(org.springframework.javapoet.CodeBlock codeBlock) Add aCodeBlockto the statement builder.addAll(Iterable<? extends T> elements, String delim, Function<? super T, org.springframework.javapoet.CodeBlock> mapper) Concatenate elements into the builder with a delimiter.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.booleanisEmpty()Determine whether this builder is empty.when(boolean state) Add a conditional statement to the builder if the condition is met.whenNot(boolean state) Add a conditional statement to the builder if the condition is not met.
-
Method Details
-
isEmpty
public boolean isEmpty()Determine whether this builder is empty.- Returns:
trueif the builder is empty;falseotherwise.
-
when
Add a conditional statement to the builder if the condition is met.- Parameters:
state- the condition to evaluate.- Returns:
- a
LordOfTheStrings.StatementBuilder.ConditionalStatementStepfor 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.ConditionalStatementStepfor 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:
thisbuilder.
-
add
@Contract("null -> fail; _ -> this") public LordOfTheStrings.StatementBuilder add(org.springframework.javapoet.CodeBlock codeBlock) Add aCodeBlockto the statement builder.- Parameters:
codeBlock- the code block to add.- Returns:
thisbuilder.
-
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 aCodeBlockto add.- Returns:
thisbuilder.
-
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 aCodeBlockto add.- Returns:
thisbuilder.
-