public class

Joiner

extends Object
java.lang.Object
   ↳ com.google.gdata.util.common.base.Joiner

Class Overview

An object which joins pieces of text (specified as an array, Iterable, varargs or even a Map) with a separator. It either appends the results to an Appendable or returns them as a String. Example:

   Joiner joiner = Joiner.on("; ").skipNulls();
    . . .
   return joiner.join("Harry", null, "Ron", "Hermione");
This returns the string "Harry; Ron; Hermione". Note that all input elements are converted to strings using toString() before being appended.

If neither skipNulls() nor useForNull(String) is specified, the joining methods will throw NullPointerException if any given element is null.

Summary

Nested Classes
class Joiner.MapJoiner An object that joins map entries in the same manner as Joiner joins iterables and arrays. 
Fields
private final String separator
Public Methods
final StringBuilder appendTo(StringBuilder builder, Iterable<?> parts)
Appends the string representation of each of parts, using the previously configured separator between each, to builder.
<A extends Appendable> A appendTo(A appendable, Iterable<?> parts)
Appends the string representation of each of parts, using the previously configured separator between each, to appendable.
final StringBuilder appendTo(StringBuilder builder, Object[] parts)
Appends the string representation of each of parts, using the previously configured separator between each, to builder.
final <A extends Appendable> A appendTo(A appendable, Object first, Object second, Object... rest)
Appends to appendable the string representation of each of the remaining arguments.
final StringBuilder appendTo(StringBuilder builder, Object first, Object second, Object... rest)
Appends to builder the string representation of each of the remaining arguments.
final <A extends Appendable> A appendTo(A appendable, Object[] parts)
Appends the string representation of each of parts, using the previously configured separator between each, to appendable.
final String join(Object[] parts)
Returns a string containing the string representation of each of parts, using the previously configured separator between each.
final String join(Object first, Object second, Object... rest)
Returns a string containing the string representation of each argument, using the previously configured separator between each.
final String join(Iterable<?> parts)
Returns a string containing the string representation of each of parts, using the previously configured separator between each.
static Joiner on(String separator)
Returns a joiner which automatically places separator between consecutive elements.
Joiner skipNulls()
Returns a joiner with the same behavior as this joiner, except automatically skipping over any provided null elements.
Joiner useForNull(String nullText)
Returns a joiner with the same behavior as this one, except automatically substituting nullText for any provided null elements.
Joiner.MapJoiner withKeyValueSeparator(String keyValueSeparator)
Returns a MapJoiner using the given key-value separator, and the same configuration as this Joiner otherwise.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private final String separator

Public Methods

public final StringBuilder appendTo (StringBuilder builder, Iterable<?> parts)

Appends the string representation of each of parts, using the previously configured separator between each, to builder. Identical to appendTo(Appendable, Iterable), except that it does not throw IOException.

Parameters
builder
parts

public A appendTo (A appendable, Iterable<?> parts)

Appends the string representation of each of parts, using the previously configured separator between each, to appendable.

Parameters
appendable
parts
Throws
IOException

public final StringBuilder appendTo (StringBuilder builder, Object[] parts)

Appends the string representation of each of parts, using the previously configured separator between each, to builder. Identical to appendTo(Appendable, Iterable), except that it does not throw IOException.

Parameters
builder
parts

public final A appendTo (A appendable, Object first, Object second, Object... rest)

Appends to appendable the string representation of each of the remaining arguments.

Parameters
appendable
first
second
rest
Throws
IOException

public final StringBuilder appendTo (StringBuilder builder, Object first, Object second, Object... rest)

Appends to builder the string representation of each of the remaining arguments. Identical to appendTo(Appendable, Object, Object, Object[]), except that it does not throw IOException.

Parameters
builder
first
second
rest

public final A appendTo (A appendable, Object[] parts)

Appends the string representation of each of parts, using the previously configured separator between each, to appendable.

Parameters
appendable
parts
Throws
IOException

public final String join (Object[] parts)

Returns a string containing the string representation of each of parts, using the previously configured separator between each.

Parameters
parts

public final String join (Object first, Object second, Object... rest)

Returns a string containing the string representation of each argument, using the previously configured separator between each.

Parameters
first
second
rest

public final String join (Iterable<?> parts)

Returns a string containing the string representation of each of parts, using the previously configured separator between each.

Parameters
parts

public static Joiner on (String separator)

Returns a joiner which automatically places separator between consecutive elements.

Parameters
separator

public Joiner skipNulls ()

Returns a joiner with the same behavior as this joiner, except automatically skipping over any provided null elements.

public Joiner useForNull (String nullText)

Returns a joiner with the same behavior as this one, except automatically substituting nullText for any provided null elements.

Parameters
nullText

public Joiner.MapJoiner withKeyValueSeparator (String keyValueSeparator)

Returns a MapJoiner using the given key-value separator, and the same configuration as this Joiner otherwise.

Parameters
keyValueSeparator