Merge branch 'eugenp:master' into master
This commit is contained in:
@@ -7,3 +7,4 @@ This module contains articles about Java 11 core features
|
||||
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
|
||||
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
|
||||
- [New Features in Java 11](https://www.baeldung.com/java-11-new-features)
|
||||
- [Getting the Java Version at Runtime](https://www.baeldung.com/get-java-version-runtime)
|
||||
|
||||
@@ -34,4 +34,4 @@
|
||||
<maven.compiler.target>1.9</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -7,7 +7,7 @@
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-9-streams</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
@@ -25,4 +25,4 @@
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -5,3 +5,4 @@ This module contains articles about core features in the Java language
|
||||
- [The Java final Keyword – Impact on Performance](https://www.baeldung.com/java-final-performance)
|
||||
- [The package-info.java File](https://www.baeldung.com/java-package-info)
|
||||
- [What are Compile-time Constants in Java?](https://www.baeldung.com/java-compile-time-constants)
|
||||
- [Java Objects.hash() vs Objects.hashCode()](https://www.baeldung.com/java-objects-hash-vs-objects-hashcode)
|
||||
|
||||
@@ -7,3 +7,4 @@ This module contains articles about Object-oriented programming (OOP) patterns i
|
||||
- [Inheritance and Composition (Is-a vs Has-a relationship) in Java](https://www.baeldung.com/java-inheritance-composition)
|
||||
- [Immutable Objects in Java](https://www.baeldung.com/java-immutable-object)
|
||||
- [How to Make a Deep Copy of an Object in Java](https://www.baeldung.com/java-deep-copy)
|
||||
- [Using an Interface vs. Abstract Class in Java](https://www.baeldung.com/java-interface-vs-abstract-class)
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.ignore.pattern.metacharacters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class IgnoringPatternMetacharactersUnitTest {
|
||||
private static final String dollarAmounts = "$100.25, $100.50, $150.50, $100.50, $100.75";
|
||||
private static final String patternStr = "$100.50";
|
||||
|
||||
@Test
|
||||
public void givenPatternStringHasMetacharacters_whenPatternMatchedWithoutEscapingMetacharacters_thenNoMatchesFound() {
|
||||
Pattern pattern = Pattern.compile(patternStr);
|
||||
Matcher matcher = pattern.matcher(dollarAmounts);
|
||||
|
||||
int matches = 0;
|
||||
while (matcher.find()) {
|
||||
matches++;
|
||||
}
|
||||
|
||||
assertEquals(0, matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPatternStringHasMetacharacters_whenPatternCompiledUsingManuallyMetaEscapedPattern_thenMatchingSuccessful() {
|
||||
String metaEscapedPatternStr = "\\Q" + patternStr + "\\E";
|
||||
Pattern pattern = Pattern.compile(metaEscapedPatternStr);
|
||||
Matcher matcher = pattern.matcher(dollarAmounts);
|
||||
|
||||
int matches = 0;
|
||||
while (matcher.find()) {
|
||||
matches++;
|
||||
}
|
||||
|
||||
assertEquals(2, matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPatternStringHasMetacharacters_whenPatternCompiledUsingLiteralPatternFromQuote_thenMatchingSuccessful() {
|
||||
String literalPatternStr = Pattern.quote(patternStr);
|
||||
Pattern pattern = Pattern.compile(literalPatternStr);
|
||||
Matcher matcher = pattern.matcher(dollarAmounts);
|
||||
|
||||
int matches = 0;
|
||||
while (matcher.find()) {
|
||||
matches++;
|
||||
}
|
||||
|
||||
assertEquals(2, matches);
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,5 @@ This module contains articles about the Stream API in Java.
|
||||
- [Should We Close a Java Stream?](https://www.baeldung.com/java-stream-close)
|
||||
- [Returning Stream vs. Collection](https://www.baeldung.com/java-return-stream-collection)
|
||||
- [Convert a Java Enumeration Into a Stream](https://www.baeldung.com/java-enumeration-to-stream)
|
||||
- [When to Use a Parallel Stream in Java](https://www.baeldung.com/java-when-to-use-parallel-stream)
|
||||
- More articles: [[<-- prev>]](/../core-java-streams-2)
|
||||
|
||||
@@ -6,4 +6,5 @@ This module contains articles about string conversions from/to another type.
|
||||
- [Java String Conversions](https://www.baeldung.com/java-string-conversions)
|
||||
- [Convert String to Byte Array and Reverse in Java](https://www.baeldung.com/java-string-to-byte-array)
|
||||
- [Convert Character Array to String in Java](https://www.baeldung.com/java-char-array-to-string)
|
||||
- [Converting String to BigDecimal in Java](https://www.baeldung.com/java-string-to-bigdecimal)
|
||||
- More articles: [[<-- prev]](/core-java-string-conversions)
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.baeldung.stringtobigdecimal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringToBigDecimalConversionUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenValidString_WhenBigDecimalObjectWithStringParameter_ThenResultIsDecimalObject() {
|
||||
BigDecimal bigDecimal = new BigDecimal("123");
|
||||
assertEquals(new BigDecimal(123), bigDecimal);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void givenNullString_WhenBigDecimalObjectWithStringParameter_ThenNullPointerExceptionIsThrown() {
|
||||
String bigDecimal = null;
|
||||
new BigDecimal(bigDecimal);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void givenInalidString_WhenBigDecimalObjectWithStringParameter_ThenNumberFormatExceptionIsThrown() {
|
||||
new BigDecimal("&");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValidString_WhenValueOfDoubleFromString_ThenResultIsDecimalObject() {
|
||||
BigDecimal bigDecimal = BigDecimal.valueOf(Double.valueOf("123.42"));
|
||||
assertEquals(new BigDecimal(123.42).setScale(2, BigDecimal.ROUND_HALF_UP), bigDecimal);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void givenNullString_WhenValueOfDoubleFromString_ThenNullPointerExceptionIsThrown() {
|
||||
BigDecimal.valueOf(Double.valueOf(null));
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
public void givenInalidString_WhenValueOfDoubleFromString_ThenNumberFormatExceptionIsThrown() {
|
||||
BigDecimal.valueOf(Double.valueOf("&"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValidString_WhenDecimalFormatOfString_ThenResultIsDecimalObject() throws ParseException {
|
||||
BigDecimal bigDecimal = new BigDecimal(10692467440017.111).setScale(3, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||
symbols.setGroupingSeparator(',');
|
||||
symbols.setDecimalSeparator('.');
|
||||
String pattern = "#,##0.0#";
|
||||
DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
|
||||
decimalFormat.setParseBigDecimal(true);
|
||||
|
||||
// parse the string value
|
||||
BigDecimal parsedStringValue = (BigDecimal) decimalFormat.parse("10,692,467,440,017.111");
|
||||
|
||||
assertEquals(bigDecimal, parsedStringValue);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void givenNullString_WhenDecimalFormatOfString_ThenNullPointerExceptionIsThrown() throws ParseException {
|
||||
new DecimalFormat("#").parse(null);
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void givenInalidString_WhenDecimalFormatOfString_ThenNumberFormatExceptionIsThrown() throws ParseException {
|
||||
new DecimalFormat("#").parse("&");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,3 +3,4 @@
|
||||
- [Version Comparison in Java](https://www.baeldung.com/java-comparing-versions)
|
||||
- [Java (String) or .toString()?](https://www.baeldung.com/java-string-casting-vs-tostring)
|
||||
- [Split Java String by Newline](https://www.baeldung.com/java-string-split-by-newline)
|
||||
- [Split a String in Java and Keep the Delimiters](https://www.baeldung.com/java-split-string-keep-delimiters)
|
||||
|
||||
+4
-3
@@ -1,6 +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/maven-v4_0_0.xsd">
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>jws</artifactId>
|
||||
@@ -66,4 +67,4 @@
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
+2
-2
@@ -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>libraries-4</artifactId>
|
||||
|
||||
|
||||
+2
-2
@@ -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>libraries-5</artifactId>
|
||||
|
||||
|
||||
+4
-4
@@ -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>libraries-6</artifactId>
|
||||
|
||||
@@ -112,12 +112,12 @@
|
||||
<artifactId>renjin-script-engine</artifactId>
|
||||
<version>${renjin.version}</version>
|
||||
</dependency>
|
||||
<!-- libphonenumber -->
|
||||
<!-- libphonenumber -->
|
||||
<dependency>
|
||||
<groupId>com.googlecode.libphonenumber</groupId>
|
||||
<artifactId>libphonenumber</artifactId>
|
||||
<version>${libphonenumber.version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
||||
+5
-3
@@ -1,6 +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">
|
||||
<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>
|
||||
<artifactId>libraries</artifactId>
|
||||
<name>libraries</name>
|
||||
@@ -335,7 +336,8 @@
|
||||
<configuration>
|
||||
<finalName>benchmarks</finalName>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.openjdk.jmh.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.mapper;
|
||||
|
||||
import com.baeldung.dto.SimpleSource;
|
||||
import com.baeldung.entity.SimpleDestination;
|
||||
import com.baeldung.service.SimpleService;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public abstract class SimpleDestinationMapperUsingInjectedService {
|
||||
|
||||
@Autowired
|
||||
protected SimpleService simpleService;
|
||||
|
||||
@Mapping(target = "name", expression = "java(simpleService.enrichName(source.getName()))")
|
||||
public abstract SimpleDestination sourceToDestination(SimpleSource source);
|
||||
|
||||
public abstract SimpleSource destinationToSource(SimpleDestination destination);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SimpleService {
|
||||
|
||||
public String enrichName(String name) {
|
||||
return "-:: " + name + " ::-";
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.mapper;
|
||||
|
||||
import com.baeldung.dto.SimpleSource;
|
||||
import com.baeldung.entity.SimpleDestination;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:applicationContext.xml")
|
||||
public class SimpleDestinationMapperUsingInjectedIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private SimpleDestinationMapperUsingInjectedService mapper;
|
||||
|
||||
@Test
|
||||
public void givenSourceToDestination_whenMaps_thenNameEnriched() {
|
||||
// Given
|
||||
SimpleSource source = new SimpleSource();
|
||||
source.setName("Bob");
|
||||
source.setDescription("The Builder");
|
||||
|
||||
// When
|
||||
SimpleDestination destination = mapper.sourceToDestination(source);
|
||||
|
||||
// Then
|
||||
assertThat(destination).isNotNull();
|
||||
assertThat(destination.getName()).isEqualTo("-:: Bob ::-");
|
||||
assertThat(destination.getDescription()).isEqualTo("The Builder");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Copying Files With Maven](https://www.baeldung.com/maven-copy-files)
|
||||
@@ -49,9 +49,11 @@
|
||||
<goal>echo</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<message>Hello, world</message>
|
||||
<message>Embed a line break: ${line.separator}</message>
|
||||
<message>ArtifactId is ${project.artifactId}</message>
|
||||
<message>
|
||||
Hello, world
|
||||
Embed a line break: ${line.separator}
|
||||
ArtifactId is ${project.artifactId}
|
||||
</message>
|
||||
<level>INFO</level>
|
||||
<toFile>/logs/log-echo.txt</toFile>
|
||||
<append>true</append>
|
||||
|
||||
@@ -10,3 +10,4 @@ This module contains articles about the Java Persistence API (JPA) in Java.
|
||||
- [JPA CascadeType.REMOVE vs orphanRemoval](https://www.baeldung.com/jpa-cascade-remove-vs-orphanremoval)
|
||||
- [A Guide to MultipleBagFetchException in Hibernate](https://www.baeldung.com/java-hibernate-multiplebagfetchexception)
|
||||
- [How to Convert a Hibernate Proxy to a Real Entity Object](https://www.baeldung.com/hibernate-proxy-to-real-entity-object)
|
||||
- [Returning an Auto-Generated Id with JPA](https://www.baeldung.com/jpa-get-auto-generated-id)
|
||||
|
||||
@@ -9,6 +9,7 @@ This module contains articles about annotations used in Spring Data JPA
|
||||
- [Spring JPA @Embedded and @EmbeddedId](https://www.baeldung.com/spring-jpa-embedded-method-parameters)
|
||||
- [Programmatic Transaction Management in Spring](https://www.baeldung.com/spring-programmatic-transaction-management)
|
||||
- [JPA Entity Lifecycle Events](https://www.baeldung.com/jpa-entity-lifecycle-events)
|
||||
- [Overriding Column Definition With @AttributeOverride](https://www.baeldung.com/jpa-attributeoverride)
|
||||
|
||||
### Eclipse Config
|
||||
After importing the project into Eclipse, you may see the following error:
|
||||
|
||||
@@ -10,6 +10,7 @@ This module contains articles about CRUD operations in Spring Data JPA
|
||||
- [Batch Insert/Update with Hibernate/JPA](https://www.baeldung.com/jpa-hibernate-batch-insert-update)
|
||||
- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush)
|
||||
- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema)
|
||||
- [How to Implement a Soft Delete with Spring JPA](https://www.baeldung.com/spring-jpa-soft-delete)
|
||||
|
||||
### Eclipse Config
|
||||
After importing the project into Eclipse, you may see the following error:
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ public class WebClientLoggingIntegrationTest {
|
||||
.exchange()
|
||||
.block();
|
||||
|
||||
verify(mockAppender).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains("domain=.typicode.com;")));
|
||||
verify(mockAppender).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains(sampleUrl)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@
|
||||
<module>spring-boot-swagger-jwt</module>
|
||||
<module>spring-boot-testing</module>
|
||||
<module>spring-boot-vue</module>
|
||||
<module>spring-boot-xml</module>
|
||||
<module>spring-boot-actuator</module>
|
||||
<module>spring-boot-data-2</module>
|
||||
<module>spring-boot-react</module>
|
||||
|
||||
@@ -5,3 +5,4 @@ This module contains articles about Spring Boot customization 2
|
||||
### Relevant Articles:
|
||||
|
||||
- [DispatcherServlet and web.xml in Spring Boot](https://www.baeldung.com/spring-boot-dispatcherservlet-web-xml)
|
||||
- [XML Defined Beans in Spring Boot](https://www.baeldung.com/spring-boot-xml-beans)
|
||||
@@ -23,7 +23,10 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
sample=string loaded from properties!
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user