use of java8.util.StringJoiner in project streamsupport by stefan-zobel.
the class MergeTest method testMergeSelf.
public void testMergeSelf() {
fixesStream().forEach(fixes -> {
final StringJoiner sj = new StringJoiner(",", fixes.pre0, fixes.suf0).add("a").add("b");
assertEquals(sj.merge(sj).toString(), fixes.pre0 + "a,b,a,b" + fixes.suf0);
assertEquals(sj.merge(sj).toString(), fixes.pre0 + "a,b,a,b,a,b,a,b" + fixes.suf0);
});
}
use of java8.util.StringJoiner in project streamsupport by stefan-zobel.
the class StringJoinerTest method toStringWithCustomEmptyValue.
public void toStringWithCustomEmptyValue() {
StringJoiner sj = new StringJoiner(DASH, "<", ">").setEmptyValue(EMPTY);
assertEquals(sj.toString(), EMPTY);
sj.add("");
assertEquals(sj.toString(), "<>");
sj.add("");
assertEquals(sj.toString(), "<->");
}
use of java8.util.StringJoiner in project streamsupport by stefan-zobel.
the class StringJoinerTest method stringFromtoString.
public void stringFromtoString() {
StringJoiner sj = new StringJoiner(", ");
assertEquals(sj.toString(), "");
sj = new StringJoiner(",", "{", "}");
assertEquals(sj.toString(), "{}");
sj = new StringJoiner(",");
sj.add(ONE);
assertEquals(sj.toString(), ONE);
sj.add(TWO);
assertEquals(sj.toString(), ONE + "," + TWO);
sj = new StringJoiner(",", "{--", "--}");
sj.add(ONE);
sj.add(TWO);
assertEquals(sj.toString(), "{--" + ONE + "," + TWO + "--}");
}
use of java8.util.StringJoiner in project streamsupport by stefan-zobel.
the class StringJoinerTest method addAlladdAll.
// The following tests do two successive adds of different types
public void addAlladdAll() {
final StringJoiner sj = new StringJoiner(DASH, "{", "}");
ArrayList<String> firstOne = new ArrayList<String>();
firstOne.add(ONE);
firstOne.add(TWO);
firstOne.add(THREE);
Stream<String> stream = StreamSupport.stream(firstOne);
stream.forEachOrdered(new java8.util.function.Consumer<String>() {
@Override
public void accept(String t) {
sj.add(t);
}
});
ArrayList<String> nextOne = new ArrayList<String>();
nextOne.add(FOUR);
nextOne.add(FIVE);
Stream<String> stream2 = StreamSupport.stream(nextOne);
stream2.forEachOrdered(new java8.util.function.Consumer<String>() {
@Override
public void accept(String t) {
sj.add(t);
}
});
String expected = "{" + ONE + DASH + TWO + DASH + THREE + DASH + FOUR + DASH + FIVE + "}";
assertEquals(sj.toString(), expected);
}
use of java8.util.StringJoiner in project streamsupport by stefan-zobel.
the class StringJoinerTest method addCharSequence.
public void addCharSequence() {
StringJoiner sj = new StringJoiner(",");
CharSequence cs_one = ONE;
CharSequence cs_two = TWO;
sj.add(cs_one);
sj.add(cs_two);
assertEquals(sj.toString(), ONE + "," + TWO);
sj = new StringJoiner(DASH, "{", "}");
sj.add(cs_one);
sj.add(cs_two);
assertEquals(sj.toString(), "{" + ONE + DASH + TWO + "}");
StringBuilder builder = new StringBuilder(ONE);
StringBuffer buffer = new StringBuffer(THREE);
sj = new StringJoiner(", ", "{ ", " }");
sj.add(builder).add(buffer);
builder.append(TWO);
buffer.append(FOUR);
assertEquals(sj.toString(), "{ " + ONE + ", " + THREE + " }", "CharSequence is copied when add");
sj.add(builder);
assertEquals(sj.toString(), "{ " + ONE + ", " + THREE + ", " + ONE + TWO + " }");
}
Aggregations