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

org.dbtools.codegen.kotlin.KotlinEnum.kt Maven / Gradle / Ivy

There is a newer version: 11.0.0
Show newest version
/*
 * KotlinEnum.kt
 *
 * Created on Nov 7, 2015
 *
 * Copyright 2007 Jeff Campbell. All rights reserved. Unauthorized reproduction
 * is a violation of applicable law. This material contains certain
 * confidential or proprietary information and trade secrets of Jeff Campbell.
 */

package org.dbtools.codegen.kotlin

import java.util.*

@SuppressWarnings("PMD.UseStringBufferForStringAppends")
class KotlinEnum : KotlinClass {

    private val enums = ArrayList()

    constructor(name: String, enums: List) : super(name, classType = KotlinClassType.ENUM) {
        setEnums(enums)
    }

    constructor(name: String, packageName: String, enums: List) : super(name, packageName, KotlinClassType.ENUM) {
        setEnums(enums)
    }

    fun getEnums(): List {
        return Collections.unmodifiableList(enums)
    }

    fun setEnums(enums: List) {
        if (enums.isEmpty()) {
            throw IllegalArgumentException("enums cannot be null or empty")
        }

        this.enums.clear()
        this.enums.addAll(enums)
    }

    override fun buildPostClassHeader(): String {
        var enumStr = ""

        var count = 0
        for (enumItem in enums) {
            if (count > 0) {
                enumStr += ", "
            }

            enumStr += enumItem

            count++
        }

        enumStr += ";\n"

        return enumStr
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy