Search in sources :

Example 21 with StringJoiner

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 + " }");
}
Also used : StringJoiner(java.util.StringJoiner)

Example 22 with StringJoiner

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());
}
Also used : StringJoiner(java.util.StringJoiner)

Example 23 with StringJoiner

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);
}
Also used : ArrayList(java.util.ArrayList) StringJoiner(java.util.StringJoiner)

Example 24 with StringJoiner

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();
}
Also used : StringJoiner(java.util.StringJoiner) Test(org.testng.annotations.Test)

Example 25 with StringJoiner

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;
}
Also used : DecimalFormat(java.text.DecimalFormat) StringJoiner(java.util.StringJoiner)

Aggregations

StringJoiner (java.util.StringJoiner)94 ArrayList (java.util.ArrayList)20 List (java.util.List)10 HashSet (java.util.HashSet)6 Map (java.util.Map)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 ClassName (com.squareup.javapoet.ClassName)3 FieldSpec (com.squareup.javapoet.FieldSpec)3 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)3 TypeName (com.squareup.javapoet.TypeName)3 TypeSpec (com.squareup.javapoet.TypeSpec)3 Expression (com.sri.ai.expresso.api.Expression)3 Attribute (io.requery.meta.Attribute)3 Scanner (java.util.Scanner)3 RaptorColumnHandle (com.facebook.presto.raptor.RaptorColumnHandle)2 Range (com.facebook.presto.spi.predicate.Range)2 MaterializedResult (com.facebook.presto.testing.MaterializedResult)2 MaterializedRow (com.facebook.presto.testing.MaterializedRow)2