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
Fields -
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
(Iterable<? extends T> c, Throwables.Predicate<? super T, E> filter) appendAll
(Collection<?> c) appendAll
(Collection<?> c, int fromIndex, int toIndex) appendAll
(Iterator<? extends T> iter, Throwables.Predicate<? super T, E> filter) appendEntries
(Object bean) appendEntries
(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames) appendEntries
(Object bean, Throwables.BiPredicate<? super String, ?, E> filter) appendEntries
(Object bean, Collection<String> selectPropNames) appendEntries
(Map<?, ?> m) appendEntries
(Map<?, ?> m, int fromIndex, int toIndex) appendEntries
(Map<K, V> m, Throwables.BiPredicate<? super K, ? super V, E> filter) appendEntries
(Map<K, V> m, Throwables.Function<? super K, ?, E> keyMapper, Throwables.Function<? super V, ?, E2> valueMapper) appendEntries
(Map<K, V> m, Throwables.Predicate<? super Map.Entry<K, V>, E> filter) 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.<A extends Appendable>
AappendTo
(A appendable) 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.Improving performance by setuseCachedBuffer=true
, and must remember to calltoString()/appendTo()/map()/mapIfNotEmpty()/stream()/streamIfNotEmpty()
orclose()
to recycle the cached buffer.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 separator) static Joiner
with
(CharSequence separator, CharSequence keyValueDelimiter) static Joiner
with
(CharSequence separator, CharSequence prefix, CharSequence suffix) static Joiner
with
(CharSequence separator, CharSequence keyValueSeparator, CharSequence prefix, CharSequence suffix)
-
Field Details
-
DEFAULT_DELIMITER
-
DEFAULT_KEY_VALUE_DELIMITER
- See Also:
-
-
Method Details
-
defauLt
- Returns:
-
with
- Parameters:
separator
-- Returns:
-
with
- Parameters:
separator
-keyValueDelimiter
-- Returns:
-
with
- 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
Sets the empty value.- Parameters:
emptyValue
-- Returns:
-
trim
Deprecated.replaced bytrimBeforeAppend()
- Parameters:
trim
-- Returns:
-
trimBeforeAppend
- Returns:
-
skipNull
Deprecated.replaced byskipNulls()
Ignore thenull
element/value forkey/value, Map, Bean
when the specifiedelement
orvalue
isnull
if it's set totrue
.- Parameters:
skipNull
-- Returns:
-
skipNulls
- Returns:
-
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
Improving performance by setuseCachedBuffer=true
, and must remember to calltoString()/appendTo()/map()/mapIfNotEmpty()/stream()/streamIfNotEmpty()
orclose()
to recycle the cached buffer.- 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
-- 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
- 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 specifiedIterable
or not.skipNulls()
won't be used here.- Returns:
- Throws:
E
-
appendAll
- 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 specifiedIterable
or not.skipNulls()
won't be used here.- Returns:
- Throws:
E
-
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> (Map<K, V> m, Throwables.Predicate<? super Map.Entry<K, throws EV>, E> filter) - Type Parameters:
K
-V
-E
-- Parameters:
m
-filter
-- Returns:
- Throws:
E
-
appendEntries
public <K,V, Joiner appendEntriesE extends Exception> (Map<K, V> m, Throwables.BiPredicate<? super K, throws E? super V, E> filter) - Type Parameters:
K
-V
-E
-- Parameters:
m
-filter
-- Returns:
- Throws:
E
-
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) - Type Parameters:
K
-V
-E
-E2
-- Parameters:
m
-keyMapper
-valueMapper
-- Returns:
- Throws:
E
E2
-
appendEntries
- Parameters:
bean
-- Returns:
-
appendEntries
- Parameters:
bean
-selectPropNames
-- Returns:
-
appendEntries
- Parameters:
bean
-ignoreNullProperty
-ignoredPropNames
-- Returns:
-
appendEntries
public <E extends Exception> Joiner appendEntries(Object bean, Throwables.BiPredicate<? super String, ?, throws EE> filter) - Type Parameters:
E
-- Parameters:
bean
-filter
-- Returns:
- Throws:
E
-
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 if append/appendAll 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()- Returns:
-
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. -
appendTo
- Type Parameters:
A
-- Parameters:
appendable
-- Returns:
- Throws:
IOException
-
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()