forked from plusone/plusone-commons
Quarter 实现 IWithIntCode。
parent
ef35833dc0
commit
4b9b38eeb9
|
@ -23,13 +23,15 @@ import java.time.temporal.ChronoField;
|
||||||
import com.google.common.collect.Range;
|
import com.google.common.collect.Range;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||||
|
import xyz.zhouxy.plusone.commons.base.IWithIntCode;
|
||||||
|
import xyz.zhouxy.plusone.commons.util.AssertTools;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 季度
|
* 季度
|
||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
public enum Quarter {
|
public enum Quarter implements IWithIntCode {
|
||||||
/** 第一季度 */
|
/** 第一季度 */
|
||||||
Q1(1),
|
Q1(1),
|
||||||
/** 第二季度 */
|
/** 第二季度 */
|
||||||
|
@ -107,10 +109,7 @@ public enum Quarter {
|
||||||
*/
|
*/
|
||||||
@StaticFactoryMethod(Quarter.class)
|
@StaticFactoryMethod(Quarter.class)
|
||||||
public static Quarter of(int value) {
|
public static Quarter of(int value) {
|
||||||
if (value < 1 || value > 4) {
|
return ENUMS[checkValidIntValue(value) - 1];
|
||||||
throw new IllegalArgumentException("Invalid value for Quarter: " + value);
|
|
||||||
}
|
|
||||||
return ENUMS[value - 1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StaticFactoryMethods end
|
// StaticFactoryMethods end
|
||||||
|
@ -134,6 +133,11 @@ public enum Quarter {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCode() {
|
||||||
|
return getValue();
|
||||||
|
}
|
||||||
|
|
||||||
public Month firstMonth() {
|
public Month firstMonth() {
|
||||||
return Month.of(firstMonthValue());
|
return Month.of(firstMonthValue());
|
||||||
}
|
}
|
||||||
|
@ -166,6 +170,11 @@ public enum Quarter {
|
||||||
|
|
||||||
// Getters end
|
// Getters end
|
||||||
|
|
||||||
|
public static int checkValidIntValue(int value) {
|
||||||
|
AssertTools.checkArgument(value >= 1 && value <= 4, () -> "Invalid value for Quarter: " + value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue