Package com.landawn.abacus.util
Class Joiner
java.lang.Object
com.landawn.abacus.util.Joiner
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Since:
- 1.3
- Author:
- haiyangl
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionappend
(boolean element) append
(char element) append
(char[] element) append
(char[] element, int offset, int len) append
(double element) append
(float element) append
(int element) append
(long element) append
(CharSequence element) append
(CharSequence element, int start, int end) append
(StringBuffer element) appendAll
(boolean[] a) appendAll
(boolean[] a, int fromIndex, int toIndex) appendAll
(byte[] a) appendAll
(byte[] a, int fromIndex, int toIndex) appendAll
(char[] a) appendAll
(char[] a, int fromIndex, int toIndex) appendAll
(double[] a) appendAll
(double[] a, int fromIndex, int toIndex) appendAll
(float[] a) appendAll
(float[] a, int fromIndex, int toIndex) appendAll
(int[] a) appendAll
(int[] a, int fromIndex, int toIndex) appendAll
(long[] a) appendAll
(long[] a, int fromIndex, int toIndex) appendAll
(short[] a) appendAll
(short[] a, int fromIndex, int toIndex) appendAll
(BooleanList c, int fromIndex, int toIndex) appendAll
(DoubleList c, int fromIndex, int toIndex) appendAll
(Collection<?> c) appendAll
(Collection<?> c, int fromIndex, int toIndex) appendEntries
(Object entity) appendEntries
(Object entity, Collection<String> propNamesToAppend) appendEntries
(Map<?, ?> m) appendEntries
(Map<?, ?> m, int fromIndex, int toIndex) appendEntries
(Map<K, V> m, Throwables.Function<? super K, ?, E> keyMapper, Throwables.Function<? super V, ?, E2> valueMapper) appendEntriesExclusively
(Object entity, Set<String> propNamesToExeclude) appendEntry
(String key, boolean value) appendEntry
(String key, char value) appendEntry
(String key, char[] value) appendEntry
(String key, double value) appendEntry
(String key, float value) appendEntry
(String key, int value) appendEntry
(String key, long value) appendEntry
(String key, CharSequence value) appendEntry
(String key, Object value) appendEntry
(String key, String value) appendEntry
(String key, StringBuffer value) appendEntry
(Map.Entry<?, ?> entry) appendIfNotNull
(Object element) Append if not null.void
close()
Close.static Joiner
defauLt()
int
length()
<T,
E extends Exception>
Tmap
(Throwables.Function<? super String, T, E> mapper) The underlineStringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.<T,
E extends Exception>
u.Nullable<T>mapIfNotEmpty
(Throwables.Function<? super String, T, E> mapper) Callmapper
only if at least one element/object/entry is appended.Adds the contents of the givenStringJoiner
without prefix and suffix as the next element if it is non-empty.reuseCachedBuffer
(boolean useCachedBuffer) Deprecated.setEmptyValue
(CharSequence emptyValue) Sets the empty value.skipNull
(boolean skipNull) Deprecated.replaced byskipNulls()
stream()
The underlineStringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.Returns a stream with the String value generated bytoString()
if at least one element/object/entry is appended, otherwise an emptyStream
is returned.toString()
Returns the current value, consisting of theprefix
, the values added so far separated by thedelimiter
, and thesuffix
, unless no elements have been added in which case, theprefix + suffix
or theemptyValue
characters are returnedtrim
(boolean trim) Deprecated.replaced bytrimBeforeAppend()
useForNull
(String nullText) Use for null.static Joiner
with
(CharSequence delimiter) static Joiner
with
(CharSequence delimiter, CharSequence keyValueDelimiter) static Joiner
with
(CharSequence delimiter, CharSequence prefix, CharSequence suffix) static Joiner
with
(CharSequence delimiter, CharSequence keyValueDelimiter, CharSequence prefix, CharSequence suffix)
-
Field Details
-
DEFAULT_DELIMITER
-
DEFAULT_KEY_VALUE_DELIMITER
- See Also:
-
-
Method Details
-
defauLt
-
with
- Parameters:
delimiter
-- Returns:
-
with
- Parameters:
delimiter
-keyValueDelimiter
-- Returns:
-
with
- Parameters:
delimiter
-prefix
-suffix
-- Returns:
-
with
public static Joiner with(CharSequence delimiter, CharSequence keyValueDelimiter, CharSequence prefix, CharSequence suffix) - Parameters:
delimiter
-keyValueDelimiter
-prefix
-suffix
-- Returns:
-
setEmptyValue
Sets the empty value.- Parameters:
emptyValue
-- Returns:
-
trim
Deprecated.replaced bytrimBeforeAppend()
- Parameters:
trim
-- Returns:
-
trimBeforeAppend
-
skipNull
Deprecated.replaced byskipNulls()
Ignore thenull
element/value forkey/value, Map, Entity
when the specifiedelement
orvalue
isnull
if it's set totrue
.- Parameters:
skipNull
-- Returns:
-
skipNulls
-
useForNull
Use for null.- Parameters:
nullText
-- Returns:
-
reuseCachedBuffer
Deprecated.replaced byreuseCachedBuffer()
Improving performance by setuseCachedBuffer=true
, and must remember to calltoString()/map()/mapIfNotEmpty()/stream()/streamIfNotEmpty()
orclose()
to recycle the cached buffer.- Parameters:
useCachedBuffer
-- Returns:
-
reuseCachedBuffer
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-start
-end
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
append
- Parameters:
element
-offset
-len
-- Returns:
-
append
- Parameters:
element
-- Returns:
-
appendIfNotNull
Append if not null.- Parameters:
element
-- Returns:
-
appendIf
- Parameters:
b
-supplier
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
a
-- Returns:
-
appendAll
- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
- Parameters:
c
-- Returns:
-
appendAll
- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
appendAll
-
appendAll
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
key
-value
-- Returns:
-
appendEntry
- Parameters:
entry
-- Returns:
-
appendEntries
- Parameters:
m
-- Returns:
-
appendEntries
- Parameters:
m
-fromIndex
-toIndex
-- Returns:
-
appendEntries
public <K,V, Joiner appendEntriesE extends Exception, E2 extends Exception> (Map<K, V> m, Throwables.Function<? super K, throws E, E2?, E> keyMapper, Throwables.Function<? super V, ?, E2> valueMapper) -
appendEntries
- Parameters:
entity
- entity class with getter/setter methods.- Returns:
-
appendEntries
- Parameters:
entity
- entity class with getter/setter methods.propNamesToAppend
-- Returns:
-
appendEntriesExclusively
- Parameters:
entity
- entity class with getter/setter methods.propNamesToAppend
-- Returns:
-
repeat
- Parameters:
str
-n
-- Returns:
-
repeat
- Parameters:
obj
-n
-- Returns:
-
merge
Adds the contents of the givenStringJoiner
without prefix and suffix as the next element if it is non-empty. If the givenStringJoiner
is empty, the call has no effect.A
StringJoiner
is empty ifadd()
has never been called, and ifmerge()
has never been called with a non-emptyStringJoiner
argument.If the other
StringJoiner
is using a different delimiter, then elements from the otherStringJoiner
are concatenated with that delimiter and the result is appended to thisStringJoiner
as a single element.Remember to close
other
Joiner ifreuseCachedBuffer
is set to true.- Parameters:
other
- TheStringJoiner
whose contents should be merged into this one- Returns:
- This
StringJoiner
- Throws:
NullPointerException
- if the otherStringJoiner
is null
-
length
public int length() -
toString
Returns the current value, consisting of theprefix
, the values added so far separated by thedelimiter
, and thesuffix
, unless no elements have been added in which case, theprefix + suffix
or theemptyValue
characters are returnedThe underline
StringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance. -
map
The underline
StringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, 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, throws EE> mapper) Callmapper
only if at least one element/object/entry is appended.The underline
StringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.- Type Parameters:
T
-E
-- Parameters:
mapper
-- Returns:
- Throws:
E
- the e
-
stream
The underline
StringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.- Returns:
-
streamIfNotEmpty
Returns a stream with the String value generated bytoString()
if at least one element/object/entry is appended, otherwise an emptyStream
is returned.The underline
StringBuilder
will be recycled after this method is called ifresueStringBuilder
is set totrue
, and should not continue to this instance.- Returns:
-
close
public void close()Close.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
reuseCachedBuffer()