Migrate to using join* functions instead of deprecated.
This commit is contained in:
committed by
Andrey Breslav
parent
19858b9f74
commit
f471f7901c
@@ -333,7 +333,7 @@ fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
|
||||
/** Converts the collection of nodes to an XML String */
|
||||
public fun nodesToXmlString(nodes: Iterable<Node>, xmlDeclaration: Boolean = false): String {
|
||||
// TODO this should work...
|
||||
// return this.map{it.toXmlString()}.makeString("")
|
||||
// return this.map{it.toXmlString()}.join("")
|
||||
val builder = StringBuilder()
|
||||
for (n in nodes) {
|
||||
builder.append(n.toXmlString(xmlDeclaration))
|
||||
|
||||
@@ -109,7 +109,7 @@ get() = childNodes.outerHTML
|
||||
* Returns the HTML representation of the nodes
|
||||
*/
|
||||
public val NodeList.outerHTML: String
|
||||
get() = toList().map { it.innerHTML }.makeString("")
|
||||
get() = toList().map { it.innerHTML }.join("")
|
||||
|
||||
/** Returns an [[Iterator]] of all the next [[Element]] siblings */
|
||||
fun Node.nextElements(): List<Element> = nextSiblings().filterIsInstance<Node, Element>(javaClass<Element>())
|
||||
@@ -130,7 +130,7 @@ get() {
|
||||
return answer
|
||||
}
|
||||
set(value) {
|
||||
this.classes = value.makeString(" ")
|
||||
this.classes = value.join(" ")
|
||||
}
|
||||
|
||||
/** Adds the given CSS class to this element's 'class' attribute */
|
||||
|
||||
@@ -13,7 +13,7 @@ class CollectionJVMTest {
|
||||
val characters = data.flatMap { it.toCharList() }
|
||||
println("Got list of characters ${characters}")
|
||||
assertEquals(7, characters.size())
|
||||
val text = characters.makeString("")
|
||||
val text = characters.joinToString("")
|
||||
assertEquals("foobarx", text)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,20 +6,20 @@ import org.junit.Test as test
|
||||
|
||||
class CollectionTest {
|
||||
|
||||
test fun appendString() {
|
||||
test fun joinTo() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val buffer = StringBuilder()
|
||||
val text = data.appendString(buffer, "-", "{", "}")
|
||||
data.joinTo(buffer, "-", "{", "}")
|
||||
assertEquals("{foo-bar}", buffer.toString())
|
||||
}
|
||||
|
||||
test fun makeString() {
|
||||
test fun join() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val text = data.makeString("-", "<", ">")
|
||||
val text = data.join("-", "<", ">")
|
||||
assertEquals("<foo-bar>", text)
|
||||
|
||||
val big = arrayListOf("a", "b", "c", "d", "e", "f")
|
||||
val text2 = big.makeString(limit = 3, truncated = "*")
|
||||
val text2 = big.join(limit = 3, truncated = "*")
|
||||
assertEquals("a, b, c, *", text2)
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
|
||||
}
|
||||
|
||||
test fun iterateWithProperties() {
|
||||
@@ -85,7 +85,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
|
||||
}
|
||||
|
||||
test fun iterateWithExtraction() {
|
||||
@@ -102,7 +102,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
|
||||
}
|
||||
|
||||
test fun contains() {
|
||||
@@ -203,7 +203,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
|
||||
println("==== worked! $list")
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -65,18 +65,18 @@ public class StreamTest {
|
||||
}
|
||||
|
||||
test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
|
||||
assertEquals("13, 21, 34, 55, 89, ...", fibonacci().filter { it > 10 }.makeString(separator = ", ", limit = 5))
|
||||
assertEquals("13, 21, 34, 55, 89, ...", fibonacci().filter { it > 10 }.joinToString(separator = ", ", limit = 5))
|
||||
}
|
||||
|
||||
test fun skippingIterator() {
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(7).makeString(limit = 10))
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(3).drop(4).makeString(limit = 10))
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(7).joinToString(limit = 10))
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(3).drop(4).joinToString(limit = 10))
|
||||
}
|
||||
|
||||
test fun toStringJoinsNoMoreThanTheFirstTenElements() {
|
||||
assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().makeString(limit = 10))
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.makeString(limit = 10))
|
||||
assertEquals("144, 233, 377, 610, 987", fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.makeString())
|
||||
assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().joinToString(limit = 10))
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.joinToString(limit = 10))
|
||||
assertEquals("144, 233, 377, 610, 987", fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.joinToString())
|
||||
}
|
||||
|
||||
test fun plus() {
|
||||
@@ -146,7 +146,7 @@ public class StreamTest {
|
||||
|
||||
/*
|
||||
test fun pairIterator() {
|
||||
val pairStr = (fibonacci() zip fibonacci().map { i -> i*2 }).makeString(limit = 10)
|
||||
val pairStr = (fibonacci() zip fibonacci().map { i -> i*2 }).joinToString(limit = 10)
|
||||
assertEquals("(0, 0), (1, 2), (1, 2), (2, 4), (3, 6), (5, 10), (8, 16), (13, 26), (21, 42), (34, 68), ...", pairStr)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -219,7 +219,7 @@ abstract class MapJsTest {
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
|
||||
}
|
||||
|
||||
test fun iterateWithProperties() {
|
||||
@@ -236,7 +236,7 @@ abstract class MapJsTest {
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
|
||||
}
|
||||
|
||||
test fun map() {
|
||||
@@ -305,7 +305,7 @@ abstract class MapJsTest {
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
|
||||
println("==== worked! $list")
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,7 @@ fun customerTemplate(customer: Customer) = """
|
||||
<body>
|
||||
<h1>Hello ${customer.name}</h1>
|
||||
<ul>
|
||||
${customer.products.map{ productSnippet(it) }.makeString("\n")}
|
||||
${customer.products.map{ productSnippet(it) }.join("\n")}
|
||||
</ul>
|
||||
<p>lets do some kool stuff</p>
|
||||
</body>
|
||||
|
||||
@@ -111,10 +111,10 @@ class StringJVMTest {
|
||||
}
|
||||
}
|
||||
|
||||
test fun appendString() {
|
||||
val data = "kotlin"
|
||||
test fun joinTo() {
|
||||
val data = "kotlin".toList()
|
||||
val sb = StringBuilder()
|
||||
data.appendString(sb, "^", "<", ">")
|
||||
data.joinTo(sb, "^", "<", ">")
|
||||
assertEquals("<k^o^t^l^i^n>", sb.toString())
|
||||
}
|
||||
|
||||
@@ -228,13 +228,23 @@ class StringJVMTest {
|
||||
assertEquals(listOf('a','b','b','a','c'), result.get(true))
|
||||
}
|
||||
|
||||
test fun makeString() {
|
||||
val data = "abcd"
|
||||
val result = data.makeString("_", "(", ")")
|
||||
test fun joinToString() {
|
||||
val data = "abcd".toList()
|
||||
val result = data.joinToString("_", "(", ")")
|
||||
assertEquals("(a_b_c_d)", result)
|
||||
|
||||
val data2 = "verylongstring"
|
||||
val result2 = data2.makeString("-", "[", "]", 11, "oops")
|
||||
val data2 = "verylongstring".toList()
|
||||
val result2 = data2.joinToString("-", "[", "]", 11, "oops")
|
||||
assertEquals("[v-e-r-y-l-o-n-g-s-t-r-oops]", result2)
|
||||
}
|
||||
|
||||
test fun join() {
|
||||
val data = "abcd".map { it.toString() }
|
||||
val result = data.join("_", "(", ")")
|
||||
assertEquals("(a_b_c_d)", result)
|
||||
|
||||
val data2 = "verylongstring".map { it.toString() }
|
||||
val result2 = data2.join("-", "[", "]", 11, "oops")
|
||||
assertEquals("[v-e-r-y-l-o-n-g-s-t-r-oops]", result2)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user