Java 类org.apache.commons.lang.enums.Enum 实例源码

项目:lakeside-java    文件:StateEnum.java   
/**
   * 根据枚举对象的类型名称(类名的简写)和枚举值获取枚举名
   * @param simpleStateTypeName
   * @param value
   * @return
   */
  public static <T extends StateEnum> String getStateName(String simpleStateTypeName,int value){
    if (simpleStateTypeName == null) {
    throw new IllegalArgumentException("The Enum Class must not be null");
}
    Class<? extends StateEnum> stateType = simpleName2ClassMap.get(simpleStateTypeName);
    if (stateType == null) {
    throw new IllegalArgumentException("The Enum Class can't be found");
}
List<T> list = Enum.getEnumList(stateType);
for (Iterator<T> it = list.iterator(); it.hasNext();) {
    T enumeration = (T) it.next();
    if (enumeration.getValue() == value) {
        return enumeration.getName();
    }
}
return null;
  }
项目:wife    文件:SwiftServiceId.java   
/**
 * Tell if name is a valid service id, true if it is, and false ni any other
 * case. This method is null-safe.
 * 
 * @param name
 *            the name to test as service id, may be <code>null</code>
 * @return <code>true</code> if the parameter name is a valid service id
 * @since 6.0
 */
@SuppressWarnings("unchecked")
public static boolean contains(String name) {
    if (StringUtils.isNotEmpty(name)) {
        List values = getEnumList(SwiftServiceId.class);
        for (int i = 0; i < values.size(); i++) {
            if (StringUtils.equals(((Enum) values.get(i)).getName(), name)) {
                return true;
            }
        }
    }
    return false;
}
项目:lakeside-java    文件:StateEnum.java   
/**
   * 根据枚举对象的类型和枚举值获取枚举名
   * @param stateType
   * @param value
   * @return
   */
  public static <T extends StateEnum> String getStateName(Class<T> stateType,int value){
    if (stateType == null) {
    throw new IllegalArgumentException("The Enum Class must not be null");
}
List<T> list = Enum.getEnumList(stateType);
for (Iterator<T> it = list.iterator(); it.hasNext();) {
    T enumeration = (T) it.next();
    if (enumeration.getValue() == value) {
        return enumeration.getName();
    }
}
return null;
  }
项目:lakeside-java    文件:StateEnum.java   
/**
    * 根据枚举对象的类型和枚举值获取枚举
    * @param stateType
    * @param value
    * @return
    */
public static <T extends StateEnum> T getState(Class<T> stateType, int value) {
    if (stateType == null) {
        throw new IllegalArgumentException("The Enum Class must not be null");
    }
    List<T> list = Enum.getEnumList(stateType);
    for (Iterator<T> it = list.iterator(); it.hasNext();) {
        T enumeration = (T) it.next();
        if (enumeration.getValue() == value) {
            return enumeration;
        }
    }
    return null;
}
项目:lakeside-java    文件:StateEnum.java   
/**
 * 根据枚举对象的类型和枚举名称获取枚举
 * @param stateType
 * @param value
 * @return
 */
public static <T extends StateEnum> T getState(Class<T> stateType, String name) {
    if (stateType == null) {
        throw new IllegalArgumentException("The Enum Class must not be null");
    }
    Enum e = Enum.getEnum(stateType,name);
    return (T) e;
}