Class Joiner

java.lang.Object
com.landawn.abacus.util.Joiner
All Implemented Interfaces:
Closeable, AutoCloseable

public final class Joiner extends Object implements Closeable
Since:
1.3
Author:
haiyangl
  • Field Details

    • DEFAULT_DELIMITER

      public static final String DEFAULT_DELIMITER
    • DEFAULT_KEY_VALUE_DELIMITER

      public static final String DEFAULT_KEY_VALUE_DELIMITER
      See Also:
  • Method Details

    • defauLt

      public static Joiner defauLt()
      Returns:
    • with

      public static Joiner with(CharSequence separator)
      Parameters:
      separator -
      Returns:
    • with

      public static Joiner with(CharSequence separator, CharSequence keyValueDelimiter)
      Parameters:
      separator -
      keyValueDelimiter -
      Returns:
    • with

      public static Joiner with(CharSequence separator, CharSequence prefix, CharSequence suffix)
      Parameters:
      separator -
      prefix -
      suffix -
      Returns:
    • with

      public static Joiner with(CharSequence separator, CharSequence keyValueSeparator, CharSequence prefix, CharSequence suffix)
      Parameters:
      separator -
      keyValueSeparator -
      prefix -
      suffix -
      Returns:
    • setEmptyValue

      public Joiner setEmptyValue(CharSequence emptyValue)
      Sets the empty value.
      Parameters:
      emptyValue -
      Returns:
    • trim

      @Deprecated public Joiner trim(boolean trim)
      Deprecated.
      replaced by trimBeforeAppend()
      Parameters:
      trim -
      Returns:
    • trimBeforeAppend

      public Joiner trimBeforeAppend()
      Returns:
    • skipNull

      @Deprecated public Joiner skipNull(boolean skipNull)
      Deprecated.
      replaced by skipNulls()
      Ignore the null element/value for key/value, Map, Bean when the specified element or value is null if it's set to true.
      Parameters:
      skipNull -
      Returns:
    • skipNulls

      public Joiner skipNulls()
      Returns:
    • useForNull

      public Joiner useForNull(String nullText)
      Use for null.
      Parameters:
      nullText -
      Returns:
    • reuseCachedBuffer

      @Deprecated public Joiner reuseCachedBuffer(boolean useCachedBuffer)
      Deprecated.
      Improving performance by set useCachedBuffer=true, and must remember to call toString()/map()/mapIfNotEmpty()/stream()/streamIfNotEmpty() or close() to recycle the cached buffer.
      Parameters:
      useCachedBuffer -
      Returns:
    • reuseCachedBuffer

      public Joiner reuseCachedBuffer()
      Improving performance by set useCachedBuffer=true, and must remember to call toString()/appendTo()/map()/mapIfNotEmpty()/stream()/streamIfNotEmpty() or close() to recycle the cached buffer.
      Returns:
    • append

      public Joiner append(boolean element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(char element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(int element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(long element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(float element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(double element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(String element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(CharSequence element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(CharSequence element, int start, int end)
      Parameters:
      element -
      start -
      end -
      Returns:
    • append

      public Joiner append(StringBuffer element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(char[] element)
      Parameters:
      element -
      Returns:
    • append

      public Joiner append(char[] element, int offset, int len)
      Parameters:
      element -
      offset -
      len -
      Returns:
    • append

      public Joiner append(Object element)
      Parameters:
      element -
      Returns:
    • appendIfNotNull

      public Joiner appendIfNotNull(Object element)
      Append if not null.
      Parameters:
      element -
      Returns:
    • appendIf

      public Joiner appendIf(boolean b, Supplier<?> supplier)
      Parameters:
      b -
      supplier -
      Returns:
    • appendAll

      public Joiner appendAll(boolean[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(boolean[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(char[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(char[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(byte[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(byte[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(short[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(short[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(int[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(int[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(long[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(long[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(float[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(float[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(double[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(double[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(Object[] a)
      Parameters:
      a -
      Returns:
    • appendAll

      public Joiner appendAll(Object[] a, int fromIndex, int toIndex)
      Parameters:
      a -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(BooleanList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(BooleanList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(CharList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(CharList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(ByteList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(ByteList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(ShortList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(ShortList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(IntList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(IntList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(LongList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(LongList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(FloatList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(FloatList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(DoubleList c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(DoubleList c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(Collection<?> c)
      Parameters:
      c -
      Returns:
    • appendAll

      public Joiner appendAll(Collection<?> c, int fromIndex, int toIndex)
      Parameters:
      c -
      fromIndex -
      toIndex -
      Returns:
    • appendAll

      public Joiner appendAll(Iterable<?> c)
      Parameters:
      c -
      Returns:
    • appendAll

      public <T, E extends Exception> Joiner appendAll(Iterable<? extends T> c, Throwables.Predicate<? super T,E> filter) throws E
      Type Parameters:
      T -
      E -
      Parameters:
      c -
      filter - will be the only condition to decide if append an element from the specified Iterable or not. skipNulls() won't be used here.
      Returns:
      Throws:
      E
    • appendAll

      public Joiner appendAll(Iterator<?> iter)
      Parameters:
      iter -
      Returns:
    • appendAll

      public <T, E extends Exception> Joiner appendAll(Iterator<? extends T> iter, Throwables.Predicate<? super T,E> filter) throws E
      Type Parameters:
      T -
      E -
      Parameters:
      iter -
      filter - will be the only condition to decide if append an element from the specified Iterable or not. skipNulls() won't be used here.
      Returns:
      Throws:
      E
    • appendEntry

      public Joiner appendEntry(String key, boolean value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, char value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, int value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, long value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, float value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, double value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, String value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, CharSequence value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, StringBuffer value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, char[] value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(String key, Object value)
      Parameters:
      key -
      value -
      Returns:
    • appendEntry

      public Joiner appendEntry(Map.Entry<?,?> entry)
      Parameters:
      entry -
      Returns:
    • appendEntries

      public Joiner appendEntries(Map<?,?> m)
      Parameters:
      m -
      Returns:
    • appendEntries

      public Joiner appendEntries(Map<?,?> m, int fromIndex, int toIndex)
      Parameters:
      m -
      fromIndex -
      toIndex -
      Returns:
    • appendEntries

      public <K, V, E extends Exception> Joiner appendEntries(Map<K,V> m, Throwables.Predicate<? super Map.Entry<K,V>,E> filter) throws E
      Type Parameters:
      K -
      V -
      E -
      Parameters:
      m -
      filter -
      Returns:
      Throws:
      E
    • appendEntries

      public <K, V, E extends Exception> Joiner appendEntries(Map<K,V> m, Throwables.BiPredicate<? super K,? super V,E> filter) throws E
      Type Parameters:
      K -
      V -
      E -
      Parameters:
      m -
      filter -
      Returns:
      Throws:
      E
    • appendEntries

      public <K, V, E extends Exception, E2 extends Exception> Joiner appendEntries(Map<K,V> m, Throwables.Function<? super K,?,E> keyMapper, Throwables.Function<? super V,?,E2> valueMapper) throws E, E2
      Type Parameters:
      K -
      V -
      E -
      E2 -
      Parameters:
      m -
      keyMapper -
      valueMapper -
      Returns:
      Throws:
      E
      E2
    • appendEntries

      public Joiner appendEntries(Object bean)
      Parameters:
      bean -
      Returns:
    • appendEntries

      public Joiner appendEntries(Object bean, Collection<String> selectPropNames)
      Parameters:
      bean -
      selectPropNames -
      Returns:
    • appendEntries

      public Joiner appendEntries(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames)
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      Returns:
    • appendEntries

      public <E extends Exception> Joiner appendEntries(Object bean, Throwables.BiPredicate<? super String,?,E> filter) throws E
      Type Parameters:
      E -
      Parameters:
      bean -
      filter -
      Returns:
      Throws:
      E
    • repeat

      public Joiner repeat(String str, int n)
      Parameters:
      str -
      n -
      Returns:
    • repeat

      public Joiner repeat(Object obj, int n)
      Parameters:
      obj -
      n -
      Returns:
    • merge

      public Joiner merge(Joiner other)
      Adds the contents of the given StringJoiner without prefix and suffix as the next element if it is non-empty. If the given StringJoiner is empty, the call has no effect.

      A StringJoiner is empty if add() has never been called, and if merge() has never been called with a non-empty StringJoiner argument.

      If the other StringJoiner is using a different delimiter, then elements from the other StringJoiner are concatenated with that delimiter and the result is appended to this StringJoiner as a single element.

      Remember to close other Joiner if reuseCachedBuffer is set to true.

      Parameters:
      other - The StringJoiner whose contents should be merged into this one
      Returns:
      This StringJoiner
      Throws:
      NullPointerException - if the other StringJoiner is null
    • length

      public int length()
      Returns:
    • toString

      public String toString()
      Returns the current value, consisting of the prefix, the values added so far separated by the delimiter, and the suffix, unless no elements have been added in which case, the prefix + suffix or the emptyValue characters are returned
       The underline StringBuilder will be recycled after this method is called if resueStringBuilder is set to true,
       and should not continue to this instance.
       
      Overrides:
      toString in class Object
      Returns:
    • appendTo

      public <A extends Appendable> A appendTo(A appendable) throws IOException
      Type Parameters:
      A -
      Parameters:
      appendable -
      Returns:
      Throws:
      IOException
    • map

      public <T, E extends Exception> T map(Throwables.Function<? super String,T,E> mapper) throws E
       The underline StringBuilder will be recycled after this method is called if resueStringBuilder is set to true,
       and should not continue to this instance.
       
      Type Parameters:
      T -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • mapIfNotEmpty

      public <T, E extends Exception> u.Nullable<T> mapIfNotEmpty(Throwables.Function<? super String,T,E> mapper) throws E
      Call mapper only if at least one element/object/entry is appended.
       The underline StringBuilder will be recycled after this method is called if resueStringBuilder is set to true,
       and should not continue to this instance.
       
      Type Parameters:
      T -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • stream

      public Stream<String> stream()
       The underline StringBuilder will be recycled after this method is called if resueStringBuilder is set to true,
       and should not continue to this instance.
       
      Returns:
    • streamIfNotEmpty

      public Stream<String> streamIfNotEmpty()
      Returns a stream with the String value generated by toString() if at least one element/object/entry is appended, otherwise an empty Stream is returned.
       The underline StringBuilder will be recycled after this method is called if resueStringBuilder is set to true,
       and should not continue to this instance.
       
      Returns:
    • close

      public void close()
      Close.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable