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

com.ancientlightstudios.quarkus.kotlin.openapi.transformer.NameRegistry.kt Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
package com.ancientlightstudios.quarkus.kotlin.openapi.transformer

import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformed.name.ClassName

class NameRegistry {

    private val nameBuilder = mutableMapOf()

    fun uniqueNameFor(name: ClassName): ClassName {
        val builder = nameBuilder[name]
        return if (builder != null) {
            builder.next()
        } else {
            nameBuilder[name] = NameBuilder(name)
            name
        }
    }

    private class NameBuilder(private val name: ClassName) {

        private var nextIndex = 1

        fun next() = name.extend(postfix = "${nextIndex++}")

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy