public interface EnumMatchInteger
使用例子:
public enum StringType implements EnumStringCode, EnumMatchInteger
{
// 集团编码。
ENTERPRISE
{
public String getCode()
{
return "a";
}
public boolean isMatch(int val)
{
return val == 1;
}
},
// 成员。
PERSONAL
{
public String getCode()
{
return "b";
}
public boolean isMatch(int val)
{
return val == 2 || val == 3;
}
},
UNKNOWN
{
public String getCode()
{
return "";
}
public boolean isMatch(int val)
{
return val <= 0;
}
};
// 通过字符串值获取指定类型。
public static StringType get(String code)
{
if (code != null && (code = code.trim()).length() > 0)
{
for (StringType val : StringType.values())
{
if (code.equalsIgnoreCase(val.getCode()))
{
return val;
}
}
}
return UNKNOWN;
}
// 通过整型值获取指定类型。
public static SimType get(int code)
{
for (SimType val : SimType.values())
{
if (val.isMatch(code))
{
return val;
}
}
return UNKNOWN;
}
}
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
isMatch(int val)
值匹配时返回true。
|
Copyright © 2001-2014 hynnet.com