All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.likethesalad.android.templates.common.tasks.identifier.data.TemplateItemsSerializer.kt Maven / Gradle / Ivy

Go to download

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])
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy