/** * 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(); }
@Override public String toString() { return Joiner.on(", ") .appendTo(new StringBuilder().append('['), this) .append(']') .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}. */ @CanIgnoreReturnValue public final StringBuilder appendTo(StringBuilder builder, Iterable<?> parts) { return appendTo(builder, parts.iterator()); }
/** * Appends the string representation of each of {@code parts}, using the previously configured * separator between each, to {@code appendable}. */ @CanIgnoreReturnValue 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 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}. */ @CanIgnoreReturnValue public final StringBuilder appendTo(StringBuilder builder, Object[] parts) { return appendTo(builder, Arrays.asList(parts)); }
/** * Appends the string representation of each of {@code parts}, using the previously configured * separator between each, to {@code appendable}. */ @CanIgnoreReturnValue 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. * * @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 */ @CanIgnoreReturnValue public final StringBuilder appendTo(StringBuilder builder, Iterator<?> parts) { try { appendTo((Appendable) builder, parts); } catch (IOException impossible) { throw new AssertionError(impossible); } return builder; }
@Override public String toString() { return Joiner.on(", ") .appendTo(new StringBuilder().append('['), this) .append(']') .toString(); } };
/** * Appends the string representation of each of {@code parts}, using the previously configured * separator between each, to {@code appendable}. */ @CanIgnoreReturnValue 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 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}. */ @CanIgnoreReturnValue public final StringBuilder appendTo(StringBuilder builder, Iterable<?> parts) { return appendTo(builder, parts.iterator()); }
/** * Appends the string representation of each of {@code parts}, using the previously configured * separator between each, to {@code appendable}. */ @CanIgnoreReturnValue public <A extends Appendable> A appendTo(A appendable, Iterable<?> parts) throws IOException { return appendTo(appendable, parts.iterator()); }
/** * 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}. */ @CanIgnoreReturnValue public final StringBuilder appendTo(StringBuilder builder, Object[] parts) { return appendTo(builder, Arrays.asList(parts)); }
@Override protected String visitLambdaExpression(LambdaExpression node, Void context) { StringBuilder builder = new StringBuilder(); builder.append('('); Joiner.on(", ").appendTo(builder, node.getArguments()); builder.append(") -> "); builder.append(process(node.getBody(), context)); return builder.toString(); }
@Override protected Void visitExecute(Execute node, Integer indent) { append(indent, "EXECUTE "); builder.append(node.getName()); List<Expression> parameters = node.getParameters(); if (!parameters.isEmpty()) { builder.append(" USING "); Joiner.on(", ").appendTo(builder, parameters); } return null; }
/** Appends to {@code appendable} the string representation of each of the remaining arguments. */ @CanIgnoreReturnValue 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)); }
/** * 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}. */ @CanIgnoreReturnValue public final StringBuilder appendTo( StringBuilder builder, @Nullable Object first, @Nullable Object second, Object... rest) { return appendTo(builder, iterable(first, second, rest)); }
private static void checkResult(Joiner joiner, Iterable<Integer> parts, String expected) { assertEquals(expected, joiner.join(parts)); assertEquals(expected, joiner.join(parts.iterator())); StringBuilder sb1FromIterable = new StringBuilder().append('x'); joiner.appendTo(sb1FromIterable, parts); assertEquals("x" + expected, sb1FromIterable.toString()); StringBuilder sb1FromIterator = new StringBuilder().append('x'); joiner.appendTo(sb1FromIterator, parts.iterator()); assertEquals("x" + expected, sb1FromIterator.toString()); Integer[] partsArray = Lists.newArrayList(parts).toArray(new Integer[0]); assertEquals(expected, joiner.join(partsArray)); StringBuilder sb2 = new StringBuilder().append('x'); joiner.appendTo(sb2, partsArray); assertEquals("x" + expected, sb2.toString()); int num = partsArray.length - 2; if (num >= 0) { Object[] rest = new Integer[num]; for (int i = 0; i < num; i++) { rest[i] = partsArray[i + 2]; } assertEquals(expected, joiner.join(partsArray[0], partsArray[1], rest)); StringBuilder sb3 = new StringBuilder().append('x'); joiner.appendTo(sb3, partsArray[0], partsArray[1], rest); assertEquals("x" + expected, sb3.toString()); } }
private static void checkNoOutput(Joiner joiner, Iterable<Integer> set) { assertEquals("", joiner.join(set)); assertEquals("", joiner.join(set.iterator())); Object[] array = Lists.newArrayList(set).toArray(new Integer[0]); assertEquals("", joiner.join(array)); StringBuilder sb1FromIterable = new StringBuilder(); assertSame(sb1FromIterable, joiner.appendTo(sb1FromIterable, set)); assertEquals(0, sb1FromIterable.length()); StringBuilder sb1FromIterator = new StringBuilder(); assertSame(sb1FromIterator, joiner.appendTo(sb1FromIterator, set)); assertEquals(0, sb1FromIterator.length()); StringBuilder sb2 = new StringBuilder(); assertSame(sb2, joiner.appendTo(sb2, array)); assertEquals(0, sb2.length()); try { joiner.appendTo(NASTY_APPENDABLE, set); } catch (IOException e) { throw new AssertionError(e); } try { joiner.appendTo(NASTY_APPENDABLE, set.iterator()); } catch (IOException e) { throw new AssertionError(e); } try { joiner.appendTo(NASTY_APPENDABLE, array); } catch (IOException e) { throw new AssertionError(e); } }
/** Appends to {@code appendable} the string representation of each of the remaining arguments. */ @CanIgnoreReturnValue public final <A extends Appendable> A appendTo( A appendable, @NullableDecl Object first, @NullableDecl Object second, Object... rest) throws IOException { return appendTo(appendable, iterable(first, second, rest)); }