YearQuarter 实现 Comparable 和 Serializable 接口;新增 isBefore 和 isAfter 方法。

dev
ZhouXY108 2024-08-26 10:41:26 +08:00
parent fd1126be9b
commit 43e01e5595
1 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package xyz.zhouxy.plusone.commons.base;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
@ -16,7 +17,8 @@ import com.google.common.base.Preconditions;
*
* @author zhouxy
*/
public final class YearQuarter {
public final class YearQuarter implements Comparable<YearQuarter>, Serializable {
private static final long serialVersionUID = 3804145964419489753L;
/** 年份 */
private final int year;
@ -153,6 +155,25 @@ public final class YearQuarter {
return year == other.year && quarter == other.quarter;
}
// compareTo
@Override
public int compareTo(YearQuarter other) {
int cmp = (this.year - other.year);
if (cmp == 0) {
cmp = (this.quarter.compareTo(other.quarter));
}
return cmp;
}
public boolean isBefore(YearQuarter other) {
return this.compareTo(other) < 0;
}
public boolean isAfter(YearQuarter other) {
return this.compareTo(other) > 0;
}
// toString
/**