forked from plusone/plusone-commons
docs: 完善 javadoc
This commit is contained in:
@@ -46,6 +46,7 @@ public enum Quarter implements IWithIntCode {
|
||||
/** 季度值 (1/2/3/4) */
|
||||
private final int value;
|
||||
|
||||
/** 月份范围 */
|
||||
private final Range<Integer> monthRange;
|
||||
|
||||
/** 常量值 */
|
||||
@@ -63,7 +64,9 @@ public enum Quarter implements IWithIntCode {
|
||||
this.monthRange = Range.closed(firstMonth, lastMonth);
|
||||
}
|
||||
|
||||
// StaticFactoryMethods
|
||||
// ================================
|
||||
// #region - StaticFactoryMethods
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 根据给定的月份值返回对应的季度
|
||||
@@ -114,23 +117,48 @@ public enum Quarter implements IWithIntCode {
|
||||
return ENUMS[checkValidIntValue(value) - 1];
|
||||
}
|
||||
|
||||
// StaticFactoryMethods end
|
||||
// ================================
|
||||
// #endregion - StaticFactoryMethods
|
||||
// ================================
|
||||
|
||||
// computes
|
||||
// ================================
|
||||
// #region - computes
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 加上指定数量的季度
|
||||
*
|
||||
* @param quarters 所添加的季度数量
|
||||
* @return 计算结果
|
||||
*/
|
||||
public Quarter plus(long quarters) {
|
||||
final int amount = (int) ((quarters % 4) + 4);
|
||||
return ENUMS[(ordinal() + amount) % 4];
|
||||
}
|
||||
|
||||
/**
|
||||
* 减去指定数量的季度
|
||||
*
|
||||
* @param quarters 所减去的季度数量
|
||||
* @return 计算结果
|
||||
*/
|
||||
public Quarter minus(long quarters) {
|
||||
return plus(-(quarters % 4));
|
||||
}
|
||||
|
||||
// computes end
|
||||
// ================================
|
||||
// #endregion - computes
|
||||
// ================================
|
||||
|
||||
// Getters
|
||||
// ================================
|
||||
// #region - Getters
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 获取季度值
|
||||
*
|
||||
* @return 季度值
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
@@ -140,45 +168,92 @@ public enum Quarter implements IWithIntCode {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 该季度的第一个月
|
||||
*
|
||||
* @return {@code Month} 对象
|
||||
*/
|
||||
public Month firstMonth() {
|
||||
return Month.of(firstMonthValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 该季度的第一个月
|
||||
*
|
||||
* @return 月份值从 1 开始,1 表示 1月,以此类推。
|
||||
*/
|
||||
public int firstMonthValue() {
|
||||
return this.monthRange.lowerEndpoint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 该季度的最后一个月
|
||||
*
|
||||
* @return {@code Month} 对象
|
||||
*/
|
||||
public Month lastMonth() {
|
||||
return Month.of(lastMonthValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 该季度的最后一个月
|
||||
*
|
||||
* @return 月份值从 1 开始,1 表示 1月,以此类推。
|
||||
*/
|
||||
public int lastMonthValue() {
|
||||
return this.monthRange.upperEndpoint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 该季度的第一天
|
||||
*
|
||||
* @return {@code MonthDay} 对象
|
||||
*/
|
||||
public MonthDay firstMonthDay() {
|
||||
return MonthDay.of(firstMonth(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 该季度的最后一天
|
||||
*
|
||||
* @return {@code MonthDay} 对象
|
||||
*/
|
||||
public MonthDay lastMonthDay() {
|
||||
// 季度的最后一个月不可能是 2 月
|
||||
final Month month = lastMonth();
|
||||
return MonthDay.of(month, month.maxLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算该季度的第一天为当年的第几天
|
||||
*
|
||||
* @param leapYear 是否为闰年
|
||||
* @return day of year
|
||||
*/
|
||||
public int firstDayOfYear(boolean leapYear) {
|
||||
return firstMonth().firstDayOfYear(leapYear);
|
||||
}
|
||||
|
||||
// Getters end
|
||||
// ================================
|
||||
// #endregion - Getters
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 检查给定的季度值是否有效
|
||||
*
|
||||
* @param value 季度值
|
||||
* @return 如果给定的季度值有效则返回该值
|
||||
* @throws DateTimeException 如果给定的季度值不在有效范围内(1到4),将抛出异常
|
||||
*/
|
||||
public static int checkValidIntValue(int value) {
|
||||
AssertTools.checkCondition(value >= 1 && value <= 4,
|
||||
() -> new DateTimeException("Invalid value for Quarter: " + value));
|
||||
return value;
|
||||
}
|
||||
|
||||
// Internal
|
||||
// ================================
|
||||
// #region - Internal
|
||||
// ================================
|
||||
|
||||
/**
|
||||
* 计算给定月份对应的季度值
|
||||
@@ -189,4 +264,8 @@ public enum Quarter implements IWithIntCode {
|
||||
private static int computeQuarterValueInternal(int monthValue) {
|
||||
return (monthValue - 1) / 3 + 1;
|
||||
}
|
||||
|
||||
// ================================
|
||||
// #endregion - Internal
|
||||
// ================================
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user