Skip to content

Commit 3cd9ddb

Browse files
authored
Java 5065 (eugenp#11126)
* Commit source code to branch * BAEL-5065 improvement of groupBy with complex key
1 parent 8ee76e5 commit 3cd9ddb

File tree

5 files changed

+383
-40
lines changed

5 files changed

+383
-40
lines changed
Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
6-
<artifactId>core-java-16</artifactId>
7-
<version>0.1.0-SNAPSHOT</version>
8-
<name>core-java-16</name>
9-
<packaging>jar</packaging>
10-
<url>http://maven.apache.org</url>
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>core-java-16</artifactId>
7+
<version>0.1.0-SNAPSHOT</version>
8+
<name>core-java-16</name>
9+
<packaging>jar</packaging>
10+
<url>http://maven.apache.org</url>
1111

12-
<parent>
13-
<groupId>com.baeldung</groupId>
14-
<artifactId>parent-modules</artifactId>
15-
<version>1.0.0-SNAPSHOT</version>
16-
<relativePath>../../</relativePath>
17-
</parent>
12+
<parent>
13+
<groupId>com.baeldung</groupId>
14+
<artifactId>parent-modules</artifactId>
15+
<version>1.0.0-SNAPSHOT</version>
16+
<relativePath>../../</relativePath>
17+
</parent>
1818

19-
<dependencies>
20-
<dependency>
21-
<groupId>org.assertj</groupId>
22-
<artifactId>assertj-core</artifactId>
23-
<version>${assertj.version}</version>
24-
<scope>test</scope>
25-
</dependency>
26-
</dependencies>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.assertj</groupId>
22+
<artifactId>assertj-core</artifactId>
23+
<version>${assertj.version}</version>
24+
<scope>test</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.commons</groupId>
28+
<artifactId>commons-lang3</artifactId>
29+
<version>3.12.0</version>
30+
</dependency>
31+
</dependencies>
2732

28-
<build>
29-
<plugins>
30-
<plugin>
31-
<groupId>org.apache.maven.plugins</groupId>
32-
<artifactId>maven-compiler-plugin</artifactId>
33-
<version>${maven-compiler-plugin.version}</version>
34-
<configuration>
35-
<source>${maven.compiler.source.version}</source>
36-
<target>${maven.compiler.target.version}</target>
37-
</configuration>
38-
</plugin>
39-
</plugins>
40-
</build>
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<version>${maven-compiler-plugin.version}</version>
39+
<configuration>
40+
<source>${maven.compiler.source.version}</source>
41+
<target>${maven.compiler.target.version}</target>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
4146

42-
<properties>
43-
<maven.compiler.source.version>16</maven.compiler.source.version>
44-
<maven.compiler.target.version>16</maven.compiler.target.version>
45-
<assertj.version>3.6.1</assertj.version>
46-
</properties>
47+
<properties>
48+
<maven.compiler.source.version>16</maven.compiler.source.version>
49+
<maven.compiler.target.version>16</maven.compiler.target.version>
50+
<assertj.version>3.6.1</assertj.version>
51+
</properties>
4752

4853
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.java_16_features.groupingby;
2+
3+
public class BlogPost {
4+
5+
private String title;
6+
private String author;
7+
private BlogPostType type;
8+
private int likes;
9+
record AuthPostTypesLikes(String author, BlogPostType type, int likes) {};
10+
11+
public BlogPost(String title, String author, BlogPostType type, int likes) {
12+
this.title = title;
13+
this.author = author;
14+
this.type = type;
15+
this.likes = likes;
16+
}
17+
18+
public String getTitle() {
19+
return title;
20+
}
21+
22+
public String getAuthor() {
23+
return author;
24+
}
25+
26+
public BlogPostType getType() {
27+
return type;
28+
}
29+
30+
public int getLikes() {
31+
return likes;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return "BlogPost{" + "title='" + title + '\'' + ", type=" + type + ", likes=" + likes + '}';
37+
}
38+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.java_16_features.groupingby;
2+
3+
public enum BlogPostType {
4+
NEWS, REVIEW, GUIDE
5+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.java_16_features.groupingby;
2+
3+
import java.util.Objects;
4+
5+
public class Tuple {
6+
private final BlogPostType type;
7+
private final String author;
8+
9+
public Tuple(BlogPostType type, String author) {
10+
this.type = type;
11+
this.author = author;
12+
}
13+
14+
public BlogPostType getType() {
15+
return type;
16+
}
17+
18+
public String getAuthor() {
19+
return author;
20+
}
21+
22+
@Override
23+
public boolean equals(Object o) {
24+
if (this == o)
25+
return true;
26+
if (o == null || getClass() != o.getClass())
27+
return false;
28+
Tuple tuple = (Tuple) o;
29+
return type == tuple.type && author.equals(tuple.author);
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return Objects.hash(type, author);
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "Tuple{" + "type=" + type + ", author='" + author + '\'' + '}';
40+
}
41+
}

0 commit comments

Comments
 (0)