From 7d80c360410a3e8e4943c0071f5b066a4fe2aade Mon Sep 17 00:00:00 2001 From: zongzhihui Date: Fri, 22 Dec 2023 14:14:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?ChineseDate=E7=B1=BB=E6=B7=BB=E5=8A=A0hashc?= =?UTF-8?q?ode=E4=B8=8Eequals=E6=96=B9=E6=B3=95=E5=8F=8A=E5=85=B6=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=8F=82=E8=80=83java.time?= =?UTF-8?q?.LocalDateTime=E4=B8=8Ejava.util.Date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hutool/core/date/chinese/ChineseDate.java | 21 +++++++++++++++++++ .../hutool/core/date/ChineseDateTest.java | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java b/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java index 0faba0a9b..32dc663a2 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java @@ -403,6 +403,27 @@ public class ChineseDate { return String.format("%s%s年 %s%s", getCyclical(), getChineseZodiac(), getChineseMonthName(), getChineseDay()); } + @Override + public int hashCode() { + return getChineseDay().hashCode() ^ getChineseMonth().hashCode() + ^ Integer.valueOf(getChineseYear()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + 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 /** diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java index df599522a..8ea3f7303 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java @@ -174,4 +174,23 @@ public class ChineseDateTest { chineseDate = new ChineseDate(1998, 5, 1, false); Assertions.assertEquals("1998-05-26 00:00:00", chineseDate.getGregorianDate().toString()); } + + @Test + public void equalsTest(){ + // 二月初一 + Date date1 = new Date(2023 - 1900, 1, 20); + // 润二月初一 + Date date2 = new Date(2023 - 1900, 2, 22); + + ChineseDate chineseDate1 = new ChineseDate(date1); + ChineseDate chineseDate2 = new ChineseDate(date2); + ChineseDate chineseDate3 = new ChineseDate(date2); + + Assertions.assertEquals("2023-02-01", chineseDate1.toStringNormal()); + Assertions.assertEquals("2023-02-01", chineseDate2.toStringNormal()); + Assertions.assertEquals("2023-02-01", chineseDate3.toStringNormal()); + + Assertions.assertNotEquals(chineseDate1, chineseDate2); + Assertions.assertEquals(chineseDate2, chineseDate3); + } } From 3a1eb66f14983146daf5bc994822a928a8206c5d Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 23 Dec 2023 23:39:10 +0800 Subject: [PATCH 2/3] fix code --- .../hutool/core/date/chinese/ChineseDate.java | 28 +++++++++---------- .../hutool/core/date/ChineseDateTest.java | 11 ++++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java b/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java index 32dc663a2..03d691cb8 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/date/chinese/ChineseDate.java @@ -18,11 +18,13 @@ import org.dromara.hutool.core.date.DateTime; import org.dromara.hutool.core.date.DateUtil; import org.dromara.hutool.core.date.TimeUtil; import org.dromara.hutool.core.date.Zodiac; +import org.dromara.hutool.core.lang.Console; import org.dromara.hutool.core.text.StrUtil; import java.time.LocalDate; import java.util.Calendar; import java.util.Date; +import java.util.Objects; /** @@ -404,24 +406,20 @@ public class ChineseDate { } @Override - public int hashCode() { - return getChineseDay().hashCode() ^ getChineseMonth().hashCode() - ^ Integer.valueOf(getChineseYear()).hashCode(); + public boolean equals(final Object o) { + if (this == o) { + 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 - public boolean equals(Object obj) { - if (this == obj) { - 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; + public int hashCode() { + return Objects.hash(year, month, day); } // ------------------------------------------------------- private method start diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java index 8ea3f7303..8ea818ccf 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/date/ChineseDateTest.java @@ -17,6 +17,7 @@ import org.dromara.hutool.core.text.StrUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.time.LocalDate; import java.util.Date; import java.util.Objects; @@ -178,13 +179,13 @@ public class ChineseDateTest { @Test 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); - ChineseDate chineseDate2 = new ChineseDate(date2); - ChineseDate chineseDate3 = new ChineseDate(date2); + final ChineseDate chineseDate1 = new ChineseDate(date1); + final ChineseDate chineseDate2 = new ChineseDate(date2); + final ChineseDate chineseDate3 = new ChineseDate(date2); Assertions.assertEquals("2023-02-01", chineseDate1.toStringNormal()); Assertions.assertEquals("2023-02-01", chineseDate2.toStringNormal()); From f22015512a598df31289c47df284561154d0db19 Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 23 Dec 2023 23:57:46 +0800 Subject: [PATCH 3/3] prepare M10 --- CHANGELOG.md | 2 +- README-EN.md | 6 +++--- README.md | 6 +++--- bin/version.txt | 2 +- docs/js/version.js | 2 +- hutool-all/pom.xml | 2 +- hutool-bom/pom.xml | 2 +- hutool-core/pom.xml | 2 +- hutool-cron/pom.xml | 2 +- hutool-crypto/pom.xml | 2 +- hutool-db/pom.xml | 2 +- hutool-extra/pom.xml | 2 +- hutool-http/pom.xml | 2 +- hutool-json/pom.xml | 2 +- hutool-log/pom.xml | 2 +- hutool-poi/pom.xml | 2 +- hutool-setting/pom.xml | 2 +- hutool-socket/pom.xml | 2 +- hutool-swing/pom.xml | 2 +- pom.xml | 2 +- 20 files changed, 24 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66638f35c..d3eedc509 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ------------------------------------------------------------------------------------------------------------- -# 6.0.0-M9 (2023-11-29) +# 6.0.0-M10 (2023-12-23) ### 计划实现 * 【poi 】 Markdown相关(如HTML转换等),基于commonmark-java diff --git a/README-EN.md b/README-EN.md index ee17ac049..c71a5d51f 100755 --- a/README-EN.md +++ b/README-EN.md @@ -144,18 +144,18 @@ We provide the T-Shirt and Sweater with Hutool Logo, please visit the shop: org.dromara.hutool hutool-all - 6.0.0-M9 + 6.0.0-M10 ``` ### 🍐Gradle ``` -implementation 'org.dromara.hutool:hutool-all:6.0.0-M9' +implementation 'org.dromara.hutool:hutool-all:6.0.0-M10' ``` ## 📥Download -- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/hutool-all/6.0.0-M9/) +- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/hutool-all/6.0.0-M10/) > 🔔️note: > Hutool 5.x supports JDK8+ and is not tested on Android platforms, and cannot guarantee that all tool classes or tool methods are available. diff --git a/README.md b/README.md index 787eeca42..b2cc82c74 100755 --- a/README.md +++ b/README.md @@ -139,21 +139,21 @@ org.dromara.hutool hutool-all - 6.0.0-M9 + 6.0.0-M10 ``` ### 🍐Gradle ``` -implementation 'org.dromara.hutool:hutool-all:6.0.0-M9' +implementation 'org.dromara.hutool:hutool-all:6.0.0-M10' ``` ### 📥下载jar 点击以下链接,下载`hutool-all-X.X.X.jar`即可: -- [Maven中央库](https://repo1.maven.org/maven2/org/dromara/hutool/hutool-all/6.0.0-M9/) +- [Maven中央库](https://repo1.maven.org/maven2/org/dromara/hutool/hutool-all/6.0.0-M10/) > 🔔️注意 > Hutool 6.x支持JDK8+,对Android平台没有测试,不能保证所有工具类或工具方法可用。 diff --git a/bin/version.txt b/bin/version.txt index 80169ba26..76f9249ad 100644 --- a/bin/version.txt +++ b/bin/version.txt @@ -1 +1 @@ -6.0.0-M9 +6.0.0-M10 diff --git a/docs/js/version.js b/docs/js/version.js index 2468041ce..2221a2e15 100755 --- a/docs/js/version.js +++ b/docs/js/version.js @@ -1 +1 @@ -var version = '6.0.0-M9' \ No newline at end of file +var version = '6.0.0-M10' \ No newline at end of file diff --git a/hutool-all/pom.xml b/hutool-all/pom.xml index e0305ecdc..41bd94850 100755 --- a/hutool-all/pom.xml +++ b/hutool-all/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-all diff --git a/hutool-bom/pom.xml b/hutool-bom/pom.xml index 3410120c2..231002101 100755 --- a/hutool-bom/pom.xml +++ b/hutool-bom/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-bom diff --git a/hutool-core/pom.xml b/hutool-core/pom.xml index 9f8af2e8a..f83eb80fb 100755 --- a/hutool-core/pom.xml +++ b/hutool-core/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-core diff --git a/hutool-cron/pom.xml b/hutool-cron/pom.xml index a7160fd8b..d7a4bd4f7 100755 --- a/hutool-cron/pom.xml +++ b/hutool-cron/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-cron diff --git a/hutool-crypto/pom.xml b/hutool-crypto/pom.xml index e2dc83c4c..0428e92fa 100755 --- a/hutool-crypto/pom.xml +++ b/hutool-crypto/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-crypto diff --git a/hutool-db/pom.xml b/hutool-db/pom.xml index f9bc0205b..31c1c263e 100755 --- a/hutool-db/pom.xml +++ b/hutool-db/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-db diff --git a/hutool-extra/pom.xml b/hutool-extra/pom.xml index a01385523..b47531240 100755 --- a/hutool-extra/pom.xml +++ b/hutool-extra/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-extra diff --git a/hutool-http/pom.xml b/hutool-http/pom.xml index 71f42bc4a..69d179d74 100755 --- a/hutool-http/pom.xml +++ b/hutool-http/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-http diff --git a/hutool-json/pom.xml b/hutool-json/pom.xml index b29d824e7..f80f9801c 100755 --- a/hutool-json/pom.xml +++ b/hutool-json/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-json diff --git a/hutool-log/pom.xml b/hutool-log/pom.xml index 6cf6162e5..db948322f 100755 --- a/hutool-log/pom.xml +++ b/hutool-log/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-log diff --git a/hutool-poi/pom.xml b/hutool-poi/pom.xml index c353545f7..5f0a3be63 100755 --- a/hutool-poi/pom.xml +++ b/hutool-poi/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-poi diff --git a/hutool-setting/pom.xml b/hutool-setting/pom.xml index 16c1745dd..613367242 100755 --- a/hutool-setting/pom.xml +++ b/hutool-setting/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-setting diff --git a/hutool-socket/pom.xml b/hutool-socket/pom.xml index 334fdd553..c259cf477 100755 --- a/hutool-socket/pom.xml +++ b/hutool-socket/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-socket diff --git a/hutool-swing/pom.xml b/hutool-swing/pom.xml index 9e04e3ecf..185754e1c 100755 --- a/hutool-swing/pom.xml +++ b/hutool-swing/pom.xml @@ -21,7 +21,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool-swing diff --git a/pom.xml b/pom.xml index 1bac446ad..6666b0cb9 100755 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ org.dromara.hutool hutool-parent - 6.0.0-M9 + 6.0.0-M10 hutool Hutool是一个功能丰富且易用的Java工具库,通过诸多实用工具类的使用,旨在帮助开发者快速、便捷地完成各类开发任务。这些封装的工具涵盖了字符串、数字、集合、编码、日期、文件、IO、加密、数据库JDBC、JSON、HTTP客户端等一系列操作,可以满足各种不同的开发需求。