use of java.util.StringJoiner in project jdk8u_jdk by JetBrains.
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 + " }");
}
use of java.util.StringJoiner in project jdk8u_jdk by JetBrains.
the class StringJoinerTest method lengthWithCustomEmptyValue.
public void lengthWithCustomEmptyValue() {
StringJoiner sj = new StringJoiner(DASH, "<", ">").setEmptyValue(EMPTY);
assertEquals(sj.length(), EMPTY.length());
sj.add("");
assertEquals(sj.length(), "<>".length());
sj.add("");
assertEquals(sj.length(), "<->".length());
sj.add(ONE);
assertEquals(sj.length(), 4 + ONE_LEN);
assertEquals(sj.toString().length(), sj.length());
sj.add(TWO);
assertEquals(sj.length(), 5 + ONE_LEN + TWO_LEN);
assertEquals(sj.toString().length(), sj.length());
sj = new StringJoiner("||", "<", "-->");
assertEquals(sj.length(), 4);
assertEquals(sj.toString().length(), sj.length());
sj.add("abcdef");
assertEquals(sj.length(), 10);
assertEquals(sj.toString().length(), sj.length());
sj.add("xyz");
assertEquals(sj.length(), 15);
assertEquals(sj.toString().length(), sj.length());
}
use of java.util.StringJoiner in project jdk8u_jdk by JetBrains.
the class StringJoinerTest method addAlladd.
void addAlladd() {
StringJoiner sj = new StringJoiner(DASH, "{", "}");
ArrayList<String> firstOne = new ArrayList<>();
firstOne.add(ONE);
firstOne.add(TWO);
firstOne.stream().forEachOrdered(sj::add);
sj.add(THREE);
String expected = "{" + ONE + DASH + TWO + DASH + THREE + "}";
assertEquals(sj.toString(), expected);
}
use of java.util.StringJoiner in project jdk8u_jdk by JetBrains.
the class TabulatorsTest method testJoin.
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
public void testJoin(String name, TestData.OfRef<Integer> data) throws ReflectiveOperationException {
withData(data).terminal(s -> s.map(Object::toString).collect(Collectors.joining())).expectedResult(join(data, "")).exercise();
Collector<String, StringBuilder, String> likeJoining = Collector.of(StringBuilder::new, StringBuilder::append, (sb1, sb2) -> sb1.append(sb2.toString()), StringBuilder::toString);
withData(data).terminal(s -> s.map(Object::toString).collect(likeJoining)).expectedResult(join(data, "")).exercise();
withData(data).terminal(s -> s.map(Object::toString).collect(Collectors.joining(","))).expectedResult(join(data, ",")).exercise();
withData(data).terminal(s -> s.map(Object::toString).collect(Collectors.joining(",", "[", "]"))).expectedResult("[" + join(data, ",") + "]").exercise();
withData(data).terminal(s -> s.map(Object::toString).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString()).expectedResult(join(data, "")).exercise();
withData(data).terminal(s -> s.map(Object::toString).collect(() -> new StringJoiner(","), (sj, cs) -> sj.add(cs), (j1, j2) -> j1.merge(j2)).toString()).expectedResult(join(data, ",")).exercise();
withData(data).terminal(s -> s.map(Object::toString).collect(() -> new StringJoiner(",", "[", "]"), (sj, cs) -> sj.add(cs), (j1, j2) -> j1.merge(j2)).toString()).expectedResult("[" + join(data, ",") + "]").exercise();
}
use of java.util.StringJoiner in project intellij-community by JetBrains.
the class JavaFxColorProvider method getHsbCallText.
private static String getHsbCallText(Color color) {
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
DecimalFormat df = new DecimalFormat(DECIMAL_FORMAT_PATTERN, DECIMAL_FORMAT_SYMBOLS);
StringJoiner args = new StringJoiner(",", "(", ")");
args.add(df.format(hsb[0] * 360));
args.add(df.format(hsb[1]));
args.add(df.format(hsb[2]));
if (color.getAlpha() != 255) {
args.add(formatScaledComponent(color.getAlpha()));
}
return HSB + args;
}
Aggregations