package com.huawei.web.util;
public enum DbParamEnum
{
userName(0),userPwd(1);
private int iValue;
private static final String exception = "Invalid Enum Value";
private DbParamEnum(int iValue)
{
this.iValue = iValue;
}
public int getIValue()
{
return iValue;
}
public static DbParamEnum valueOf(int iValue)
{
for (DbParamEnum type : DbParamEnum.values())
{
if (type.getIValue() == iValue)
{
return type;
}
}
throw new IllegalArgumentException(exception);
}
public String toString()
{
return String.valueOf(iValue);
}
}
public static DbTypeEnum getDBTypeEnum(String dbtype)
{
DbTypeEnum type = DbTypeEnum.ORACLE;
if (dbtype.equals(DbTypeEnum.ORACLE.name()))
{
type = DbTypeEnum.ORACLE;
}
else if (dbtype.equals(DbTypeEnum.DB2.name()))
{
type = DbTypeEnum.DB2;
}
else if (dbtype.equals(DbTypeEnum.SQLSERVER.name()))
{
type = DbTypeEnum.SQLSERVER;
}
else if (dbtype.equals(DbTypeEnum.SYBASE.name()))
{
type = DbTypeEnum.SYBASE;
}
return type;
}
public enum DbParamEnum
{
userName(0),userPwd(1);
private int iValue;
private static final String exception = "Invalid Enum Value";
private DbParamEnum(int iValue)
{
this.iValue = iValue;
}
public int getIValue()
{
return iValue;
}
public static DbParamEnum valueOf(int iValue)
{
for (DbParamEnum type : DbParamEnum.values())
{
if (type.getIValue() == iValue)
{
return type;
}
}
throw new IllegalArgumentException(exception);
}
public String toString()
{
return String.valueOf(iValue);
}
}
public static DbTypeEnum getDBTypeEnum(String dbtype)
{
DbTypeEnum type = DbTypeEnum.ORACLE;
if (dbtype.equals(DbTypeEnum.ORACLE.name()))
{
type = DbTypeEnum.ORACLE;
}
else if (dbtype.equals(DbTypeEnum.DB2.name()))
{
type = DbTypeEnum.DB2;
}
else if (dbtype.equals(DbTypeEnum.SQLSERVER.name()))
{
type = DbTypeEnum.SQLSERVER;
}
else if (dbtype.equals(DbTypeEnum.SYBASE.name()))
{
type = DbTypeEnum.SYBASE;
}
return type;
}
本文介绍了一个Java枚举类型的实现案例,展示了如何定义枚举并实现自定义方法,包括通过整数值获取枚举实例及字符串转换。同时,文中还提供了一个数据库类型的获取方法。
421

被折叠的 条评论
为什么被折叠?



