本文整理汇总了Java中java.util.StringJoiner.merge方法的典型用法代码示例。如果您正苦于以下问题:Java StringJoiner.merge方法的具体用法?Java StringJoiner.merge怎么用?Java StringJoiner.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.StringJoiner
的用法示例。
在下文中一共展示了StringJoiner.merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEmptyBoth
import java.util.StringJoiner; //导入方法依赖的package包/类
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");
}
示例2: testNull
import java.util.StringJoiner; //导入方法依赖的package包/类
public void testNull() {
StringJoiner sj = new StringJoiner(",", "{", "}");
try {
sj.merge(null);
fail("Should throw NullPointerException!");
} catch (NullPointerException npe) {
// expected
}
}
示例3: testSimple
import java.util.StringJoiner; //导入方法依赖的package包/类
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}");
}
示例4: testEmptyOther
import java.util.StringJoiner; //导入方法依赖的package包/类
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}");
}
示例5: testEmptyThis
import java.util.StringJoiner; //导入方法依赖的package包/类
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}");
}
示例6: testCascadeEmpty
import java.util.StringJoiner; //导入方法依赖的package包/类
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(), "{}");
}
示例7: testDelimiter
import java.util.StringJoiner; //导入方法依赖的package包/类
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}");
}
示例8: testNull
import java.util.StringJoiner; //导入方法依赖的package包/类
@Test(expectedExceptions = {NullPointerException.class})
public void testNull() {
StringJoiner sj = new StringJoiner(",", "{", "}");
sj.merge(null);
}