java.lang.Object
xyz.ronella.trivial.decorator.StringBuilderAppender
A decorator for StringBuilder that gives you a chance to add pre-append and post-append logic.
- Since:
- 2019-12-01
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance of StringBuilderAppender with default StringBuilder.StringBuilderAppender(String string) Accepts a StringBuilder to decorate.StringBuilderAppender(StringBuilder builder) Accepts a StringBuilder to decorate.StringBuilderAppender(StringBuilder builder, Consumer<StringBuilder> defaultBeforeAppend) Decorate the StringBuilder to have a default pre-append logic.StringBuilderAppender(StringBuilder builder, Consumer<StringBuilder> defaultBeforeAppend, Consumer<StringBuilder> defaultAfterAppend) Decorate the StringBuilder to have a default pre-append and post-append logic.StringBuilderAppender(String string, Consumer<StringBuilder> defaultBeforeAppend) Decorate the StringBuilder to have a default pre-append logic.StringBuilderAppender(String string, Consumer<StringBuilder> defaultBeforeAppend, Consumer<StringBuilder> defaultAfterAppend) Decorate the StringBuilder to have a default pre-append and post-append logic.StringBuilderAppender(Consumer<StringBuilder> defaultBeforeAppend) Creates an instance of StringBuilderAppender with default StringBuilder.StringBuilderAppender(Consumer<StringBuilder> defaultBeforeAppend, Consumer<StringBuilder> defaultAfterAppend) Creates an instance of StringBuilderAppender with default StringBuilder. -
Method Summary
Modifier and TypeMethodDescriptionPerform a normal append without any pre-append or post-append logic.Perform a normal append without any pre-append or post-append logic.append(String text, Consumer<StringBuilder> beforeAppend) Perform an append operation with pre-append logic.append(String text, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Perform an append operation with pre-append and post-append logic.append(BooleanSupplier condition, String text) Perform a normal append without any pre-append or post-append logic.append(BooleanSupplier condition, String... texts) Perform a normal append without any pre-append or post-append logic.append(BooleanSupplier condition, String text, Consumer<StringBuilder> beforeAppend) Perform an append operation with pre-append logic.append(BooleanSupplier condition, String text, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Perform an append operation with pre-append and post-append logic.append(BooleanSupplier condition, Consumer<StringBuilder> updateLogic) Ability to append using your own custom logic that this decorator cannot handle.append(BooleanSupplier condition, Consumer<StringBuilder> beforeAppend, String... texts) Perform an append operation with pre-append logic.append(BooleanSupplier condition, Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend) Ability to append using your own custom logic that this decorator cannot handle.append(BooleanSupplier condition, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend, String... texts) Perform an append operation with pre-append and post-append logic.append(BooleanSupplier condition, Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Ability to append using your own custom logic that this decorator cannot handle.append(Consumer<StringBuilder> updateLogic) Ability to append using your own custom logic that this decorator cannot handle.append(Consumer<StringBuilder> beforeAppend, String... texts) Perform an append operation with pre-append logic.append(Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend) Ability to append using your own custom logic that this decorator cannot handle.append(Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend, String... texts) Perform an append operation with pre-append and post-append logic.append(Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Ability to append using your own custom logic that this decorator cannot handle.clear()Clears the content of the target string builderAccess the internal StringBuilder that the decorator is holding.replace(CharSequence target, CharSequence replacement) Replace part of StringBuilderMake the appending task thread safe.toString()String representation of the internal StringBuilder that the decorator is holding.
-
Constructor Details
-
StringBuilderAppender
public StringBuilderAppender(StringBuilder builder, Consumer<StringBuilder> defaultBeforeAppend, Consumer<StringBuilder> defaultAfterAppend) Decorate the StringBuilder to have a default pre-append and post-append logic.- Parameters:
builder- An instance of StringBuilder.defaultBeforeAppend- The logic to perform before an append.defaultAfterAppend- The logic to perform after an append.
-
StringBuilderAppender
public StringBuilderAppender(String string, Consumer<StringBuilder> defaultBeforeAppend, Consumer<StringBuilder> defaultAfterAppend) Decorate the StringBuilder to have a default pre-append and post-append logic.- Parameters:
string- An instance of String.defaultBeforeAppend- The logic to perform before an append.defaultAfterAppend- The logic to perform after an append.- Since:
- 2.1.0
-
StringBuilderAppender
public StringBuilderAppender(Consumer<StringBuilder> defaultBeforeAppend, Consumer<StringBuilder> defaultAfterAppend) Creates an instance of StringBuilderAppender with default StringBuilder.- Parameters:
defaultBeforeAppend- The logic to perform before an append.defaultAfterAppend- The logic to perform after an append.- Since:
- 2.1.0
-
StringBuilderAppender
Decorate the StringBuilder to have a default pre-append logic.- Parameters:
builder- An instance of StringBuilder.defaultBeforeAppend- The logic to perform before an append.
-
StringBuilderAppender
Decorate the StringBuilder to have a default pre-append logic.- Parameters:
string- An instance of String.defaultBeforeAppend- The logic to perform before an append.- Since:
- 2.1.0
-
StringBuilderAppender
Creates an instance of StringBuilderAppender with default StringBuilder.- Parameters:
defaultBeforeAppend- The logic to perform before an append.- Since:
- 2.1.0
-
StringBuilderAppender
Accepts a StringBuilder to decorate.- Parameters:
builder- An instance of StringBuilder.
-
StringBuilderAppender
Accepts a StringBuilder to decorate.- Parameters:
string- An instance of String.- Since:
- 2.1.0
-
StringBuilderAppender
public StringBuilderAppender()Creates an instance of StringBuilderAppender with default StringBuilder.- Since:
- 2.1.0
-
-
Method Details
-
threadSafe
Make the appending task thread safe.- Returns:
- An instance of StringBuilderAppender.
-
append
public StringBuilderAppender append(String text, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Perform an append operation with pre-append and post-append logic. This will override the default pre-append and post-append logic.- Parameters:
text- The text to be appended.beforeAppend- The logic to perform before an append.afterAppend- The logic to perform after an append.- Returns:
- An instance of StringBuilderAppender.
-
append
public StringBuilderAppender append(BooleanSupplier condition, String text, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Perform an append operation with pre-append and post-append logic. This will override the default pre-append and post-append logic.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.text- The text to be appended.beforeAppend- The logic to perform before an append.afterAppend- The logic to perform after an append.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
Perform an append operation with pre-append logic. This will override the default pre-append logic.- Parameters:
text- The text to be appended.beforeAppend- The logic to perform before an append.- Returns:
- An instance of StringBuilderAppender.
-
append
public StringBuilderAppender append(BooleanSupplier condition, String text, Consumer<StringBuilder> beforeAppend) Perform an append operation with pre-append logic. This will override the default pre-append logic.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.text- The text to be appended.beforeAppend- The logic to perform before an append.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
Perform a normal append without any pre-append or post-append logic.- Parameters:
text- The text to be appended.- Returns:
- An instance of StringBuilderAppender.
-
append
Perform a normal append without any pre-append or post-append logic.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.text- The text to be appended.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
toString
String representation of the internal StringBuilder that the decorator is holding. The one that passed in the constructor or the one generated automatically. -
getStringBuilder
Access the internal StringBuilder that the decorator is holding.- Returns:
- An instance of StringBuilder
- Since:
- 2.0.0
-
append
public StringBuilderAppender append(Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Ability to append using your own custom logic that this decorator cannot handle.- Parameters:
updateLogic- Must hold the custom logic for appending.beforeAppend- The logic to perform before an append.afterAppend- The logic to perform after an append.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
public StringBuilderAppender append(BooleanSupplier condition, Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend) Ability to append using your own custom logic that this decorator cannot handle.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.updateLogic- Must hold the custom logic for appending.beforeAppend- The logic to perform before an append.afterAppend- The logic to perform after an append.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
public StringBuilderAppender append(Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend) Ability to append using your own custom logic that this decorator cannot handle.- Parameters:
updateLogic- Must hold the custom logic for appending.beforeAppend- The logic to perform before an append.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
public StringBuilderAppender append(BooleanSupplier condition, Consumer<StringBuilder> updateLogic, Consumer<StringBuilder> beforeAppend) Ability to append using your own custom logic that this decorator cannot handle.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.updateLogic- Must hold the custom logic for appending.beforeAppend- The logic to perform before an append.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
Ability to append using your own custom logic that this decorator cannot handle.- Parameters:
updateLogic- Must hold the custom logic for appending.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
Ability to append using your own custom logic that this decorator cannot handle.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.updateLogic- Must hold the custom logic for appending.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.0.0
-
append
public StringBuilderAppender append(Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend, String... texts) Perform an append operation with pre-append and post-append logic. This will soverride the default pre-append and post-append logic.- Parameters:
beforeAppend- The logic to perform before an append.afterAppend- The logic to perform after an append.texts- The array of texts to be appended.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.1.0
-
append
Perform an append operation with pre-append logic. This will override the default pre-append logic.- Parameters:
beforeAppend- The logic to perform before an append.texts- The array of texts to be appended.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.1.0
-
append
Perform a normal append without any pre-append or post-append logic.- Parameters:
texts- The array of texts to be appended.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.1.0
-
append
public StringBuilderAppender append(BooleanSupplier condition, Consumer<StringBuilder> beforeAppend, Consumer<StringBuilder> afterAppend, String... texts) Perform an append operation with pre-append and post-append logic. This will override the default pre-append and post-append logic.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.beforeAppend- The logic to perform before an append.afterAppend- The logic to perform after an append.texts- The array of texts to be appended.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.1.0
-
append
public StringBuilderAppender append(BooleanSupplier condition, Consumer<StringBuilder> beforeAppend, String... texts) Perform an append operation with pre-append logic. This will override the default pre-append logic.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.beforeAppend- The logic to perform before an append.texts- The array of texts to be appended.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.1.0
-
append
Perform a normal append without any pre-append or post-append logic.- Parameters:
condition- An implementation of BooleanSupplier that must return true to perform any append.texts- The array of texts to be appended.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.1.0
-
clear
Clears the content of the target string builder- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.7.0
-
replace
Replace part of StringBuilder- Parameters:
target- The target string to replacement.replacement- The replacement of the target.- Returns:
- An instance of StringBuilderAppender.
- Since:
- 2.8.0
-