mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
1463172c2d
commit
3a1eb66f14
@ -18,11 +18,13 @@ import org.dromara.hutool.core.date.DateTime;
|
|||||||
import org.dromara.hutool.core.date.DateUtil;
|
import org.dromara.hutool.core.date.DateUtil;
|
||||||
import org.dromara.hutool.core.date.TimeUtil;
|
import org.dromara.hutool.core.date.TimeUtil;
|
||||||
import org.dromara.hutool.core.date.Zodiac;
|
import org.dromara.hutool.core.date.Zodiac;
|
||||||
|
import org.dromara.hutool.core.lang.Console;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -404,24 +406,20 @@ public class ChineseDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public boolean equals(final Object o) {
|
||||||
return getChineseDay().hashCode() ^ getChineseMonth().hashCode()
|
if (this == o) {
|
||||||
^ Integer.valueOf(getChineseYear()).hashCode();
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ChineseDate that = (ChineseDate) o;
|
||||||
|
return year == that.year && month == that.month && day == that.day;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public int hashCode() {
|
||||||
if (this == obj) {
|
return Objects.hash(year, month, day);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj instanceof ChineseDate) {
|
|
||||||
ChineseDate other = (ChineseDate) obj;
|
|
||||||
return day == other.day
|
|
||||||
&& month == other.month
|
|
||||||
&& year == other.year
|
|
||||||
&& isLeapMonth == other.isLeapMonth;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------- private method start
|
// ------------------------------------------------------- private method start
|
||||||
|
@ -17,6 +17,7 @@ import org.dromara.hutool.core.text.StrUtil;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -178,13 +179,13 @@ public class ChineseDateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void equalsTest(){
|
public void equalsTest(){
|
||||||
// 二月初一
|
// 二月初一
|
||||||
Date date1 = new Date(2023 - 1900, 1, 20);
|
final Date date1 = DateUtil.date(LocalDate.of(2023, 2, 20));
|
||||||
// 润二月初一
|
// 润二月初一
|
||||||
Date date2 = new Date(2023 - 1900, 2, 22);
|
final Date date2 = DateUtil.date(LocalDate.of(2023, 3, 22));
|
||||||
|
|
||||||
ChineseDate chineseDate1 = new ChineseDate(date1);
|
final ChineseDate chineseDate1 = new ChineseDate(date1);
|
||||||
ChineseDate chineseDate2 = new ChineseDate(date2);
|
final ChineseDate chineseDate2 = new ChineseDate(date2);
|
||||||
ChineseDate chineseDate3 = new ChineseDate(date2);
|
final ChineseDate chineseDate3 = new ChineseDate(date2);
|
||||||
|
|
||||||
Assertions.assertEquals("2023-02-01", chineseDate1.toStringNormal());
|
Assertions.assertEquals("2023-02-01", chineseDate1.toStringNormal());
|
||||||
Assertions.assertEquals("2023-02-01", chineseDate2.toStringNormal());
|
Assertions.assertEquals("2023-02-01", chineseDate2.toStringNormal());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user