枚举类型使⽤⽰例
⼀枚举类型的定义:
public enum MamsOperateAction {
NEW(0,"新建"),APPLY_DOWNLOAD(1,"申请下载"),UPLOAD(2,"上传"),
DOWNLOAD(3,"下载"),MOVE(4,"移动"),CREATE_PREIVEW(5,"⽣成预览流"),
RECOVER(6,"还原"),CATALOG(7,"编⽬"),DELETE(8,"删除"),LEGO_IMPORT(9,"LEGO_IMPORT"),
SHARE(10,"共享");
private MamsOperateAction(Integer act, String comment){
this.act = act;
thisment = comment;
}
private Integer act;
private String comment;
public Integer getAct(){
return act;
}
public String getComment(){
return comment;
}
public static MamsOperateAction getMamsOperateActionByAct(Integer act){
for(MamsOperateAction mamsOperateAction : MamsOperateAction.values()){
Act().equals(act)){
return mamsOperateAction;
}
}
return null;
}
public static MamsOperateAction getMamsOperateActionByAct(String comment){
for(MamsOperateAction mamsOperateAction : MamsOperateAction.values()){
Comment().equals(comment)){
return mamsOperateAction;
}
}
enum类型如何使用
return null;
}
}
⼆枚举类型测试使⽤:
public class MamsOperateActionTest {
@Test
public void testEnumMamsOperateAction(){
MamsOperateAction operateAction = MamsOperateAction.APPLY_DOWNLOAD;//赋值
MamsOperateAction a = Enum.valueOf(MamsOperateAction.class,"APPLY_DOWNLOAD");//根据字符串名称,返回枚举类型的常量
MamsOperateAction b = MamsOperateAction.valueOf("APPLY_DOWNLOAD");
Assert.assertEquals(operateAction,a);
Assert.assertEquals(a,b);
Assert.assertEquals(MamsOperateAction.APPLY_DOWNLOAD.name(),"APPLY_DOWNLOAD");//测试枚举类型常量的名称
Assert.assertEquals(MamsOperateAction.APPLY_MamsOperateActionByAct(1));//根据act获取指定的枚举类型}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。