Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

枚举问题修改。 #77

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/main/java/com/xkzhangsan/time/enums/MonthNameEnum.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xkzhangsan.time.enums;


/**
* 月份名称枚举,包含英文全称,英文简称,中文全称
*
Expand All @@ -20,6 +21,8 @@ public enum MonthNameEnum {
Nov(11, "November", "十一月", "十一"),
Dec(12, "December", "十二月", "十二"),;

private static final MonthNameEnum[] ENUMS = MonthNameEnum.values();

/**
* 序号
*/
Expand Down Expand Up @@ -54,14 +57,10 @@ private MonthNameEnum(int code, String fullNameEn, String fullNameCn, String sho
* @return MonthNameEnum
*/
public static MonthNameEnum getByCode(int code){
if(code >=1 && code <= 12){
for(MonthNameEnum monthNameEnum : MonthNameEnum.values()){
if(monthNameEnum.getCode() == code){
return monthNameEnum;
}
}
if (code < 1 || code > 12) {
return null;
}
return null;
return ENUMS[code -1];
}

/**
Expand Down Expand Up @@ -119,5 +118,4 @@ public String getFullNameCn() {
public String getShortNameCn() {
return shortNameCn;
}

}
14 changes: 5 additions & 9 deletions src/main/java/com/xkzhangsan/time/enums/WeekNameEnum.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xkzhangsan.time.enums;


/**
* 星期名称枚举,包含英文全称,英文简称,中文
* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday
Expand All @@ -15,6 +16,7 @@ public enum WeekNameEnum {
Sat(6, "Saturday", "星期六"),
Sun(7, "Sunday", "星期日"),;

private static final WeekNameEnum[] ENUMS = WeekNameEnum.values();
/**
* 序号
*/
Expand Down Expand Up @@ -43,14 +45,10 @@ private WeekNameEnum(int code, String fullNameEn, String nameCn) {
* @return WeekNameEnum
*/
public static WeekNameEnum getByCode(int code){
if(code >=1 && code <= 12){
for(WeekNameEnum monthNameEnum : WeekNameEnum.values()){
if(monthNameEnum.getCode() == code){
return monthNameEnum;
}
}
if (code < 1 || code > 7) {
return null;
}
return null;
return ENUMS[code -1];
}

/**
Expand Down Expand Up @@ -94,6 +92,4 @@ public String getFullNameEn() {
public String getNameCn() {
return nameCn;
}


}