Skip to content

Commit b13caa4

Browse files
authored
Merge branch 'eugenp:master' into master
2 parents 561df5f + b453c38 commit b13caa4

File tree

85 files changed

+1717
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1717
-76
lines changed

core-java-modules/core-java-string-algorithms-5/src/main/java/com/baeldung/uniqueint/StringToUniqueInt.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public static int toIntByMD5(String value) {
3838
}
3939

4040
public static int toIntByLookup(String value) {
41-
var found = lookupMap.get(value);
41+
Integer found = lookupMap.get(value);
4242
if (found != null) {
4343
return found;
4444
}
4545

46-
var intValue = counter.incrementAndGet();
46+
Integer intValue = counter.incrementAndGet();
4747
lookupMap.put(value, intValue);
4848
return intValue;
4949
}

core-java-modules/core-java-swing/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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">
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">
55
<modelVersion>4.0.0</modelVersion>
66
<artifactId>core-java-swing</artifactId>
77
<packaging>jar</packaging>
@@ -19,4 +19,8 @@
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2020
</properties>
2121

22+
<build>
23+
<sourceDirectory>src/main/java</sourceDirectory>
24+
</build>
25+
2226
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.clipboard;
2+
3+
import java.awt.Toolkit;
4+
import java.awt.datatransfer.Clipboard;
5+
import java.awt.datatransfer.StringSelection;
6+
import java.awt.datatransfer.Transferable;
7+
import java.awt.datatransfer.UnsupportedFlavorException;
8+
import java.io.IOException;
9+
import java.awt.datatransfer.DataFlavor;
10+
11+
public class AwtClipboard {
12+
13+
public static void main(String[] args) throws IOException, UnsupportedFlavorException {
14+
String textToCopy = "Baeldung helps developers explore the Java ecosystem and simply be better engineers.";
15+
copyToClipboard(textToCopy);
16+
17+
String textCopied = copyFromClipboard();
18+
if (textCopied != null) {
19+
System.out.println(textCopied);
20+
}
21+
}
22+
23+
public static void copyToClipboard(String text) {
24+
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
25+
StringSelection data = new StringSelection(text);
26+
cb.setContents(data, null);
27+
}
28+
29+
public static String copyFromClipboard() throws UnsupportedFlavorException, IOException {
30+
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
31+
Transferable transferable = cb.getContents(null);
32+
if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
33+
String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
34+
return data;
35+
}
36+
System.out.println("Couldn't get data from the clipboard");
37+
return null;
38+
}
39+
}

logging-modules/logback/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
<artifactId>logback-classic</artifactId>
2525
<version>${logback.version}</version>
2626
</dependency>
27+
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core -->
28+
<dependency>
29+
<groupId>ch.qos.logback</groupId>
30+
<artifactId>logback-core</artifactId>
31+
<version>${logback.version}</version>
32+
</dependency>
2733
<dependency>
2834
<groupId>ch.qos.logback.contrib</groupId>
2935
<artifactId>logback-json-classic</artifactId>
@@ -109,10 +115,10 @@
109115
<docx4j.version>3.3.5</docx4j.version>
110116
<angus.mail.version>2.0.1</angus.mail.version>
111117
<angus.activation.version>2.0.0</angus.activation.version>
112-
<logback.version>1.5.6</logback.version>
118+
<logback.version>1.5.18</logback.version>
113119
<slf4j.version>2.1.0-alpha1</slf4j.version>
114120
<janino.version>3.1.12</janino.version>
115121
<logstash.version>8.0</logstash.version>
116122
</properties>
117123

118-
</project>
124+
</project>

logging-modules/logback/src/test/java/com/baeldung/logback/ConditionalLoggingUnitTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,4 @@ public void whenSystemPropertyIsPresent_thenReturnFileLogger() throws IOExceptio
4747
String logOutput = FileUtils.readFileToString(new File("conditional.log"));
4848
assertTrue(logOutput.contains("test prod log"));
4949
}
50-
51-
@Test
52-
public void whenMatchedWithEvaluatorFilter_thenReturnFilteredLogs() throws IOException {
53-
logger = (Logger) LoggerFactory.getLogger(ConditionalLoggingUnitTest.class);
54-
55-
logger.info("normal log");
56-
logger.info("billing details: XXXX");
57-
String normalLog = FileUtils.readFileToString(new File("conditional.log"));
58-
assertTrue(normalLog.contains("normal log"));
59-
assertTrue(normalLog.contains("billing details: XXXX"));
60-
61-
String filteredLog = FileUtils.readFileToString(new File("filtered.log"));
62-
assertTrue(filteredLog.contains("test prod log"));
63-
assertFalse(filteredLog.contains("billing details: XXXX"));
64-
}
65-
6650
}

mapstruct-2/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
<version>${lombok.version}</version>
2626
<scope>provided</scope>
2727
</dependency>
28+
<dependency>
29+
<groupId>org.springframework</groupId>
30+
<artifactId>spring-context</artifactId>
31+
<version>${springframework.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework</groupId>
36+
<artifactId>spring-test</artifactId>
37+
<version>${springframework.version}</version>
38+
<scope>test</scope>
39+
</dependency>
2840
</dependencies>
2941
<build>
3042
<finalName>mapstruct-2</finalName>
@@ -60,6 +72,7 @@
6072
<properties>
6173
<org.mapstruct.version>1.6.3</org.mapstruct.version>
6274
<lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
75+
<springframework.version>6.2.1</springframework.version>
6376
</properties>
6477

6578
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.dto;
2+
3+
public class MediaDto {
4+
5+
private Long id;
6+
7+
private String title;
8+
9+
public MediaDto(Long id, String title) {
10+
this.id = id;
11+
this.title = title;
12+
}
13+
14+
public MediaDto() {
15+
}
16+
17+
public Long getId() {
18+
return id;
19+
}
20+
21+
public void setId(Long id) {
22+
this.id = id;
23+
}
24+
25+
public String getTitle() {
26+
return title;
27+
}
28+
29+
public void setTitle(String title) {
30+
this.title = title;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return "MediaDto{" + "id=" + id + ", title='" + title + '\'' + '}';
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.entity;
2+
3+
public class Media {
4+
5+
private Long id;
6+
7+
private String title;
8+
9+
public Media(Long id, String title) {
10+
this.id = id;
11+
this.title = title;
12+
}
13+
14+
public Media() {
15+
}
16+
17+
public Long getId() {
18+
return id;
19+
}
20+
21+
public void setId(Long id) {
22+
this.id = id;
23+
}
24+
25+
public String getTitle() {
26+
return title;
27+
}
28+
29+
public void setTitle(String title) {
30+
this.title = title;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return "Media{" + "id=" + id + ", title='" + title + '\'' + '}';
36+
}
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.mapper;
2+
3+
import org.mapstruct.Mapper;
4+
5+
import com.baeldung.dto.MediaDto;
6+
import com.baeldung.entity.Media;
7+
8+
@Mapper
9+
public interface MediaMapper {
10+
11+
MediaDto toDto(Media media);
12+
13+
Media toEntity(MediaDto mediaDto);
14+
15+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.service;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import com.baeldung.dto.MediaDto;
7+
import com.baeldung.entity.Media;
8+
import com.baeldung.mapper.MediaMapper;
9+
10+
public class MediaService {
11+
12+
final Logger logger = LoggerFactory.getLogger(MediaService.class);
13+
14+
private final MediaMapper mediaMapper;
15+
16+
public MediaService(MediaMapper mediaMapper) {
17+
this.mediaMapper = mediaMapper;
18+
}
19+
20+
public Media persistMedia(MediaDto mediaDto) {
21+
Media media = mediaMapper.toEntity(mediaDto);
22+
logger.info("Persist media: {}", media);
23+
return media;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)