Class Join
- java.lang.Object
-
- org.elasticsearch.common.inject.internal.Join
-
public final class Join extends java.lang.Object
Utility for joining pieces of text separated by a delimiter. It can handle iterators, collections, arrays, and varargs, and can append to anyAppendable
or just return aString
. For example,join(":", "a", "b", "c")
returns"a:b:c"
.All methods of this class throw
NullPointerException
when a value ofnull
is supplied for any parameter. The elements within the collection, iterator, array, or varargs parameter list may be null -- these will be represented in the output by the string"null"
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Join.JoinException
Exception thrown in response to anIOException
from the suppliedAppendable
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
join(java.lang.String delimiter, java.lang.Iterable<?> tokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
.static java.lang.String
join(java.lang.String delimiter, java.lang.Object[] tokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
.static java.lang.String
join(java.lang.String delimiter, java.lang.Object firstToken, java.lang.Object... otherTokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
.static java.lang.String
join(java.lang.String keyValueSeparator, java.lang.String entryDelimiter, java.util.Map<?,?> map)
Returns a string containing the contents ofmap
, with entries separated byentryDelimiter
, and keys and values separated withkeyValueSeparator
.static java.lang.String
join(java.lang.String delimiter, java.util.Iterator<?> tokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
.static <T extends java.lang.Appendable>
Tjoin(T appendable, java.lang.String delimiter, java.lang.Iterable<?> tokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.static <T extends java.lang.Appendable>
Tjoin(T appendable, java.lang.String delimiter, java.lang.Object[] tokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.static <T extends java.lang.Appendable>
Tjoin(T appendable, java.lang.String delimiter, java.lang.Object firstToken, java.lang.Object... otherTokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.static <T extends java.lang.Appendable>
Tjoin(T appendable, java.lang.String keyValueSeparator, java.lang.String entryDelimiter, java.util.Map<?,?> map)
Appends the contents ofmap
toappendable
, with entries separated byentryDelimiter
, and keys and values separated withkeyValueSeparator
.static <T extends java.lang.Appendable>
Tjoin(T appendable, java.lang.String delimiter, java.util.Iterator<?> tokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.
-
-
-
Method Detail
-
join
public static java.lang.String join(java.lang.String delimiter, java.lang.Iterable<?> tokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
. Iftokens
is empty, it returns an empty string.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
delimiter
- a string to append between every element, but not at the beginning or endtokens
- objects to append- Returns:
- a string consisting of the joined elements
-
join
public static java.lang.String join(java.lang.String delimiter, java.lang.Object[] tokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
. Iftokens
is empty, it returns an empty string.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
delimiter
- a string to append between every element, but not at the beginning or endtokens
- objects to append- Returns:
- a string consisting of the joined elements
-
join
public static java.lang.String join(java.lang.String delimiter, @Nullable java.lang.Object firstToken, java.lang.Object... otherTokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
delimiter
- a string to append between every element, but not at the beginning or endfirstToken
- the first object to appendotherTokens
- subsequent objects to append- Returns:
- a string consisting of the joined elements
-
join
public static java.lang.String join(java.lang.String delimiter, java.util.Iterator<?> tokens)
Returns a string containing thetokens
, converted to strings if necessary, separated bydelimiter
. Iftokens
is empty, it returns an empty string.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
delimiter
- a string to append between every element, but not at the beginning or endtokens
- objects to append- Returns:
- a string consisting of the joined elements
-
join
public static java.lang.String join(java.lang.String keyValueSeparator, java.lang.String entryDelimiter, java.util.Map<?,?> map)
Returns a string containing the contents ofmap
, with entries separated byentryDelimiter
, and keys and values separated withkeyValueSeparator
.Each key and value will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
keyValueSeparator
- a string to append between every key and its associated valueentryDelimiter
- a string to append between every entry, but not at the beginning or endmap
- the map containing the data to join- Returns:
- a string consisting of the joined entries of the map; empty if the map is empty
-
join
public static <T extends java.lang.Appendable> T join(T appendable, java.lang.String delimiter, java.lang.Iterable<?> tokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
appendable
- the object to append the results todelimiter
- a string to append between every element, but not at the beginning or endtokens
- objects to append- Returns:
- the same
Appendable
instance that was passed in - Throws:
Join.JoinException
- if anIOException
occurs
-
join
public static <T extends java.lang.Appendable> T join(T appendable, java.lang.String delimiter, java.lang.Object[] tokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
appendable
- the object to append the results todelimiter
- a string to append between every element, but not at the beginning or endtokens
- objects to append- Returns:
- the same
Appendable
instance that was passed in - Throws:
Join.JoinException
- if anIOException
occurs
-
join
public static <T extends java.lang.Appendable> T join(T appendable, java.lang.String delimiter, @Nullable java.lang.Object firstToken, java.lang.Object... otherTokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
appendable
- the object to append the results todelimiter
- a string to append between every element, but not at the beginning or endfirstToken
- the first object to appendotherTokens
- subsequent objects to append- Returns:
- the same
Appendable
instance that was passed in - Throws:
Join.JoinException
- if anIOException
occurs
-
join
public static <T extends java.lang.Appendable> T join(T appendable, java.lang.String delimiter, java.util.Iterator<?> tokens)
Appends each of thetokens
toappendable
, separated bydelimiter
.Each token will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
appendable
- the object to append the results todelimiter
- a string to append between every element, but not at the beginning or endtokens
- objects to append- Returns:
- the same
Appendable
instance that was passed in - Throws:
Join.JoinException
- if anIOException
occurs
-
join
public static <T extends java.lang.Appendable> T join(T appendable, java.lang.String keyValueSeparator, java.lang.String entryDelimiter, java.util.Map<?,?> map)
Appends the contents ofmap
toappendable
, with entries separated byentryDelimiter
, and keys and values separated withkeyValueSeparator
.Each key and value will be converted to a
CharSequence
usingString.valueOf(Object)
, if it isn't aCharSequence
already. Note that this implies that null tokens will be appended as the four-character string"null"
.- Parameters:
appendable
- the object to append the results tokeyValueSeparator
- a string to append between every key and its associated valueentryDelimiter
- a string to append between every entry, but not at the beginning or endmap
- the map containing the data to join- Returns:
- the same
Appendable
instance that was passed in
-
-