package cmtech.soft.biz.utils.model;
import cmtech.soft.biz.utils.MyStrTool;
/**
* 工单状态
*/
public enum WorkOrderStatus {
CREATED("created", "未开始生产"),
RUNNING("running", "生产开始"),
PAUSED("paused", "生产暂停"),
ENDED("ended", "生产结束");
private String description;
private String code;
WorkOrderStatus(String code, String description) {// 对象初始化在枚举内部
this.description = description;
this.code = code;
}
public String getDescription() {
return description;
}
public String getCode() {
return code;
}
/**
* 根据枚举名字(无论大小写)获取枚举类型
* @param name 枚举名字
* @return 枚举类型
*/
public static WorkOrderStatus valueOfByEnumName(String name) {
if (!MyStrTool.isNullOrEmpty(name)) {
return valueOf(WorkOrderStatus.class, name.toUpperCase());
} else {
return null;
}
}
/**
* 根据枚举名字(无论大小写)获取枚举描述
* @param name 举名字(无论大小写)
* @return 枚举描述
*/
public static String getDescriptionByEnumName(String name){
WorkOrderStatus workOrderStatus= valueOfByEnumName(name);
if(workOrderStatus!=null){
return workOrderStatus.getDescription();
}else {
return "";
}
}
/**
* 根据枚举名字(无论大小写)获取枚举编码
* @param name 举名字(无论大小写)
* @return 枚举编码
*/
public static String getCodeByEnumName(String name){
WorkOrderStatus workOrderStatus= valueOfByEnumName(name);
if(workOrderStatus!=null){
return workOrderStatus.getCode();
}else {
return "";
}
}
}
class反编译成汇编,可以看到枚举被编译成一个类继承了Enum<cmtech.soft.biz.utils.model.WorkOrderStatus>类。cmtech.soft.biz.utils.model.WorkOrderStatus CREATED;是一个成员变量-字段。
有个方法valueOf调用了Enum类中的java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;方法
这个方法将当前对象的Class类对象和name名传入Enum的valueOf方法。
public static cmtech.soft.biz.utils.model.WorkOrderStatus valueOf(java.lang.String);
descriptor: (Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=1, args_size=1
0: ldc #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
2: aload_0
3: invokestatic #5 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
6: checkcast #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
9: areturn
LineNumberTable:
line 8: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 name Ljava/lang/String;
MethodParameters:
Name Flags
name mandated
/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/bin/javap -c -verbose -p cmtech.soft.biz.utils.model.WorkOrderStatus
Classfile /Users/smilezmh/Desktop/companywork/cmmes_biz_new/target/classes/cmtech/soft/biz/utils/model/WorkOrderStatus.class
Last modified 2020-9-25; size 2457 bytes
MD5 checksum bf5afa7e2727d74fac5940159e9d5338
Compiled from "WorkOrderStatus.java"
public final class cmtech.soft.biz.utils.model.WorkOrderStatus extends java.lang.Enum<cmtech.soft.biz.utils.model.WorkOrderStatus>
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_ENUM
Constant pool:
#1 = Fieldref #4.#75 // cmtech/soft/biz/utils/model/WorkOrderStatus.$VALUES:[Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#2 = Methodref #76.#77 // "[Lcmtech/soft/biz/utils/model/WorkOrderStatus;".clone:()Ljava/lang/Object;
#3 = Class #43 // "[Lcmtech/soft/biz/utils/model/WorkOrderStatus;"
#4 = Class #78 // cmtech/soft/biz/utils/model/WorkOrderStatus
#5 = Methodref #33.#79 // java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
#6 = Methodref #33.#80 // java/lang/Enum."<init>":(Ljava/lang/String;I)V
#7 = Fieldref #4.#81 // cmtech/soft/biz/utils/model/WorkOrderStatus.description:Ljava/lang/String;
#8 = Fieldref #4.#82 // cmtech/soft/biz/utils/model/WorkOrderStatus.code:Ljava/lang/String;
#9 = Methodref #83.#84 // cmtech/soft/biz/utils/MyStrTool.isNullOrEmpty:(Ljava/lang/String;)Z
#10 = Methodref #85.#86 // java/lang/String.toUpperCase:()Ljava/lang/String;
#11 = Methodref #4.#79 // cmtech/soft/biz/utils/model/WorkOrderStatus.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
#12 = Methodref #4.#87 // cmtech/soft/biz/utils/model/WorkOrderStatus.valueOfByEnumName:(Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#13 = Methodref #4.#88 // cmtech/soft/biz/utils/model/WorkOrderStatus.getDescription:()Ljava/lang/String;
#14 = String #89 //
#15 = Methodref #4.#90 // cmtech/soft/biz/utils/model/WorkOrderStatus.getCode:()Ljava/lang/String;
#16 = String #34 // CREATED
#17 = String #91 // created
#18 = String #92 // 未开始生产
#19 = Methodref #4.#93 // cmtech/soft/biz/utils/model/WorkOrderStatus."<init>":(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
#20 = Fieldref #4.#94 // cmtech/soft/biz/utils/model/WorkOrderStatus.CREATED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#21 = String #36 // RUNNING
#22 = String #95 // running
#23 = String #96 // 生产开始
#24 = Fieldref #4.#97 // cmtech/soft/biz/utils/model/WorkOrderStatus.RUNNING:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#25 = String #37 // PAUSED
#26 = String #98 // paused
#27 = String #99 // 生产暂停
#28 = Fieldref #4.#100 // cmtech/soft/biz/utils/model/WorkOrderStatus.PAUSED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#29 = String #38 // ENDED
#30 = String #101 // ended
#31 = String #102 // 生产结束
#32 = Fieldref #4.#103 // cmtech/soft/biz/utils/model/WorkOrderStatus.ENDED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#33 = Class #104 // java/lang/Enum
#34 = Utf8 CREATED
#35 = Utf8 Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#36 = Utf8 RUNNING
#37 = Utf8 PAUSED
#38 = Utf8 ENDED
#39 = Utf8 description
#40 = Utf8 Ljava/lang/String;
#41 = Utf8 code
#42 = Utf8 $VALUES
#43 = Utf8 [Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#44 = Utf8 values
#45 = Utf8 ()[Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#46 = Utf8 Code
#47 = Utf8 LineNumberTable
#48 = Utf8 valueOf
#49 = Utf8 (Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#50 = Utf8 LocalVariableTable
#51 = Utf8 name
#52 = Utf8 MethodParameters
#53 = Utf8 <init>
#54 = Utf8 (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
#55 = Utf8 this
#56 = Utf8 $enum$name
#57 = Utf8 $enum$ordinal
#58 = Utf8 Signature
#59 = Utf8 (Ljava/lang/String;Ljava/lang/String;)V
#60 = Utf8 getDescription
#61 = Utf8 ()Ljava/lang/String;
#62 = Utf8 getCode
#63 = Utf8 valueOfByEnumName
#64 = Utf8 StackMapTable
#65 = Utf8 getDescriptionByEnumName
#66 = Utf8 (Ljava/lang/String;)Ljava/lang/String;
#67 = Utf8 workOrderStatus
#68 = Class #78 // cmtech/soft/biz/utils/model/WorkOrderStatus
#69 = Utf8 getCodeByEnumName
#70 = Utf8 <clinit>
#71 = Utf8 ()V
#72 = Utf8 Ljava/lang/Enum<Lcmtech/soft/biz/utils/model/WorkOrderStatus;>;
#73 = Utf8 SourceFile
#74 = Utf8 WorkOrderStatus.java
#75 = NameAndType #42:#43 // $VALUES:[Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#76 = Class #43 // "[Lcmtech/soft/biz/utils/model/WorkOrderStatus;"
#77 = NameAndType #105:#106 // clone:()Ljava/lang/Object;
#78 = Utf8 cmtech/soft/biz/utils/model/WorkOrderStatus
#79 = NameAndType #48:#107 // valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
#80 = NameAndType #53:#108 // "<init>":(Ljava/lang/String;I)V
#81 = NameAndType #39:#40 // description:Ljava/lang/String;
#82 = NameAndType #41:#40 // code:Ljava/lang/String;
#83 = Class #109 // cmtech/soft/biz/utils/MyStrTool
#84 = NameAndType #110:#111 // isNullOrEmpty:(Ljava/lang/String;)Z
#85 = Class #112 // java/lang/String
#86 = NameAndType #113:#61 // toUpperCase:()Ljava/lang/String;
#87 = NameAndType #63:#49 // valueOfByEnumName:(Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#88 = NameAndType #60:#61 // getDescription:()Ljava/lang/String;
#89 = Utf8
#90 = NameAndType #62:#61 // getCode:()Ljava/lang/String;
#91 = Utf8 created
#92 = Utf8 未开始生产
#93 = NameAndType #53:#54 // "<init>":(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
#94 = NameAndType #34:#35 // CREATED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#95 = Utf8 running
#96 = Utf8 生产开始
#97 = NameAndType #36:#35 // RUNNING:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#98 = Utf8 paused
#99 = Utf8 生产暂停
#100 = NameAndType #37:#35 // PAUSED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#101 = Utf8 ended
#102 = Utf8 生产结束
#103 = NameAndType #38:#35 // ENDED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
#104 = Utf8 java/lang/Enum
#105 = Utf8 clone
#106 = Utf8 ()Ljava/lang/Object;
#107 = Utf8 (Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
#108 = Utf8 (Ljava/lang/String;I)V
#109 = Utf8 cmtech/soft/biz/utils/MyStrTool
#110 = Utf8 isNullOrEmpty
#111 = Utf8 (Ljava/lang/String;)Z
#112 = Utf8 java/lang/String
#113 = Utf8 toUpperCase
{
public static final cmtech.soft.biz.utils.model.WorkOrderStatus CREATED;
descriptor: Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_ENUM
public static final cmtech.soft.biz.utils.model.WorkOrderStatus RUNNING;
descriptor: Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_ENUM
public static final cmtech.soft.biz.utils.model.WorkOrderStatus PAUSED;
descriptor: Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_ENUM
public static final cmtech.soft.biz.utils.model.WorkOrderStatus ENDED;
descriptor: Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_ENUM
private java.lang.String description;
descriptor: Ljava/lang/String;
flags: ACC_PRIVATE
private java.lang.String code;
descriptor: Ljava/lang/String;
flags: ACC_PRIVATE
private static final cmtech.soft.biz.utils.model.WorkOrderStatus[] $VALUES;
descriptor: [Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PRIVATE, ACC_STATIC, ACC_FINAL, ACC_SYNTHETIC
public static cmtech.soft.biz.utils.model.WorkOrderStatus[] values();
descriptor: ()[Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=0, args_size=0
0: getstatic #1 // Field $VALUES:[Lcmtech/soft/biz/utils/model/WorkOrderStatus;
3: invokevirtual #2 // Method "[Lcmtech/soft/biz/utils/model/WorkOrderStatus;".clone:()Ljava/lang/Object;
6: checkcast #3 // class "[Lcmtech/soft/biz/utils/model/WorkOrderStatus;"
9: areturn
LineNumberTable:
line 8: 0
public static cmtech.soft.biz.utils.model.WorkOrderStatus valueOf(java.lang.String);
descriptor: (Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=1, args_size=1
0: ldc #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
2: aload_0
3: invokestatic #5 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
6: checkcast #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
9: areturn
LineNumberTable:
line 8: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 name Ljava/lang/String;
MethodParameters:
Name Flags
name mandated
private cmtech.soft.biz.utils.model.WorkOrderStatus(java.lang.String, java.lang.String);
descriptor: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
flags: ACC_PRIVATE
Code:
stack=3, locals=5, args_size=5
0: aload_0
1: aload_1
2: iload_2
3: invokespecial #6 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
6: aload_0
7: aload 4
9: putfield #7 // Field description:Ljava/lang/String;
12: aload_0
13: aload_3
14: putfield #8 // Field code:Ljava/lang/String;
17: return
LineNumberTable:
line 17: 0
line 18: 6
line 19: 12
line 20: 17
LocalVariableTable:
Start Length Slot Name Signature
0 18 0 this Lcmtech/soft/biz/utils/model/WorkOrderStatus;
0 18 3 code Ljava/lang/String;
0 18 4 description Ljava/lang/String;
MethodParameters:
Name Flags
$enum$name synthetic
$enum$ordinal synthetic
code
description
Signature: #59 // (Ljava/lang/String;Ljava/lang/String;)V
public java.lang.String getDescription();
descriptor: ()Ljava/lang/String;
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: getfield #7 // Field description:Ljava/lang/String;
4: areturn
LineNumberTable:
line 23: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lcmtech/soft/biz/utils/model/WorkOrderStatus;
public java.lang.String getCode();
descriptor: ()Ljava/lang/String;
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: getfield #8 // Field code:Ljava/lang/String;
4: areturn
LineNumberTable:
line 27: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lcmtech/soft/biz/utils/model/WorkOrderStatus;
public static cmtech.soft.biz.utils.model.WorkOrderStatus valueOfByEnumName(java.lang.String);
descriptor: (Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokestatic #9 // Method cmtech/soft/biz/utils/MyStrTool.isNullOrEmpty:(Ljava/lang/String;)Z
4: ifne 20
7: ldc #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
9: aload_0
10: invokevirtual #10 // Method java/lang/String.toUpperCase:()Ljava/lang/String;
13: invokestatic #11 // Method valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
16: checkcast #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
19: areturn
20: aconst_null
21: areturn
LineNumberTable:
line 36: 0
line 37: 7
line 39: 20
LocalVariableTable:
Start Length Slot Name Signature
0 22 0 name Ljava/lang/String;
StackMapTable: number_of_entries = 1
frame_type = 20 /* same */
MethodParameters:
Name Flags
name
public static java.lang.String getDescriptionByEnumName(java.lang.String);
descriptor: (Ljava/lang/String;)Ljava/lang/String;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=2, args_size=1
0: aload_0
1: invokestatic #12 // Method valueOfByEnumName:(Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
4: astore_1
5: aload_1
6: ifnull 14
9: aload_1
10: invokevirtual #13 // Method getDescription:()Ljava/lang/String;
13: areturn
14: ldc #14 // String
16: areturn
LineNumberTable:
line 49: 0
line 51: 5
line 52: 9
line 54: 14
LocalVariableTable:
Start Length Slot Name Signature
0 17 0 name Ljava/lang/String;
5 12 1 workOrderStatus Lcmtech/soft/biz/utils/model/WorkOrderStatus;
StackMapTable: number_of_entries = 1
frame_type = 252 /* append */
offset_delta = 14
locals = [ class cmtech/soft/biz/utils/model/WorkOrderStatus ]
MethodParameters:
Name Flags
name
public static java.lang.String getCodeByEnumName(java.lang.String);
descriptor: (Ljava/lang/String;)Ljava/lang/String;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=2, args_size=1
0: aload_0
1: invokestatic #12 // Method valueOfByEnumName:(Ljava/lang/String;)Lcmtech/soft/biz/utils/model/WorkOrderStatus;
4: astore_1
5: aload_1
6: ifnull 14
9: aload_1
10: invokevirtual #15 // Method getCode:()Ljava/lang/String;
13: areturn
14: ldc #14 // String
16: areturn
LineNumberTable:
line 64: 0
line 66: 5
line 67: 9
line 69: 14
LocalVariableTable:
Start Length Slot Name Signature
0 17 0 name Ljava/lang/String;
5 12 1 workOrderStatus Lcmtech/soft/biz/utils/model/WorkOrderStatus;
StackMapTable: number_of_entries = 1
frame_type = 252 /* append */
offset_delta = 14
locals = [ class cmtech/soft/biz/utils/model/WorkOrderStatus ]
MethodParameters:
Name Flags
name
static {};
descriptor: ()V
flags: ACC_STATIC
Code:
stack=6, locals=0, args_size=0
0: new #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
3: dup
4: ldc #16 // String CREATED
6: iconst_0
7: ldc #17 // String created
9: ldc #18 // String 未开始生产
11: invokespecial #19 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
14: putstatic #20 // Field CREATED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
17: new #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
20: dup
21: ldc #21 // String RUNNING
23: iconst_1
24: ldc #22 // String running
26: ldc #23 // String 生产开始
28: invokespecial #19 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
31: putstatic #24 // Field RUNNING:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
34: new #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
37: dup
38: ldc #25 // String PAUSED
40: iconst_2
41: ldc #26 // String paused
43: ldc #27 // String 生产暂停
45: invokespecial #19 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
48: putstatic #28 // Field PAUSED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
51: new #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
54: dup
55: ldc #29 // String ENDED
57: iconst_3
58: ldc #30 // String ended
60: ldc #31 // String 生产结束
62: invokespecial #19 // Method "<init>":(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
65: putstatic #32 // Field ENDED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
68: iconst_4
69: anewarray #4 // class cmtech/soft/biz/utils/model/WorkOrderStatus
72: dup
73: iconst_0
74: getstatic #20 // Field CREATED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
77: aastore
78: dup
79: iconst_1
80: getstatic #24 // Field RUNNING:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
83: aastore
84: dup
85: iconst_2
86: getstatic #28 // Field PAUSED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
89: aastore
90: dup
91: iconst_3
92: getstatic #32 // Field ENDED:Lcmtech/soft/biz/utils/model/WorkOrderStatus;
95: aastore
96: putstatic #1 // Field $VALUES:[Lcmtech/soft/biz/utils/model/WorkOrderStatus;
99: return
LineNumberTable:
line 9: 0
line 10: 17
line 11: 34
line 12: 51
line 8: 68
}
Signature: #72 // Ljava/lang/Enum<Lcmtech/soft/biz/utils/model/WorkOrderStatus;>;
SourceFile: "WorkOrderStatus.java"
Process finished with exit code 0