From c816787e068f36dadc4f73751d286a3c45a5a1c8 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Mon, 8 Aug 2022 09:34:25 -0400 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=B8=E5=BF=83=20Java?= =?UTF-8?q?=20=E7=9A=84=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=9C=A8=E8=BF=99?= =?UTF-8?q?=E9=87=8C=E6=88=91=E4=BB=AC=E4=B8=BB=E8=A6=81=E9=92=88=E5=AF=B9?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E7=8E=AF=E5=A2=83=E5=92=8C=20IDE=20=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E9=9D=9E=E5=B8=B8=E5=9F=BA=E6=9C=AC=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E8=BF=9B=E8=A1=8C=E8=AE=A8=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core-java-modules/core-java/.gitignore | 26 +++++++++ core-java-modules/core-java/README.md | 6 +++ core-java-modules/core-java/pom.xml | 54 +++++++++++++++++++ .../java/com/ossez/features/Template.java | 11 ++++ .../core-java/src/main/resources/logback.xml | 13 +++++ .../util/CurrentDateTimeUnitTest.java | 42 +++++++++++++++ .../core-java/src/test/resources/.gitignore | 13 +++++ 7 files changed, 165 insertions(+) create mode 100644 core-java-modules/core-java/.gitignore create mode 100644 core-java-modules/core-java/README.md create mode 100644 core-java-modules/core-java/pom.xml create mode 100644 core-java-modules/core-java/src/main/java/com/ossez/features/Template.java create mode 100644 core-java-modules/core-java/src/main/resources/logback.xml create mode 100644 core-java-modules/core-java/src/test/java/com/ossez/features/util/CurrentDateTimeUnitTest.java create mode 100644 core-java-modules/core-java/src/test/resources/.gitignore diff --git a/core-java-modules/core-java/.gitignore b/core-java-modules/core-java/.gitignore new file mode 100644 index 0000000000..3de4cc647e --- /dev/null +++ b/core-java-modules/core-java/.gitignore @@ -0,0 +1,26 @@ +*.class + +0.* + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* +.resourceCache + +# Packaged files # +*.jar +*.war +*.ear + +# Files generated by integration tests +*.txt +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/core-java-modules/core-java/README.md b/core-java-modules/core-java/README.md new file mode 100644 index 0000000000..0ca45409d3 --- /dev/null +++ b/core-java-modules/core-java/README.md @@ -0,0 +1,6 @@ +## Java 核心 + +本模块中包含有关 Java 核心新增功能特性的一些文章。 + +### 相关文章: +- [Java Preview Features](https://www.baeldung.com/java-preview-features) diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml new file mode 100644 index 0000000000..edf8842edf --- /dev/null +++ b/core-java-modules/core-java/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + core-java + core-java + jar + + + com.ossez.core-java-modules + core-java-modules + 0.0.2-SNAPSHOT + + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + core-java-8 + + + src/main/resources + true + + + + + + + 4.1 + + 3.6.1 + + + \ No newline at end of file diff --git a/core-java-modules/core-java/src/main/java/com/ossez/features/Template.java b/core-java-modules/core-java/src/main/java/com/ossez/features/Template.java new file mode 100644 index 0000000000..72891daaf5 --- /dev/null +++ b/core-java-modules/core-java/src/main/java/com/ossez/features/Template.java @@ -0,0 +1,11 @@ +package com.ossez.features; + +import java.time.Clock; +import java.time.Instant; +import java.time.ZoneId; + +public class Template { + + private static final Clock clock = Clock.fixed(Instant.parse("2016-10-09T15:10:30.00Z"), ZoneId.of("UTC")); + +} diff --git a/core-java-modules/core-java/src/main/resources/logback.xml b/core-java-modules/core-java/src/main/resources/logback.xml new file mode 100644 index 0000000000..11032b47f4 --- /dev/null +++ b/core-java-modules/core-java/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java/src/test/java/com/ossez/features/util/CurrentDateTimeUnitTest.java b/core-java-modules/core-java/src/test/java/com/ossez/features/util/CurrentDateTimeUnitTest.java new file mode 100644 index 0000000000..be598e73ef --- /dev/null +++ b/core-java-modules/core-java/src/test/java/com/ossez/features/util/CurrentDateTimeUnitTest.java @@ -0,0 +1,42 @@ +package com.ossez.features.util; + +import static org.junit.Assert.assertEquals; + +import java.time.Clock; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.temporal.ChronoField; + +import org.junit.jupiter.api.Test; + +public class CurrentDateTimeUnitTest { + + private static final Clock clock = Clock.fixed(Instant.parse("2016-10-09T15:10:30.00Z"), ZoneId.of("UTC")); + + @Test + public void shouldReturnCurrentDate() { + final LocalDate now = LocalDate.now(clock); + + assertEquals(9, now.get(ChronoField.DAY_OF_MONTH)); + assertEquals(10, now.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(2016, now.get(ChronoField.YEAR)); + } + + @Test + public void shouldReturnCurrentTime() { + final LocalTime now = LocalTime.now(clock); + + assertEquals(15, now.get(ChronoField.HOUR_OF_DAY)); + assertEquals(10, now.get(ChronoField.MINUTE_OF_HOUR)); + assertEquals(30, now.get(ChronoField.SECOND_OF_MINUTE)); + } + + @Test + public void shouldReturnCurrentTimestamp() { + final Instant now = Instant.now(clock); + + assertEquals(clock.instant().getEpochSecond(), now.getEpochSecond()); + } +} diff --git a/core-java-modules/core-java/src/test/resources/.gitignore b/core-java-modules/core-java/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/core-java-modules/core-java/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file From b90cdd3306fcfbb6ecef87d05ca6fdf4a1269ee9 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Mon, 8 Aug 2022 09:34:55 -0400 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E7=9A=84=E7=9A=84=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core-java-modules/core-java-11/README.md | 1 + .../ossez/multiline/MultiLineStringUnitTest.java | 13 +++++++++---- core-java-modules/pom.xml | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-11/README.md b/core-java-modules/core-java-11/README.md index f860b8b0c1..17b1f0c827 100644 --- a/core-java-modules/core-java-11/README.md +++ b/core-java-modules/core-java-11/README.md @@ -14,3 +14,4 @@ This module contains articles about Java 11 core features - [Negate a Predicate Method Reference with Java 11](https://www.baeldung.com/java-negate-predicate-method-reference) - [Benchmark JDK Collections vs Eclipse Collections](https://www.baeldung.com/jdk-collections-vs-eclipse-collections) - [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile) + diff --git a/core-java-modules/core-java-strings/src/test/java/com/ossez/multiline/MultiLineStringUnitTest.java b/core-java-modules/core-java-strings/src/test/java/com/ossez/multiline/MultiLineStringUnitTest.java index 9e9230ef8d..358a146471 100644 --- a/core-java-modules/core-java-strings/src/test/java/com/ossez/multiline/MultiLineStringUnitTest.java +++ b/core-java-modules/core-java-strings/src/test/java/com/ossez/multiline/MultiLineStringUnitTest.java @@ -2,14 +2,13 @@ package com.ossez.multiline; import org.junit.Test; -import javax.swing.*; import java.io.IOException; import static org.junit.Assert.assertEquals; public class MultiLineStringUnitTest { - + @Test public void whenCompareMultiLineStrings_thenTheyAreAllTheSame() throws IOException { MultiLineString ms = new MultiLineString(); @@ -17,7 +16,13 @@ public class MultiLineStringUnitTest { assertEquals(ms.stringJoin(), ms.stringBuilder()); assertEquals(ms.stringBuilder(), ms.guavaJoiner()); assertEquals(ms.guavaJoiner(), ms.loadFromFile()); - assertEquals(ms.loadFromFile(), ms.textBlocks()); + +// Due to JDK version, we cannot test TestBlocks +// assertEquals(ms.loadFromFile(), ms.textBlocks()); + } + @Test + public void newlineInOS() throws IOException { + System.out.println(System.lineSeparator()); + System.out.println(System.getProperty("line.separator")); } - } diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 817e092d33..3e7854fbc2 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -15,6 +15,7 @@ + core-java core-java-8 core-java-8-2 core-java-11 From f2c3c2bf0f81754e90c5c7cf694a871c53590da9 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Mon, 8 Aug 2022 09:36:36 -0400 Subject: [PATCH 3/3] =?UTF-8?q?Java=20=E5=A4=9A=E8=A1=8C=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 1 + .idea/encodings.xml | 2 ++ core-java-modules/core-java-strings/README.md | 2 +- .../spring/data/persistence/repository/IFooService.java | 5 ----- .../persistence/{ => saveperformance}/repository/Foo.java | 2 +- .../{ => saveperformance}/repository/FooService.java | 2 +- .../{ => saveperformance}/repository/IFooDAO.java | 2 +- .../persistence/saveperformance/repository/IFooService.java | 5 +++++ .../{ => saveperformance}/repository/PersistenceConfig.java | 2 +- .../persistence/repository/FooServiceIntegrationTest.java | 3 +++ 10 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooService.java rename persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/{ => saveperformance}/repository/Foo.java (95%) rename persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/{ => saveperformance}/repository/FooService.java (80%) rename persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/{ => saveperformance}/repository/IFooDAO.java (84%) create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/IFooService.java rename persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/{ => saveperformance}/repository/PersistenceConfig.java (97%) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 1afb82bd42..da660157fe 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -18,6 +18,7 @@ + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 017a39f7f5..f882ae2746 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -33,6 +33,8 @@ + + diff --git a/core-java-modules/core-java-strings/README.md b/core-java-modules/core-java-strings/README.md index 4217d3e515..8b8f885262 100644 --- a/core-java-modules/core-java-strings/README.md +++ b/core-java-modules/core-java-strings/README.md @@ -10,7 +10,7 @@ - [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting) - [Java – Generate Random String](https://www.baeldung.com/java-random-string) - [Java String Interview Questions and Answers](https://www.baeldung.com/java-string-interview-questions) -- [Java Multi-line String](https://www.baeldung.com/java-multiline-string) +- [Java 多行字符串](https://www.ossez.com/t/java/14049) - [Java 中的 String Pool 简介](https://www.ossez.com/t/java-string-pool/14017) - [Java “constant string too long” 编译错误](https://www.ossez.com/t/java-constant-string-too-long/14048) - [Java 对象如何安全的 toString](https://www.ossez.com/t/java-tostring/14000) diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooService.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooService.java deleted file mode 100644 index 8ce6a2d1ae..0000000000 --- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooService.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.spring.data.persistence.repository; - -public interface IFooService { - Foo create(Foo foo); -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/Foo.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/Foo.java similarity index 95% rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/Foo.java rename to persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/Foo.java index 6833c4c556..219f5bffb6 100644 --- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/Foo.java +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/Foo.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.data.persistence.repository; +package com.baeldung.spring.data.persistence.saveperformance.repository; import javax.persistence.*; import java.io.Serializable; diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/FooService.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/FooService.java similarity index 80% rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/FooService.java rename to persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/FooService.java index cb09a92b82..c9dd306d96 100644 --- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/FooService.java +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/FooService.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.data.persistence.repository; +package com.baeldung.spring.data.persistence.saveperformance.repository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDAO.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/IFooDAO.java similarity index 84% rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDAO.java rename to persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/IFooDAO.java index 20a81e7bfa..68712f2c32 100644 --- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDAO.java +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/IFooDAO.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.data.persistence.repository; +package com.baeldung.spring.data.persistence.saveperformance.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/IFooService.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/IFooService.java new file mode 100644 index 0000000000..f016e308d6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/IFooService.java @@ -0,0 +1,5 @@ +package com.baeldung.spring.data.persistence.saveperformance.repository; + +public interface IFooService { + Foo create(Foo foo); +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/PersistenceConfig.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/PersistenceConfig.java similarity index 97% rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/PersistenceConfig.java rename to persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/PersistenceConfig.java index f73ea94658..8ea27f968c 100644 --- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/PersistenceConfig.java +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/saveperformance/repository/PersistenceConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.data.persistence.repository; +package com.baeldung.spring.data.persistence.saveperformance.repository; import com.google.common.base.Preconditions; import org.springframework.beans.factory.annotation.Autowired; diff --git a/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/repository/FooServiceIntegrationTest.java b/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/repository/FooServiceIntegrationTest.java index 21990afb5e..0cc296397f 100644 --- a/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/repository/FooServiceIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/repository/FooServiceIntegrationTest.java @@ -1,5 +1,8 @@ package com.baeldung.spring.data.persistence.repository; +import com.baeldung.spring.data.persistence.saveperformance.repository.Foo; +import com.baeldung.spring.data.persistence.saveperformance.repository.IFooService; +import com.baeldung.spring.data.persistence.saveperformance.repository.PersistenceConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired;