/** * Returns a joiner which automatically places {@code separator} between consecutive elements. */ public static Joiner on(String separator) { return new Joiner(separator); }
/** * Appends the string representation of each of {@code parts}, using the previously configured separator between * each, to {@code appendable}. */ public <A extends Appendable> A appendTo(A appendable, Iterable<?> parts) throws IOException { return appendTo(appendable, parts.iterator()); }
/** * Returns a string containing the string representation of each of {@code parts}, using the previously configured * separator between each. */ public final String join(Iterable<?> parts) { return join(parts.iterator()); }
/** * Appends to {@code appendable} the string representation of each of the remaining arguments. */ public final <A extends Appendable> A appendTo(A appendable, @Nullable Object first, @Nullable Object second, Object... rest) throws IOException { return appendTo(appendable, iterable(first, second, rest)); }
@Override CharSequence toString(@Nullable Object part) { return (part == null) ? nullText : Joiner.this.toString(part); }
/** * Returns a map joiner with the same behavior as this one, except automatically substituting {@code nullText} * for any provided null keys or values. */ public MapJoiner useForNull(String nullText) { return new MapJoiner(joiner.useForNull(nullText), keyValueSeparator); } }
/** * Appends to {@code builder} the string representation of each of the remaining arguments. Identical to * {@link #appendTo(Appendable, Object, Object, Object...)}, except that it does not throw {@link IOException}. */ public final StringBuilder appendTo(StringBuilder builder, @Nullable Object first, @Nullable Object second, Object... rest) { return appendTo(builder, iterable(first, second, rest)); }
/** * Appends the string representation of each of {@code parts}, using the previously configured separator between * each, to {@code appendable}. * * @since 11.0 */ public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException { notNull(appendable); if (parts.hasNext()) { appendable.append(toString(parts.next())); while (parts.hasNext()) { appendable.append(separator); appendable.append(toString(parts.next())); } } return appendable; }
/** * Appends the string representation of each of {@code parts}, using the previously configured separator between * each, to {@code builder}. Identical to {@link #appendTo(Appendable, Iterable)}, except that it does not throw * {@link IOException}. */ public final StringBuilder appendTo(StringBuilder builder, Object[] parts) { return appendTo(builder, Arrays.asList(parts)); }
@Override public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException { notNull(appendable, "appendable"); notNull(parts, "parts"); while (parts.hasNext()) { Object part = parts.next(); if (part != null) { appendable.append(Joiner.this.toString(part)); break; } } while (parts.hasNext()) { Object part = parts.next(); if (part != null) { appendable.append(separator); appendable.append(Joiner.this.toString(part)); } } return appendable; }
/** * Returns a string containing the string representation of each of {@code parts}, using the previously configured * separator between each. */ public final String join(Object[] parts) { return join(Arrays.asList(parts)); }
/** * Returns a joiner which automatically places {@code separator} between consecutive elements. */ public static Joiner on(char separator) { return new Joiner(String.valueOf(separator)); }
/** * Appends the string representation of each of {@code parts}, using the previously configured separator between * each, to {@code appendable}. */ public final <A extends Appendable> A appendTo(A appendable, Object[] parts) throws IOException { return appendTo(appendable, Arrays.asList(parts)); }
/** * Appends the string representation of each entry in {@code entries}, using the previously configured separator * and key-value separator, to {@code appendable}. * * @since 11.0 */ public <A extends Appendable> A appendTo(A appendable, Iterator<? extends Entry<?, ?>> parts) throws IOException { notNull(appendable); if (parts.hasNext()) { Entry<?, ?> entry = parts.next(); appendable.append(joiner.toString(entry.getKey())); appendable.append(keyValueSeparator); appendable.append(joiner.toString(entry.getValue())); while (parts.hasNext()) { appendable.append(joiner.separator); Entry<?, ?> e = parts.next(); appendable.append(joiner.toString(e.getKey())); appendable.append(keyValueSeparator); appendable.append(joiner.toString(e.getValue())); } } return appendable; }
/** * Appends the string representation of each of {@code parts}, using the previously configured separator between * each, to {@code builder}. Identical to {@link #appendTo(Appendable, Iterable)}, except that it does not throw * {@link IOException}. */ public final StringBuilder appendTo(StringBuilder builder, Iterable<?> parts) { return appendTo(builder, parts.iterator()); }
/** * Returns a string containing the string representation of each of {@code parts}, using the previously configured * separator between each. * * @since 11.0 */ public final String join(Iterator<?> parts) { return appendTo(new StringBuilder(), parts).toString(); }
/** * Appends the string representation of each of {@code parts}, using the previously configured separator between * each, to {@code builder}. Identical to {@link #appendTo(Appendable, Iterable)}, except that it does not throw * {@link IOException}. * * @since 11.0 */ public final StringBuilder appendTo(StringBuilder builder, Iterator<?> parts) { try { appendTo((Appendable) builder, parts); } catch (IOException impossible) { throw new AssertionError(impossible); } return builder; }