YearQuarter 新增方法

pull/1/head
ZhouXY108 2024-12-24 17:39:42 +08:00
parent c9db3828a3
commit 8ac446e228
1 changed files with 28 additions and 4 deletions

View File

@ -59,7 +59,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
this.lastDate = quarter.lastMonthDay().atYear(year);
}
// #region - StaticFactoryMethod
// #region - StaticFactory
/**
* {@link YearQuarter}
@ -186,7 +186,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
// #region - computes
public YearQuarter plusQuarters(long quartersToAdd) { // TODO 单元测试
if (quartersToAdd == 0) {
if (quartersToAdd == 0L) {
return this;
}
long quarterCount = this.year * 4L + (this.quarter.getValue() - 1);
@ -200,8 +200,16 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
return plusQuarters(-quartersToAdd);
}
public YearQuarter nextQuarter() { // TODO 单元测试
return plusQuarters(1L);
}
public YearQuarter lastQuarter() { // TODO 单元测试
return minusQuarters(1L);
}
public YearQuarter plusYears(long yearsToAdd) { // TODO 单元测试
if (yearsToAdd == 0) {
if (yearsToAdd == 0L) {
return this;
}
int newYear = YEAR.checkValidIntValue(this.year + yearsToAdd); // safe overflow
@ -212,6 +220,14 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
return plusYears(-yearsToAdd);
}
public YearQuarter nextYear() {
return plusYears(1L);
}
public YearQuarter lastYear() {
return minusYears(1L);
}
// #endregion
// #region - hashCode & equals
@ -235,7 +251,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
// #endregion
// #region - compareTo
// #region - compare
@Override
public int compareTo(YearQuarter other) {
@ -254,6 +270,14 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
return this.compareTo(other) > 0;
}
public static YearQuarter min(YearQuarter yearQuarter1, YearQuarter yearQuarter2) { // TODO 单元测试
return yearQuarter1.compareTo(yearQuarter2) <= 0 ? yearQuarter1 : yearQuarter2;
}
public static YearQuarter max(YearQuarter yearQuarter1, YearQuarter yearQuarter2) { // TODO 单元测试
return yearQuarter1.compareTo(yearQuarter2) >= 0 ? yearQuarter1 : yearQuarter2;
}
// #endregion
// #region - toString