public class Joiner
extends java.lang.Object
implements java.lang.AutoCloseable
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_DELIMITER |
static java.lang.String |
DEFAULT_KEY_VALUE_DELIMITER |
Modifier and Type | Method and Description |
---|---|
Joiner |
append(boolean element) |
Joiner |
append(char element) |
Joiner |
append(char[] element) |
Joiner |
append(char[] element,
int offset,
int len) |
Joiner |
append(java.lang.CharSequence element) |
Joiner |
append(java.lang.CharSequence element,
int start,
int end) |
Joiner |
append(double element) |
Joiner |
append(float element) |
Joiner |
append(int element) |
Joiner |
append(long element) |
Joiner |
append(java.lang.Object element) |
Joiner |
append(java.lang.String element) |
Joiner |
append(java.lang.StringBuffer element) |
Joiner |
appendAll(boolean[] a) |
Joiner |
appendAll(boolean[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(BooleanList c) |
Joiner |
appendAll(BooleanList c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(byte[] a) |
Joiner |
appendAll(byte[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(ByteList c) |
Joiner |
appendAll(ByteList c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(char[] a) |
Joiner |
appendAll(char[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(CharList c) |
Joiner |
appendAll(CharList c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(java.util.Collection<?> c) |
Joiner |
appendAll(java.util.Collection<?> c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(double[] a) |
Joiner |
appendAll(double[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(DoubleList c) |
Joiner |
appendAll(DoubleList c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(float[] a) |
Joiner |
appendAll(float[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(FloatList c) |
Joiner |
appendAll(FloatList c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(int[] a) |
Joiner |
appendAll(int[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(IntList c) |
Joiner |
appendAll(IntList c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(long[] a) |
Joiner |
appendAll(long[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(LongList c) |
Joiner |
appendAll(LongList c,
int fromIndex,
int toIndex) |
Joiner |
appendAll(java.lang.Object[] a) |
Joiner |
appendAll(java.lang.Object[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(short[] a) |
Joiner |
appendAll(short[] a,
int fromIndex,
int toIndex) |
Joiner |
appendAll(ShortList c) |
Joiner |
appendAll(ShortList c,
int fromIndex,
int toIndex) |
Joiner |
appendEntries(java.util.Map<?,?> m) |
Joiner |
appendEntries(java.util.Map<?,?> m,
int fromIndex,
int toIndex) |
Joiner |
appendEntries(java.lang.Object entity) |
Joiner |
appendEntry(java.util.Map.Entry<?,?> entry) |
Joiner |
appendEntry(java.lang.String key,
boolean value) |
Joiner |
appendEntry(java.lang.String key,
char value) |
Joiner |
appendEntry(java.lang.String key,
char[] value) |
Joiner |
appendEntry(java.lang.String key,
java.lang.CharSequence value) |
Joiner |
appendEntry(java.lang.String key,
double value) |
Joiner |
appendEntry(java.lang.String key,
float value) |
Joiner |
appendEntry(java.lang.String key,
int value) |
Joiner |
appendEntry(java.lang.String key,
long value) |
Joiner |
appendEntry(java.lang.String key,
java.lang.Object value) |
Joiner |
appendEntry(java.lang.String key,
java.lang.String value) |
Joiner |
appendEntry(java.lang.String key,
java.lang.StringBuffer value) |
Joiner |
appendIf(boolean b,
Supplier<?> supplier) |
Joiner |
appendIfNotNull(java.lang.Object element) |
void |
close() |
static Joiner |
defauLt() |
int |
length() |
<T,E extends java.lang.Exception> |
map(Try.Function<? super java.lang.String,T,E> mapper)
The underline
StringBuilder will be recycled after this method is called if resueStringBuilder is set to true ,
and should not continue to this instance. |
<T,E extends java.lang.Exception> |
mapIfNotEmpty(Try.Function<? super java.lang.String,T,E> mapper)
Call
mapper only if at least one element/object/entry is appended. |
Joiner |
merge(Joiner other)
Adds the contents of the given
StringJoiner without prefix and
suffix as the next element if it is non-empty. |
Joiner |
repeat(java.lang.Object obj,
int n) |
Joiner |
repeat(java.lang.String str,
int n) |
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. |
Joiner |
setEmptyValue(java.lang.CharSequence emptyValue) |
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 . |
Stream<java.lang.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. |
Stream<java.lang.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. |
java.lang.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 |
Joiner |
trim(boolean trim) |
Joiner |
useForNull(java.lang.String nullText) |
static Joiner |
with(java.lang.CharSequence delimiter) |
static Joiner |
with(java.lang.CharSequence delimiter,
java.lang.CharSequence keyValueDelimiter) |
static Joiner |
with(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix) |
static Joiner |
with(java.lang.CharSequence delimiter,
java.lang.CharSequence keyValueDelimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix) |
public static final java.lang.String DEFAULT_DELIMITER
public static final java.lang.String DEFAULT_KEY_VALUE_DELIMITER
public static Joiner defauLt()
public static Joiner with(java.lang.CharSequence delimiter)
public static Joiner with(java.lang.CharSequence delimiter, java.lang.CharSequence keyValueDelimiter)
public static Joiner with(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)
public static Joiner with(java.lang.CharSequence delimiter, java.lang.CharSequence keyValueDelimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)
public Joiner setEmptyValue(java.lang.CharSequence emptyValue)
public Joiner trim(boolean trim)
public Joiner skipNull(boolean skipNull)
null
element/value for key/value, Map, Entity
when the specified element
or value
is null
if it's set to true
.skipNull
- public Joiner useForNull(java.lang.String nullText)
public Joiner reuseCachedBuffer(boolean useCachedBuffer)
useCachedBuffer=true
, and must remember to call toString()/map()/mapIfNotEmpty()/stream()/streamIfNotEmpty()
or close()
to recycle the cached buffer.useCachedBuffer
- public Joiner append(boolean element)
public Joiner append(char element)
public Joiner append(int element)
public Joiner append(long element)
public Joiner append(float element)
public Joiner append(double element)
public Joiner append(java.lang.String element)
public Joiner append(java.lang.CharSequence element)
public Joiner append(java.lang.CharSequence element, int start, int end)
public Joiner append(java.lang.StringBuffer element)
public Joiner append(char[] element)
public Joiner append(char[] element, int offset, int len)
public Joiner append(java.lang.Object element)
public Joiner appendIfNotNull(java.lang.Object element)
public Joiner appendAll(boolean[] a)
public Joiner appendAll(boolean[] a, int fromIndex, int toIndex)
public Joiner appendAll(char[] a)
public Joiner appendAll(char[] a, int fromIndex, int toIndex)
public Joiner appendAll(byte[] a)
public Joiner appendAll(byte[] a, int fromIndex, int toIndex)
public Joiner appendAll(short[] a)
public Joiner appendAll(short[] a, int fromIndex, int toIndex)
public Joiner appendAll(int[] a)
public Joiner appendAll(int[] a, int fromIndex, int toIndex)
public Joiner appendAll(long[] a)
public Joiner appendAll(long[] a, int fromIndex, int toIndex)
public Joiner appendAll(float[] a)
public Joiner appendAll(float[] a, int fromIndex, int toIndex)
public Joiner appendAll(double[] a)
public Joiner appendAll(double[] a, int fromIndex, int toIndex)
public Joiner appendAll(java.lang.Object[] a)
public Joiner appendAll(java.lang.Object[] a, int fromIndex, int toIndex)
public Joiner appendAll(BooleanList c)
public Joiner appendAll(BooleanList c, int fromIndex, int toIndex)
public Joiner appendAll(DoubleList c)
public Joiner appendAll(DoubleList c, int fromIndex, int toIndex)
public Joiner appendAll(java.util.Collection<?> c)
public Joiner appendAll(java.util.Collection<?> c, int fromIndex, int toIndex)
public Joiner appendEntry(java.lang.String key, boolean value)
public Joiner appendEntry(java.lang.String key, char value)
public Joiner appendEntry(java.lang.String key, int value)
public Joiner appendEntry(java.lang.String key, long value)
public Joiner appendEntry(java.lang.String key, float value)
public Joiner appendEntry(java.lang.String key, double value)
public Joiner appendEntry(java.lang.String key, java.lang.String value)
public Joiner appendEntry(java.lang.String key, java.lang.CharSequence value)
public Joiner appendEntry(java.lang.String key, java.lang.StringBuffer value)
public Joiner appendEntry(java.lang.String key, char[] value)
public Joiner appendEntry(java.lang.String key, java.lang.Object value)
public Joiner appendEntry(java.util.Map.Entry<?,?> entry)
public Joiner appendEntries(java.util.Map<?,?> m)
public Joiner appendEntries(java.util.Map<?,?> m, int fromIndex, int toIndex)
public Joiner appendEntries(java.lang.Object entity)
entity
- entity class with getter/setter methods.public Joiner repeat(java.lang.String str, int n)
public Joiner repeat(java.lang.Object obj, int n)
public Joiner merge(Joiner other)
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.
other
- The StringJoiner
whose contents should be merged
into this oneStringJoiner
java.lang.NullPointerException
- if the other StringJoiner
is nullpublic int length()
public java.lang.String toString()
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 underlineStringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.
toString
in class java.lang.Object
StringJoiner
public <T,E extends java.lang.Exception> T map(Try.Function<? super java.lang.String,T,E> mapper) throws E extends java.lang.Exception
The underlineStringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.
mapper
- E extends java.lang.Exception
public <T,E extends java.lang.Exception> u.Nullable<T> mapIfNotEmpty(Try.Function<? super java.lang.String,T,E> mapper) throws E extends java.lang.Exception
mapper
only if at least one element/object/entry is appended.
The underlineStringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.
mapper
- E extends java.lang.Exception
public Stream<java.lang.String> stream()
The underlineStringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.
public Stream<java.lang.String> streamIfNotEmpty()
toString()
if at least one element/object/entry is appended, otherwise an empty Stream
is returned.
The underlineStringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.
public void close()
close
in interface java.lang.AutoCloseable