Class Joiner

    • Field Detail

      • DEFAULT_DELIMITER

        public static final String DEFAULT_DELIMITER
        The Constant DEFAULT_DELIMITER.
      • DEFAULT_KEY_VALUE_DELIMITER

        public static final String DEFAULT_KEY_VALUE_DELIMITER
        The Constant DEFAULT_KEY_VALUE_DELIMITER.
        See Also:
        Constant Field Values
    • Method Detail

      • defauLt

        public static Joiner defauLt()
        Returns:
      • with

        public static Joiner with​(CharSequence delimiter)
        Parameters:
        delimiter -
        Returns:
      • setEmptyValue

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

        public Joiner trim​(boolean trim)
        Parameters:
        trim -
        Returns:
      • skipNull

        public Joiner skipNull​(boolean skipNull)
        Ignore the null element/value for key/value, Map, Entity when the specified element or value is null if it's set to true.
        Parameters:
        skipNull -
        Returns:
      • useForNull

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

        public Joiner reuseCachedBuffer​(boolean useCachedBuffer)
        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:
      • 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,
                             int start,
                             int end)
        Parameters:
        element -
        start -
        end -
        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,
                                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:
      • 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,
                                  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 Joiner appendEntries​(Object entity)
        Parameters:
        entity - entity class with getter/setter methods.
        Returns:
      • 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.

        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:
      • map

        public <T,​E extends Exception> T map​(Throwables.Function<? super String,​T,​E> mapper)
                                            throws E extends Exception
         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
        E extends Exception
      • mapIfNotEmpty

        public <T,​E extends Exceptionu.Nullable<T> mapIfNotEmpty​(Throwables.Function<? super String,​T,​E> mapper)
                                                                  throws E extends Exception
        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
        E extends Exception
      • 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: