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

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

There is a newer version: 11.0.0
Show newest version
/*
 * KotlinInnerEnum.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 org.dbtools.codegen.java.Access
import org.dbtools.codegen.java.JavaClass

import java.util.Collections

/**
 * @author Jeff
 */
@SuppressWarnings("PMD.UseStringBufferForStringAppends")
class KotlinInnerEnum(enumName: String, enumValues: List?) {

    var access = Access.PUBLIC
    var name: String? = null
    var values: List? = null
        get() = Collections.unmodifiableList(values)

    init {
        this.name = enumName

        if (enumValues == null) {
            throw IllegalArgumentException("enumValues cannot be null")
        }
        this.values = enumValues
    }

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

        val accessText = JavaClass.getAccessString(access)
        enumStr += accessText

        enumStr += " static enum $name {\n        " // includes 2 TABS for the next line

        var numItems = 0
        for (enumItem in values!!) {
            numItems++
            if (numItems > 1) {
                enumStr += ", "
            }
            enumStr += enumItem
        }

        enumStr += "\n    }"

        return enumStr
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy