com.likethesalad.android.templates.common.tasks.identifier.data.TemplateItemsSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-tools Show documentation
Show all versions of common-tools Show documentation
This is a Gradle plugin for Android applications which resolves XML string references in other XML strings.
The newest version!
package com.likethesalad.android.templates.common.tasks.identifier.data
object TemplateItemsSerializer {
private const val LIST_SEPARATOR = ","
private const val SINGLE_ITEM_VALUES_SEPARATOR = ":"
fun serialize(templates: List): String {
return templates.distinct()
.joinToString(LIST_SEPARATOR) { "${it.name}$SINGLE_ITEM_VALUES_SEPARATOR${it.type}" }
}
fun deserialize(string: String): List {
val separatedItems = string.split(LIST_SEPARATOR).filter { it.isNotEmpty() }
if (separatedItems.isEmpty()) {
return emptyList()
}
return separatedItems
.map { stringToTemplateItem(it) }
}
private fun stringToTemplateItem(value: String): TemplateItem {
val values = value.split(SINGLE_ITEM_VALUES_SEPARATOR)
return TemplateItem(values[0], values[1])
}
}