使用 interface嵌套interface的 方式,能夠?qū)蛹壐鼮榍宄氖褂靡恍╈o態(tài)常量
Eclipse快捷鍵:
Ctrl+Shift +X 變大寫
Ctrl+Shift +Y 變小寫
package constants;
public interface Constants {
/**
* 月份
*/
public interface Month{
public static final String JANUARY="01";
public static final String FEBRUARY="02";
public static final String MARCH="03";
public static final String APRIL="04";
public static final String MAY="05";
public static final String JUNE="06";
public static final String JULY="07";
public static final String AUGUST="08";
public static final String SEPTEMBER="09";
public static final String OCTOBER="10";
public static final String NOVEMBER="11";
public static final String DECEMBER="12";
}
/**
* 生肖
*/
public interface TheChineseZodiac{
}
}
通過枚舉配置的方式,相對"優(yōu)雅"的將一些使用多次且繁雜的判斷邏輯,通過交并集的方式處理
package util;
import org.apache.commons.lang3.StringUtils;
/**
* 判斷月份所屬季節(jié)和氣候工具
*/
public class SeasonlUtil {
/**
* 溫暖季節(jié): 春富寿、夏睬隶、秋
* @param month
* @return
*/
public static boolean chcekWarm(String month) {
return checkSrping(month)||checkSummer(month)||checkAutumn(month);
}
/**
* 涼爽季節(jié):秋、冬页徐、春
* @param month
* @return
*/
public static boolean chcekCool(String month) {
return checkSrping(month)||checkAutumn(month)||checkWinter(month);
}
/**
* 春天
* @param month
* @return
*/
public static boolean checkSrping(String month) {
boolean flag=false;
if(StringUtils.isNotBlank(month)) {
for (SpringEnum spring : SpringEnum.values()) {
if(spring.value.equals(month)){
flag=true;
}
}
}
return flag;
}
/**
* 夏天
* @param month
* @return
*/
public static boolean checkSummer(String month) {
boolean flag=false;
if(StringUtils.isNotBlank(month)) {
for (SummerEnum spring : SummerEnum.values()) {
if(spring.value.equals(month)){
flag=true;
}
}
}
return flag;
}
/**
* 秋天
* @param month
* @return
*/
public static boolean checkAutumn(String month) {
boolean flag=false;
if(StringUtils.isNotBlank(month)) {
for (AutumnEnum spring : AutumnEnum.values()) {
if(spring.value.equals(month)){
flag=true;
}
}
}
return flag;
}
/**
* 冬天
* @param month
* @return
*/
public static boolean checkWinter(String month) {
boolean flag=false;
if(StringUtils.isNotBlank(month)) {
for (WinterEnum spring : WinterEnum.values()) {
if(spring.value.equals(month)){
flag=true;
}
}
}
return flag;
}
//--------------------------------↓↓配置枚舉↓↓-------------------------------------------
/**
* 春季 2苏潜、3、4 月
*/
private enum SpringEnum {
FEBRUARY(Constants.Month.FEBRUARY),
MARCH(Constants.Month.MARCH),
APRIL(Constants.Month.APRIL);
private String value;
SpringEnum(String value) {
this.value = value;
}
}
/**
* 夏季 5变勇、6恤左、7 月
*/
private enum SummerEnum {
MAY(Constants.Month.MAY),
JUNE(Constants.Month.JUNE),
JULY(Constants.Month.JULY);
private String value;
SummerEnum(String value) {
this.value = value;
}
}
/**
* 秋季 8、9搀绣、10 月
*/
private enum AutumnEnum {
AUGUST(Constants.Month.AUGUST),
SEPTEMBER(Constants.Month.SEPTEMBER),
OCTOBER(Constants.Month.OCTOBER);
private String value;
AutumnEnum(String value) {
this.value = value;
}
}
/**
* 冬季 11赃梧、12、1 月
*/
private enum WinterEnum {
NOVEMBER(Constants.Month.NOVEMBER),
DECEMBER(Constants.Month.DECEMBER),
JANUARY(Constants.Month.JANUARY);
private String value;
WinterEnum(String value) {
this.value = value;
}
}
//--------------------------------↑↑配置枚舉↑↑-------------------------------------------
}
?