forked from plusone/plusone-commons
YearQuarter 实现 Comparable 和 Serializable 接口;新增 isBefore 和 isAfter 方法。
parent
fd1126be9b
commit
43e01e5595
|
@ -1,5 +1,6 @@
|
||||||
package xyz.zhouxy.plusone.commons.base;
|
package xyz.zhouxy.plusone.commons.base;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.Month;
|
import java.time.Month;
|
||||||
import java.time.YearMonth;
|
import java.time.YearMonth;
|
||||||
|
@ -16,7 +17,8 @@ import com.google.common.base.Preconditions;
|
||||||
*
|
*
|
||||||
* @author zhouxy
|
* @author zhouxy
|
||||||
*/
|
*/
|
||||||
public final class YearQuarter {
|
public final class YearQuarter implements Comparable<YearQuarter>, Serializable {
|
||||||
|
private static final long serialVersionUID = 3804145964419489753L;
|
||||||
|
|
||||||
/** 年份 */
|
/** 年份 */
|
||||||
private final int year;
|
private final int year;
|
||||||
|
@ -153,6 +155,25 @@ public final class YearQuarter {
|
||||||
return year == other.year && quarter == other.quarter;
|
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
|
// toString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue