Package com.helger.base.string
Class StringImplode.ImploderBuilder
java.lang.Object
com.helger.base.string.StringImplode.ImploderBuilder
- Enclosing class:
StringImplode
A simple builder that allows to implode collections of arguments with a lot of customization.
It used by all the "getImploded*" overloads and fulfills the requests of other use cases as
well.
- Since:
- 10.0.0
- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull Stringbuild()Build the imploded string from the configured source, separator, offset, length, and filter.@NonNull StringImplode.ImploderBuilderSet a custom filter predicate for source elements.@NonNull StringImplode.ImploderBuilderSet the filter to only include non-nulland non-empty source elements.@NonNull StringImplode.ImploderBuilderlength(int n) Set the number of source items to iterate, depending on the source offset.@NonNull StringImplode.ImploderBuilderoffset(int n) Set an offset of the source from which to start.@NonNull StringImplode.ImploderBuilderseparator(char c) Set the separator character to use between elements.@NonNull StringImplode.ImploderBuilderSet the separator string to use between elements.final <T> @NonNull StringImplode.ImploderBuildersource(@Nullable T... a) Set the source elements from a generic array, converting each element to a string viaObject.toString().<T> @NonNull StringImplode.ImploderBuilderSet the source elements from a generic array, converting each element using the provided mapper function.@NonNull StringImplode.ImploderBuilderSet the source elements from a string array.@NonNull StringImplode.ImploderBuildersource(@Nullable Collection<?> a) Set the source elements from a collection, converting each element to a string viaObject.toString().<T> @NonNull StringImplode.ImploderBuildersource(@Nullable Collection<T> a, @NonNull Function<? super T, String> aMapper) Set the source elements from a collection, converting each element using the provided mapper function.
-
Constructor Details
-
ImploderBuilder
public ImploderBuilder()Constructor.
-
-
Method Details
-
source
Set the source elements from a collection, converting each element to a string viaObject.toString().- Parameters:
a- The source collection. May benull.- Returns:
- this for chaining
-
source
public <T> @NonNull StringImplode.ImploderBuilder source(@Nullable Collection<T> a, @NonNull Function<? super T, String> aMapper) Set the source elements from a collection, converting each element using the provided mapper function.- Type Parameters:
T- The element type of the source collection- Parameters:
a- The source collection. May benull.aMapper- The mapping function to convert each element to a string. May not benull.- Returns:
- this for chaining
-
source
Set the source elements from a string array.- Parameters:
a- The source string array. May benull.- Returns:
- this for chaining
-
source
Set the source elements from a generic array, converting each element to a string viaObject.toString().- Type Parameters:
T- The element type of the source array- Parameters:
a- The source array. May benull.- Returns:
- this for chaining
-
source
public <T> @NonNull StringImplode.ImploderBuilder source(@Nullable T[] a, @NonNull Function<? super T, String> aMapper) Set the source elements from a generic array, converting each element using the provided mapper function.- Type Parameters:
T- The element type of the source array- Parameters:
a- The source array. May benull.aMapper- The mapping function to convert each element to a string. May not benull.- Returns:
- this for chaining
-
separator
Set the separator character to use between elements.- Parameters:
c- The separator character.- Returns:
- this for chaining
-
separator
Set the separator string to use between elements.- Parameters:
s- The separator string. May benull.- Returns:
- this for chaining
-
offset
Set an offset of the source from which to start. Only values > 0 have an effect.- Parameters:
n- The offset to use- Returns:
- this for chaining
-
length
Set the number of source items to iterate, depending on the source offset. By default all elements from start to end are used. Only values > 0 have an effect.- Parameters:
n- The length to use- Returns:
- this for chaining
-
filterNonEmpty
Set the filter to only include non-nulland non-empty source elements.- Returns:
- this for chaining
-
filter
Set a custom filter predicate for source elements. Only elements matching the filter will be included in the result.- Parameters:
a- The filter predicate. May benullto include all elements.- Returns:
- this for chaining
-
build
Build the imploded string from the configured source, separator, offset, length, and filter.
-