Java enum example

来源:互联网 发布:珠海市网络推广专员 编辑:程序博客网 时间:2024/05/22 03:34


public enum EnumTest {
            /** 入口網站通知 */
EIP(0)
            /** E-Mail通知 */
, Email(1)
;


private static EnumTest[] allEnums = {
EIP
, Email
};


private EnumTest(int value) {
}


public static EnumTest[] getAllEnums() {
return allEnums;
}


public int value() {
return ordinal();
}


public static EnumTest getEnum(int value) {
switch (value) {
case 0:
return EIP;
case 1:
return Email;
default:
return null;
}
}


public static EnumTest getEnum(String value) {
return EnumTest.valueOf(value);
}


/**
     * Checks whether the enum's value is greater than the input enum's value.
     */
    public boolean above(EnumTest input) {
        return compareTo(input) > 0;
    }


    /**
     * Checks whether the enum's value is less than the input enum's value.
     */
    public boolean below(EnumTest input) {
        return compareTo(input) < 0;
    }

}

原创粉丝点击