Merge branch 'master' of https://github.com/abh1navv/tutorials into BAEL-3201
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>akka-modules</artifactId>
|
||||
<name>akka-modules</name>
|
||||
|
||||
+7
@@ -8,6 +8,8 @@ import java.util.List;
|
||||
|
||||
import org.apache.spark.sql.Dataset;
|
||||
import org.apache.spark.sql.Row;
|
||||
import org.apache.spark.sql.SparkSession;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class CustomerToDataFrameConverterAppUnitTest {
|
||||
@@ -59,4 +61,9 @@ class CustomerToDataFrameConverterAppUnitTest {
|
||||
assertEquals( "Male", row2.getAs("gender"));
|
||||
assertEquals( 1200, (int)row2.getAs("transaction_amount"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanup() {
|
||||
SparkSession.getActiveSession().get().close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -59,4 +58,4 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
+1
-1
@@ -19,4 +19,4 @@
|
||||
<module>cas-secured-app</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -17,9 +17,7 @@
|
||||
<module>core-groovy</module>
|
||||
<module>core-groovy-2</module>
|
||||
<module>core-groovy-collections</module>
|
||||
<module>core-groovy-strings</module>
|
||||
<module>core-groovy-strings</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -11,3 +11,4 @@ This module contains articles about Java 14.
|
||||
- [Foreign Memory Access API in Java 14](https://www.baeldung.com/java-foreign-memory-access)
|
||||
- [Java 14 Record Keyword](https://www.baeldung.com/java-record-keyword)
|
||||
- [New Features in Java 14](https://www.baeldung.com/java-14-new-features)
|
||||
- [Java 14 Record vs. Lombok](https://www.baeldung.com/java-record-vs-lombok)
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.java14.recordvslombok;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ColorData {
|
||||
|
||||
private int red;
|
||||
private int green;
|
||||
private int blue;
|
||||
|
||||
public String getHexString() {
|
||||
return String.format("#%02X%02X%02X", red, green, blue);
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.java14.recordvslombok;
|
||||
|
||||
public record ColorRecord(int red, int green, int blue) {
|
||||
|
||||
public String getHexString() {
|
||||
return String.format("#%02X%02X%02X", red, green, blue);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.java14.recordvslombok;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
@Getter(AccessLevel.NONE)
|
||||
public class ColorValueObject {
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
|
||||
public String getHexString() {
|
||||
return String.format("#%02X%02X%02X", red, green, blue);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.java14.recordvslombok;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class MonochromeColor extends ColorData {
|
||||
|
||||
public MonochromeColor(int grayScale) {
|
||||
super(grayScale, grayScale, grayScale);
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.java14.recordvslombok;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class StudentBuilder {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private Long studentId;
|
||||
private String email;
|
||||
private String phoneNumber;
|
||||
private String address;
|
||||
private String country;
|
||||
private int age;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.java14.recordvslombok;
|
||||
|
||||
public record StudentRecord(String firstName, String lastName, Long studentId, String email, String phoneNumber, String address, String country, int age) {
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.java14.recordvslombok;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RecordVsLombokUntTest {
|
||||
|
||||
@Test
|
||||
public void givenAColorRecord_hexStringIsCorrect() {
|
||||
var red = new ColorRecord(255, 0, 0);
|
||||
|
||||
assertThat(red.getHexString()).isEqualTo("#FF0000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAColorValueObject_hexStringIsCorrect() {
|
||||
var red = new ColorValueObject(255, 0, 0);
|
||||
|
||||
assertThat(red.getHexString()).isEqualTo("#FF0000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRecordWithManyAttributes_firstNameShouldBeJohn() {
|
||||
StudentRecord john = new StudentRecord("John", "Doe", null, "[email protected]", null, null, "England", 20);
|
||||
|
||||
assertThat(john.firstName()).isEqualTo("John");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBuilderWithManyAttributes_firstNameShouldBeJohn() {
|
||||
StudentBuilder john = StudentBuilder.builder()
|
||||
.firstName("John")
|
||||
.lastName("Doe")
|
||||
.email("[email protected]")
|
||||
.country("England")
|
||||
.age(20)
|
||||
.build();
|
||||
|
||||
assertThat(john.getFirstName()).isEqualTo("John");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,4 +5,3 @@ This module contains articles about Java 15.
|
||||
### Relevant articles
|
||||
|
||||
- [Hidden Classes in Java 15](https://www.baeldung.com/java-hidden-classes)
|
||||
- [Sealed Classes and Interfaces in Java 15](https://www.baeldung.com/java-sealed-classes-interfaces)
|
||||
|
||||
+3
-3
@@ -4,15 +4,15 @@ import java.util.IntSummaryStatistics;
|
||||
|
||||
|
||||
public class BlogPost {
|
||||
|
||||
|
||||
private String title;
|
||||
private String author;
|
||||
private BlogPostType type;
|
||||
private int likes;
|
||||
record AuthPostTypesLikes(String author, BlogPostType type, int likes) {};
|
||||
record PostcountTitlesLikesStats(long postCount, String titles, IntSummaryStatistics likesStats){};
|
||||
record PostCountTitlesLikesStats(long postCount, String titles, IntSummaryStatistics likesStats){};
|
||||
record TitlesBoundedSumOfLikes(String titles, int boundedSumOfLikes) {};
|
||||
|
||||
|
||||
public BlogPost(String title, String author, BlogPostType type, int likes) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
|
||||
+4
-4
@@ -257,7 +257,7 @@ public class JavaGroupingByCollectorUnitTest {
|
||||
@Test
|
||||
public void givenListOfPosts_whenGroupedByAuthor_thenGetAMapUsingCollectingAndThen() {
|
||||
|
||||
Map<String, BlogPost.PostcountTitlesLikesStats> postsPerAuthor = posts.stream()
|
||||
Map<String, BlogPost.PostCountTitlesLikesStats> postsPerAuthor = posts.stream()
|
||||
.collect(groupingBy(BlogPost::getAuthor, collectingAndThen(toList(), list -> {
|
||||
long count = list.stream()
|
||||
.map(BlogPost::getTitle)
|
||||
@@ -267,10 +267,10 @@ public class JavaGroupingByCollectorUnitTest {
|
||||
.collect(joining(" : "));
|
||||
IntSummaryStatistics summary = list.stream()
|
||||
.collect(summarizingInt(BlogPost::getLikes));
|
||||
return new BlogPost.PostcountTitlesLikesStats(count, titles, summary);
|
||||
return new BlogPost.PostCountTitlesLikesStats(count, titles, summary);
|
||||
})));
|
||||
|
||||
BlogPost.PostcountTitlesLikesStats result = postsPerAuthor.get("Author 1");
|
||||
BlogPost.PostCountTitlesLikesStats result = postsPerAuthor.get("Author 1");
|
||||
assertThat(result.postCount()).isEqualTo(3L);
|
||||
assertThat(result.titles()).isEqualTo("News item 1 : Programming guide : Tech review 2");
|
||||
assertThat(result.likesStats().getMax()).isEqualTo(20);
|
||||
@@ -294,7 +294,7 @@ public class JavaGroupingByCollectorUnitTest {
|
||||
.toUpperCase(),
|
||||
u1.boundedSumOfLikes() + likes);
|
||||
}));
|
||||
|
||||
|
||||
BlogPost.TitlesBoundedSumOfLikes result = postsPerAuthor.get("Author 1");
|
||||
assertThat(result.titles()).isEqualTo("NEWS ITEM 1 : PROGRAMMING GUIDE : TECH REVIEW 2");
|
||||
assertThat(result.boundedSumOfLikes()).isEqualTo(47);
|
||||
|
||||
@@ -5,3 +5,4 @@
|
||||
- [Introduction to HexFormat in Java 17](https://www.baeldung.com/java-hexformat)
|
||||
- [New Features in Java 17](https://www.baeldung.com/java-17-new-features)
|
||||
- [Random Number Generators in Java 17](https://www.baeldung.com/java-17-random-number-generators)
|
||||
- [Sealed Classes and Interfaces in Java 17](https://www.baeldung.com/java-sealed-classes-interfaces)
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ public class VehicleUnitTest {
|
||||
public void givenCar_whenUsingReflectionAPI_thenSuperClassIsSealed() {
|
||||
Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false);
|
||||
Assertions.assertThat(car.getClass().getSuperclass().isSealed()).isEqualTo(true);
|
||||
Assertions.assertThat(car.getClass().getSuperclass().permittedSubclasses())
|
||||
Assertions.assertThat(car.getClass().getSuperclass().getPermittedSubclasses())
|
||||
.contains(ClassDesc.of(car.getClass().getCanonicalName()));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class VehicleUnitTest {
|
||||
public void givenTruck_whenUsingReflectionAPI_thenSuperClassIsSealed() {
|
||||
Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false);
|
||||
Assertions.assertThat(truck.getClass().getSuperclass().isSealed()).isEqualTo(true);
|
||||
Assertions.assertThat(truck.getClass().getSuperclass().permittedSubclasses())
|
||||
Assertions.assertThat(truck.getClass().getSuperclass().getPermittedSubclasses())
|
||||
.contains(ClassDesc.of(truck.getClass().getCanonicalName()));
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ public class InputStreamToOutputStreamUnitTest {
|
||||
void copy(InputStream source, OutputStream target) throws IOException {
|
||||
byte[] buf = new byte[8192];
|
||||
int length;
|
||||
while ((length = source.read(buf)) > 0) {
|
||||
while ((length = source.read(buf)) != -1) {
|
||||
target.write(buf, 0, length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,5 @@
|
||||
<properties>
|
||||
<commons-lang.version>2.2</commons-lang.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user