学习原博 https://blog.csdn.net/qq_27093465/article/details/52180865
package com.example.demo.bean.baseBean;
import org.springframework.util.StringUtils;
import java.util.Arrays;
/**
* @Author:
* @Date: 2018/12/21 09:06
* @Description:
*/
public class constructionBean {
/**
* 应用类型枚举
*/
enum AppTypeEnum {
ANDROID, IOS, WINDOWS
}
/**
* 颜色枚举
*/
enum ColorEnmu {
RED, GREEN, YELLOW
}
/**
* 信号灯转换
*
* @param color
* @return
*/
public static ColorEnmu changTraficColor(ColorEnmu color) {
switch (color) {
case RED:
color = ColorEnmu.GREEN;
break;
case GREEN:
color = ColorEnmu.YELLOW;
break;
case YELLOW:
color = ColorEnmu.RED;
break;
}
return color;
}
/**
* 班级枚举值
*/
public enum ClassEnum {
CLASS_ENUM1(1, "一班"),
CLASS_ENUM2(2, "二班"),
CLASS_ENUM3(3, "三班");
private int index;
private String name;
ClassEnum(int index, String name) {
this.index = index;
this.name = name;
}
public static String getNameByIndex(int a) {
String name = null;
for (ClassEnum classEnum : ClassEnum.values()) {
if (a == classEnum.getIndex()) {
return classEnum.getName();
}
}
return name;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static void main(String[] args) {
// for (AppTypeEnum a :AppTypeEnum.values()) {
// System.out.println(a);
// }
// System.out.println(AppTypeEnum.valueOf("IOS"));
// ColorEnmu colorEnmu = ColorEnmu.RED;
// for (int i=1;i<10;i++){
// ColorEnmu colorEnmuTemp = colorEnmu;
// colorEnmu = changTraficColor(colorEnmu);
// System.out.println("第"+i+"次灯色由【"+colorEnmuTemp+"】变成【"+colorEnmu+"】");
// }
int c = 4;
System.out.println(ClassEnum.getNameByIndex(c));
}
}