forked from plusone/plusone-commons
优化 YearQuarter 的代码
parent
1a9960dbf1
commit
322ecf4db8
|
@ -31,14 +31,6 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
|
||||||
/** 季度结束日期 */
|
/** 季度结束日期 */
|
||||||
private final LocalDate lastDate;
|
private final LocalDate lastDate;
|
||||||
|
|
||||||
private YearQuarter(int year, int quarter) {
|
|
||||||
Preconditions.checkNotNull(quarter, "Quarter can not be null.");
|
|
||||||
this.year = year;
|
|
||||||
this.quarter = Quarter.of(quarter);
|
|
||||||
this.firstDate = this.quarter.firstMonthDay().atYear(year);
|
|
||||||
this.lastDate = this.quarter.lastMonthDay().atYear(year);
|
|
||||||
}
|
|
||||||
|
|
||||||
private YearQuarter(int year, @Nonnull Quarter quarter) {
|
private YearQuarter(int year, @Nonnull Quarter quarter) {
|
||||||
Preconditions.checkNotNull(quarter, "Quarter can not be null.");
|
Preconditions.checkNotNull(quarter, "Quarter can not be null.");
|
||||||
this.year = year;
|
this.year = year;
|
||||||
|
@ -47,6 +39,17 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
|
||||||
this.lastDate = quarter.lastMonthDay().atYear(year);
|
this.lastDate = quarter.lastMonthDay().atYear(year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据指定年份与季度,创建 {@link YearQuarter} 实例
|
||||||
|
*
|
||||||
|
* @param year 年份
|
||||||
|
* @param quarter 季度
|
||||||
|
* @return {@link YearQuarter} 实例
|
||||||
|
*/
|
||||||
|
public static YearQuarter of(int year, int quarter) {
|
||||||
|
return of(year, Quarter.of(quarter));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据指定年份与季度,创建 {@link YearQuarter} 实例
|
* 根据指定年份与季度,创建 {@link YearQuarter} 实例
|
||||||
*
|
*
|
||||||
|
@ -65,7 +68,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
|
||||||
* @return {@link YearQuarter} 实例
|
* @return {@link YearQuarter} 实例
|
||||||
*/
|
*/
|
||||||
public static YearQuarter of(@Nonnull LocalDate date) {
|
public static YearQuarter of(@Nonnull LocalDate date) {
|
||||||
return new YearQuarter(date.getYear(), Quarter.fromMonth(date.getMonth()));
|
return of(date.getYear(), Quarter.fromMonth(date.getMonth()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +205,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
|
||||||
public int compareTo(YearQuarter other) {
|
public int compareTo(YearQuarter other) {
|
||||||
int cmp = (this.year - other.year);
|
int cmp = (this.year - other.year);
|
||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
cmp = (this.quarter.compareTo(other.quarter));
|
cmp = this.quarter.compareTo(other.quarter);
|
||||||
}
|
}
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue