Java Code Examples for java.util.StringJoiner#merge()

The following examples show how to use java.util.StringJoiner#merge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 2
Source File: MergeTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 3
Source File: MergeTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyThis() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");
}
 
Example 4
Source File: MergeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyOther() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");

    other.setEmptyValue("EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");
}
 
Example 5
Source File: MergeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testNull() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    try {
        sj.merge(null);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException npe) {
        // expected
    }
}
 
Example 6
Source File: MergeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void testSimple() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d,e,f}");
}
 
Example 7
Source File: MergeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testSimple() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d,e,f}");
}
 
Example 8
Source File: MergeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void testCascadeEmpty() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner o1 = new StringJoiner(":", "[", "]").setEmptyValue("Empty1");
    StringJoiner o2 = new StringJoiner(",", "<", ">").setEmptyValue("Empty2");

    o1.merge(o2);
    assertEquals(o1.toString(), "Empty1");

    sj.merge(o1);
    assertEquals(sj.toString(), "{}");
}
 
Example 9
Source File: MergeTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void testNull() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    try {
        sj.merge(null);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException npe) {
        // expected
    }
}
 
Example 10
Source File: MergeTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testDelimiter() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d:e:f}");
}
 
Example 11
Source File: MergeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testSimple() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d,e,f}");
}
 
Example 12
Source File: MergeTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyThis() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");
}
 
Example 13
Source File: MergeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void testNull() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    try {
        sj.merge(null);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException npe) {
        // expected
    }
}
 
Example 14
Source File: MergeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyThis() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");
}
 
Example 15
Source File: MergeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testDelimiter() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d:e:f}");
}
 
Example 16
Source File: MergeTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testDelimiter() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d:e:f}");
}
 
Example 17
Source File: MergeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void testSimple() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d,e,f}");
}
 
Example 18
Source File: MergeTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyThis() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");
}
 
Example 19
Source File: MergeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testDelimiter() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d:e:f}");
}
 
Example 20
Source File: MergeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyThis() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");
}