Class StringImplode.ImploderBuilder

java.lang.Object
com.helger.base.string.StringImplode.ImploderBuilder
All Implemented Interfaces:
IBuilder<String>
Enclosing class:
StringImplode

public static class StringImplode.ImploderBuilder extends Object implements IBuilder<String>
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 Details

    • ImploderBuilder

      public ImploderBuilder()
      Constructor.
  • Method Details

    • source

      public @NonNull StringImplode.ImploderBuilder source(@Nullable Collection<?> a)
      Set the source elements from a collection, converting each element to a string via Object.toString().
      Parameters:
      a - The source collection. May be null.
      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 be null.
      aMapper - The mapping function to convert each element to a string. May not be null.
      Returns:
      this for chaining
    • source

      public @NonNull StringImplode.ImploderBuilder source(@Nullable String... a)
      Set the source elements from a string array.
      Parameters:
      a - The source string array. May be null.
      Returns:
      this for chaining
    • source

      @SafeVarargs public final <T> @NonNull StringImplode.ImploderBuilder source(@Nullable T... a)
      Set the source elements from a generic array, converting each element to a string via Object.toString().
      Type Parameters:
      T - The element type of the source array
      Parameters:
      a - The source array. May be null.
      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 be null.
      aMapper - The mapping function to convert each element to a string. May not be null.
      Returns:
      this for chaining
    • separator

      public @NonNull StringImplode.ImploderBuilder separator(char c)
      Set the separator character to use between elements.
      Parameters:
      c - The separator character.
      Returns:
      this for chaining
    • separator

      public @NonNull StringImplode.ImploderBuilder separator(@Nullable String s)
      Set the separator string to use between elements.
      Parameters:
      s - The separator string. May be null.
      Returns:
      this for chaining
    • offset

      public @NonNull StringImplode.ImploderBuilder offset(int n)
      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

      public @NonNull StringImplode.ImploderBuilder length(int n)
      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

      public @NonNull StringImplode.ImploderBuilder filterNonEmpty()
      Set the filter to only include non-null and non-empty source elements.
      Returns:
      this for chaining
    • filter

      public @NonNull StringImplode.ImploderBuilder filter(@Nullable Predicate<String> a)
      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 be null to include all elements.
      Returns:
      this for chaining
    • build

      public @NonNull String build()
      Build the imploded string from the configured source, separator, offset, length, and filter.
      Specified by:
      build in interface IBuilder<String>
      Returns:
      The imploded string. Never null.