package cn.sagacloud.server.datacenter.utils

import java.util.HashMap

/**
 * 类型识别工具 泛型
 *
 * @author 张维新
 */
object TypeToolsGenerics {

    private val typeMap = HashMap<String, String>()
    init {
        typeMap["java.lang.Byte"] = "byte"
        typeMap["java.lang.Short"] = "short"
        typeMap["java.lang.Integer"] = "int"
        typeMap["java.lang.Long"] = "long"
        typeMap["java.lang.Double"] = "double"
        typeMap["java.lang.Float"] = "float"
        typeMap["java.lang.Character"] = "char"
        typeMap["java.lang.Boolean"] = "boolean"
        typeMap["java.lang.String"] = "String"
        typeMap["Str"] = "String"
        typeMap["Enum"] = "String"
        typeMap["Num"] = "double"
        typeMap["Enumv"] = "String"
        typeMap["Inst"] = "String"
        typeMap["Acc"] = "String"
        typeMap["Time"] = "String"
    }
    fun <T : Any> getType(t: T?): String? {
        if (t == null) {
            return null
        }
        val typeInfo = t.javaClass.name
        return if (typeMap.containsKey(typeInfo)) typeMap[typeInfo] else typeInfo
    } // Function getType()
} // Class TypeToolsGenerics