Merge remote-tracking branch 'upstream/master' into JAVA-22_spring_boot_rest_refactoring
This commit is contained in:
commit
609e2c5c1b
2
.gitignore
vendored
2
.gitignore
vendored
@ -73,8 +73,6 @@ ninja/devDb.mv.db
|
|||||||
**/out-tsc
|
**/out-tsc
|
||||||
**/nbproject/
|
**/nbproject/
|
||||||
**/nb-configuration.xml
|
**/nb-configuration.xml
|
||||||
core-scala/.cache-main
|
|
||||||
core-scala/.cache-tests
|
|
||||||
|
|
||||||
|
|
||||||
persistence-modules/hibernate5/transaction.log
|
persistence-modules/hibernate5/transaction.log
|
||||||
|
44
README.md
44
README.md
@ -22,10 +22,38 @@ This project is **a collection of small and focused tutorials** - each covering
|
|||||||
A strong focus of these is, of course, the Spring Framework - Spring, Spring Boot and Spring Security.
|
A strong focus of these is, of course, the Spring Framework - Spring, Spring Boot and Spring Security.
|
||||||
In additional to Spring, the modules here are covering a number of aspects in Java.
|
In additional to Spring, the modules here are covering a number of aspects in Java.
|
||||||
|
|
||||||
|
Profile based segregation
|
||||||
|
====================
|
||||||
|
|
||||||
|
We are using maven build profiles to segregate the huge list of individual projects we have in our repository.
|
||||||
|
|
||||||
|
The projects are broadly divided into 3 list: first, second and heavy.
|
||||||
|
|
||||||
|
Next, they are segregated further on the basis of tests that we want to execute.
|
||||||
|
|
||||||
|
Therefore, we have a total of 6 profiles:
|
||||||
|
|
||||||
|
| Profile | Includes | Type of test enabled |
|
||||||
|
| ----------------------- | --------------------------- | -------------------- |
|
||||||
|
| default-first | First set of projects | *UnitTest |
|
||||||
|
| integration-lite-first | First set of projects | *IntegrationTest |
|
||||||
|
| default-second | Second set of projects | *UnitTest |
|
||||||
|
| integration-lite-second | Second set of projects | *IntegrationTest |
|
||||||
|
| default-heavy | Heavy/long running projects | *UnitTest |
|
||||||
|
| integration-heavy | Heavy/long running projects | *IntegrationTest |
|
||||||
|
|
||||||
Building the project
|
Building the project
|
||||||
====================
|
====================
|
||||||
To do the full build, do: `mvn clean install`
|
|
||||||
|
Though it should not be needed often to build the entire repository at once because we are usually concerned with a specific module.
|
||||||
|
|
||||||
|
But if we want to, we can invoke the below command from the root of the repository if we want to build the entire repository with only Unit Tests enabled:
|
||||||
|
|
||||||
|
`mvn clean install -Pdefault-first,default-second,default-heavy`
|
||||||
|
|
||||||
|
or if we want to build the entire repository with Integration Tests enabled, we can do:
|
||||||
|
|
||||||
|
`mvn clean install -Pintegration-lite-first,integration-lite-second,integration-heavy`
|
||||||
|
|
||||||
|
|
||||||
Building a single module
|
Building a single module
|
||||||
@ -46,8 +74,18 @@ When you're working with an individual module, there's no need to import all of
|
|||||||
|
|
||||||
Running Tests
|
Running Tests
|
||||||
=============
|
=============
|
||||||
The command `mvn clean install` will run the unit tests in a module.
|
The command `mvn clean install` from within a module will run the unit tests in that module.
|
||||||
To run the integration tests, use the command `mvn clean install -Pintegration-lite-first`
|
For Spring modules this will also run the `SpringContextTest` if present.
|
||||||
|
|
||||||
|
To run the integration tests, use the command:
|
||||||
|
|
||||||
|
`mvn clean install -Pintegration-lite-first` or
|
||||||
|
|
||||||
|
`mvn clean install -Pintegration-lite-second` or
|
||||||
|
|
||||||
|
`mvn clean install -Pintegration-heavy`
|
||||||
|
|
||||||
|
depending on the list where our module exists
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,3 +10,4 @@ This module contains articles about searching algorithms.
|
|||||||
- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms)
|
- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms)
|
||||||
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search)
|
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search)
|
||||||
- [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search)
|
- [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search)
|
||||||
|
- [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree)
|
||||||
|
3
apache-beam/README.md
Normal file
3
apache-beam/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [Introduction to Apache Beam](https://www.baeldung.com/apache-beam)
|
@ -16,12 +16,6 @@
|
|||||||
<name>aws-reactive</name>
|
<name>aws-reactive</name>
|
||||||
<description>AWS Reactive Sample</description>
|
<description>AWS Reactive Sample</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<spring.version>2.2.1.RELEASE</spring.version>
|
|
||||||
<awssdk.version>2.10.27</awssdk.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
@ -105,4 +99,9 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<spring.version>2.2.1.RELEASE</spring.version>
|
||||||
|
<awssdk.version>2.10.27</awssdk.version>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -5,3 +5,5 @@ This module contains articles about Java 14.
|
|||||||
### Relevant articles
|
### Relevant articles
|
||||||
|
|
||||||
- [Guide to the @Serial Annotation in Java 14](https://www.baeldung.com/java-14-serial-annotation)
|
- [Guide to the @Serial Annotation in Java 14](https://www.baeldung.com/java-14-serial-annotation)
|
||||||
|
- [Java Text Blocks](https://www.baeldung.com/java-text-blocks)
|
||||||
|
- [Pattern Matching for instanceof in Java 14](https://www.baeldung.com/java-pattern-matching-instanceof)
|
||||||
|
3
core-java-modules/core-java-arrays-3/README.md
Normal file
3
core-java-modules/core-java-arrays-3/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [Arrays.deepEquals](https://www.baeldung.com/java-arrays-deepequals)
|
@ -0,0 +1,189 @@
|
|||||||
|
package com.baeldung.concurrent.atomic;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicMarkableReference;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class AtomicMarkableReferenceUnitTest {
|
||||||
|
|
||||||
|
class Employee {
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
Employee(int id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenMarkValueAsTrue_whenUsingIsMarkedMethod_thenMarkValueShouldBeTrue() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenMarkValueAsFalse_whenUsingIsMarkedMethod_thenMarkValueShouldBeFalse() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, false);
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingGetReferenceMethod_thenCurrentReferenceShouldBeReturned() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
|
||||||
|
Assertions.assertEquals(employee, employeeNode.getReference());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingGetMethod_thenCurrentReferenceAndMarkShouldBeReturned() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
|
||||||
|
boolean[] markHolder = new boolean[1];
|
||||||
|
Employee currentEmployee = employeeNode.get(markHolder);
|
||||||
|
|
||||||
|
Assertions.assertEquals(employee, currentEmployee);
|
||||||
|
Assertions.assertTrue(markHolder[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNewReferenceAndMark_whenUsingSetMethod_thenCurrentReferenceAndMarkShouldBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
employeeNode.set(newEmployee, false);
|
||||||
|
|
||||||
|
Assertions.assertEquals(newEmployee, employeeNode.getReference());
|
||||||
|
Assertions.assertFalse(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTheSameObjectReference_whenUsingAttemptMarkMethod_thenMarkShouldBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
|
||||||
|
Assertions.assertTrue(employeeNode.attemptMark(employee, false));
|
||||||
|
Assertions.assertFalse(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenDifferentObjectReference_whenUsingAttemptMarkMethod_thenMarkShouldNotBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee expectedEmployee = new Employee(123, "Mike");
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.attemptMark(expectedEmployee, false));
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenCurrentReferenceAndCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertTrue(employeeNode.compareAndSet(employee, newEmployee, true, false));
|
||||||
|
Assertions.assertEquals(newEmployee, employeeNode.getReference());
|
||||||
|
Assertions.assertFalse(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNotCurrentReferenceAndCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.compareAndSet(new Employee(1234, "Steve"), newEmployee, true, false));
|
||||||
|
Assertions.assertEquals(employee, employeeNode.getReference());
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenCurrentReferenceAndNotCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.compareAndSet(employee, newEmployee, false, true));
|
||||||
|
Assertions.assertEquals(employee, employeeNode.getReference());
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNotCurrentReferenceAndNotCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.compareAndSet(new Employee(1234, "Steve"), newEmployee, false, true));
|
||||||
|
Assertions.assertEquals(employee, employeeNode.getReference());
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenCurrentReferenceAndCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertTrue(employeeNode.weakCompareAndSet(employee, newEmployee, true, false));
|
||||||
|
Assertions.assertEquals(newEmployee, employeeNode.getReference());
|
||||||
|
Assertions.assertFalse(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNotCurrentReferenceAndCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.weakCompareAndSet(new Employee(1234, "Steve"), newEmployee, true, false));
|
||||||
|
Assertions.assertEquals(employee, employeeNode.getReference());
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenCurrentReferenceAndNotCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.weakCompareAndSet(employee, newEmployee, false, true));
|
||||||
|
Assertions.assertEquals(employee, employeeNode.getReference());
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNotCurrentReferenceAndNotCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() {
|
||||||
|
Employee employee = new Employee(123, "Mike");
|
||||||
|
AtomicMarkableReference<Employee> employeeNode = new AtomicMarkableReference<Employee>(employee, true);
|
||||||
|
Employee newEmployee = new Employee(124, "John");
|
||||||
|
|
||||||
|
Assertions.assertFalse(employeeNode.weakCompareAndSet(new Employee(1234, "Steve"), newEmployee, false, true));
|
||||||
|
Assertions.assertEquals(employee, employeeNode.getReference());
|
||||||
|
Assertions.assertTrue(employeeNode.isMarked());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<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>
|
||||||
|
<groupId>com.baeldung.concurrent.lock</groupId>
|
||||||
|
<artifactId>core-java-concurrency-collections-2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>${guava.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-core</artifactId>
|
||||||
|
<version>${jmh.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
|
<version>${jmh.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jmh.version>1.21</jmh.version>
|
||||||
|
<guava.version>28.2-jre</guava.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.baeldung.concurrent.lock;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Fork;
|
||||||
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
|
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||||
|
import org.openjdk.jmh.annotations.Scope;
|
||||||
|
import org.openjdk.jmh.annotations.State;
|
||||||
|
import org.openjdk.jmh.annotations.Warmup;
|
||||||
|
|
||||||
|
@State(Scope.Thread)
|
||||||
|
@Fork(value = 2)
|
||||||
|
@Warmup(iterations = 0)
|
||||||
|
public class ConcurrentAccessBenchmark {
|
||||||
|
static final int SLOTS = 4;
|
||||||
|
static final int THREADS = 10000;
|
||||||
|
static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS;
|
||||||
|
SingleLock singleLock = new SingleLock();
|
||||||
|
StripedLock stripedLock = new StripedLock(BUCKETS);
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.Throughput)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
public Map<String,String> singleLockHashMap() throws InterruptedException {
|
||||||
|
return singleLock.doWork(new HashMap<String,String>(), THREADS, SLOTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.Throughput)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
public Map<String,String> stripedLockHashMap() throws InterruptedException {
|
||||||
|
return stripedLock.doWork(new HashMap<String,String>(), THREADS, SLOTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.Throughput)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
public Map<String,String> singleLockConcurrentHashMap() throws InterruptedException {
|
||||||
|
return singleLock.doWork(new ConcurrentHashMap<String,String>(), THREADS, SLOTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.Throughput)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
public Map<String,String> stripedLockConcurrentHashMap() throws InterruptedException {
|
||||||
|
return stripedLock.doWork(new ConcurrentHashMap<String,String>(), THREADS, SLOTS);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.baeldung.concurrent.lock;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
|
public abstract class ConcurrentAccessExperiment {
|
||||||
|
|
||||||
|
public final Map<String,String> doWork(Map<String,String> map, int threads, int slots) {
|
||||||
|
CompletableFuture<?>[] requests = new CompletableFuture<?>[threads * slots];
|
||||||
|
|
||||||
|
for (int i = 0; i < threads; i++) {
|
||||||
|
requests[slots * i + 0] = CompletableFuture.supplyAsync(putSupplier(map, i));
|
||||||
|
requests[slots * i + 1] = CompletableFuture.supplyAsync(getSupplier(map, i));
|
||||||
|
requests[slots * i + 2] = CompletableFuture.supplyAsync(getSupplier(map, i));
|
||||||
|
requests[slots * i + 3] = CompletableFuture.supplyAsync(getSupplier(map, i));
|
||||||
|
}
|
||||||
|
CompletableFuture.allOf(requests).join();
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Supplier<?> putSupplier(Map<String,String> map, int key);
|
||||||
|
protected abstract Supplier<?> getSupplier(Map<String,String> map, int key);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.concurrent.lock;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
|
public class SingleLock extends ConcurrentAccessExperiment {
|
||||||
|
ReentrantLock lock;
|
||||||
|
|
||||||
|
public SingleLock() {
|
||||||
|
lock = new ReentrantLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Supplier<?> putSupplier(Map<String,String> map, int key) {
|
||||||
|
return (()-> {
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
return map.put("key" + key, "value" + key);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Supplier<?> getSupplier(Map<String,String> map, int key) {
|
||||||
|
return (()-> {
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
return map.get("key" + key);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.baeldung.concurrent.lock;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.util.concurrent.Striped;
|
||||||
|
|
||||||
|
public class StripedLock extends ConcurrentAccessExperiment {
|
||||||
|
Striped<Lock> stripedLock;
|
||||||
|
|
||||||
|
public StripedLock(int buckets) {
|
||||||
|
stripedLock = Striped.lock(buckets);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Supplier<?> putSupplier(Map<String,String> map, int key) {
|
||||||
|
return (()-> {
|
||||||
|
int bucket = key % stripedLock.size();
|
||||||
|
Lock lock = stripedLock.get(bucket);
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
return map.put("key" + key, "value" + key);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Supplier<?> getSupplier(Map<String,String> map, int key) {
|
||||||
|
return (()-> {
|
||||||
|
int bucket = key % stripedLock.size();
|
||||||
|
Lock lock = stripedLock.get(bucket);
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
return map.get("key" + key);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -7,3 +7,5 @@ This module contains articles about core java exceptions
|
|||||||
- [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice)
|
- [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice)
|
||||||
- [Wrapping vs Rethrowing Exceptions in Java](https://www.baeldung.com/java-wrapping-vs-rethrowing-exceptions)
|
- [Wrapping vs Rethrowing Exceptions in Java](https://www.baeldung.com/java-wrapping-vs-rethrowing-exceptions)
|
||||||
- [java.net.UnknownHostException: Invalid Hostname for Server](https://www.baeldung.com/java-unknownhostexception)
|
- [java.net.UnknownHostException: Invalid Hostname for Server](https://www.baeldung.com/java-unknownhostexception)
|
||||||
|
- [How to Handle Java SocketException](https://www.baeldung.com/java-socketexception)
|
||||||
|
- [Java Suppressed Exceptions](https://www.baeldung.com/java-suppressed-exceptions)
|
||||||
|
@ -47,6 +47,14 @@
|
|||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.tomakehurst</groupId>
|
||||||
|
<artifactId>wiremock</artifactId>
|
||||||
|
<version>2.26.3</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.baeldung.blockingnonblocking;
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||||
|
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class BlockingClientUnitTest {
|
||||||
|
private static final String REQUESTED_RESOURCE = "/test.json";
|
||||||
|
|
||||||
|
@Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
stubFor(get(urlEqualTo(REQUESTED_RESOURCE)).willReturn(aResponse()
|
||||||
|
.withStatus(200)
|
||||||
|
.withBody("{ \"response\" : \"It worked!\" }\r\n\r\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenSuccess() throws IOException {
|
||||||
|
// given an IO socket and somewhere to store our result
|
||||||
|
Socket socket = new Socket("localhost", wireMockRule.port());
|
||||||
|
StringBuilder ourStore = new StringBuilder();
|
||||||
|
|
||||||
|
// when we write and read (using try-with-resources so our resources are auto-closed)
|
||||||
|
try (InputStream serverInput = socket.getInputStream();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput));
|
||||||
|
OutputStream clientOutput = socket.getOutputStream();
|
||||||
|
PrintWriter writer = new PrintWriter(new OutputStreamWriter(clientOutput))) {
|
||||||
|
writer.print("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n");
|
||||||
|
writer.flush(); // important - without this the request is never sent, and the test will hang on readLine()
|
||||||
|
|
||||||
|
for (String line; (line = reader.readLine()) != null; ) {
|
||||||
|
ourStore.append(line);
|
||||||
|
ourStore.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// then we read and saved our data
|
||||||
|
assertTrue(ourStore
|
||||||
|
.toString()
|
||||||
|
.contains("It worked!"));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
package com.baeldung.blockingnonblocking;
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.CharsetDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||||
|
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class NonBlockingClientUnitTest {
|
||||||
|
private String REQUESTED_RESOURCE = "/test.json";
|
||||||
|
|
||||||
|
@Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
stubFor(get(urlEqualTo(REQUESTED_RESOURCE)).willReturn(aResponse()
|
||||||
|
.withStatus(200)
|
||||||
|
.withBody("{ \"response\" : \"It worked!\" }")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaNIOSocketChannel_whenReadingAndWritingWithBuffers_thenSuccess() throws IOException {
|
||||||
|
// given a NIO SocketChannel and a charset
|
||||||
|
InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port());
|
||||||
|
SocketChannel socketChannel = SocketChannel.open(address);
|
||||||
|
Charset charset = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
// when we write and read using buffers
|
||||||
|
socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n")));
|
||||||
|
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.allocate(8192); // or allocateDirect if we need direct memory access
|
||||||
|
CharBuffer charBuffer = CharBuffer.allocate(8192);
|
||||||
|
CharsetDecoder charsetDecoder = charset.newDecoder();
|
||||||
|
StringBuilder ourStore = new StringBuilder();
|
||||||
|
while (socketChannel.read(byteBuffer) != -1 || byteBuffer.position() > 0) {
|
||||||
|
byteBuffer.flip();
|
||||||
|
storeBufferContents(byteBuffer, charBuffer, charsetDecoder, ourStore);
|
||||||
|
byteBuffer.compact();
|
||||||
|
}
|
||||||
|
socketChannel.close();
|
||||||
|
|
||||||
|
// then we read and saved our data
|
||||||
|
assertTrue(ourStore
|
||||||
|
.toString()
|
||||||
|
.contains("It worked!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaNIOSocketChannel_whenReadingAndWritingWithSmallBuffers_thenSuccess() throws IOException {
|
||||||
|
// given a NIO SocketChannel and a charset
|
||||||
|
InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port());
|
||||||
|
SocketChannel socketChannel = SocketChannel.open(address);
|
||||||
|
Charset charset = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
// when we write and read using buffers that are too small for our message
|
||||||
|
socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n")));
|
||||||
|
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access
|
||||||
|
CharBuffer charBuffer = CharBuffer.allocate(8);
|
||||||
|
CharsetDecoder charsetDecoder = charset.newDecoder();
|
||||||
|
StringBuilder ourStore = new StringBuilder();
|
||||||
|
while (socketChannel.read(byteBuffer) != -1 || byteBuffer.position() > 0) {
|
||||||
|
byteBuffer.flip();
|
||||||
|
storeBufferContents(byteBuffer, charBuffer, charsetDecoder, ourStore);
|
||||||
|
byteBuffer.compact();
|
||||||
|
}
|
||||||
|
socketChannel.close();
|
||||||
|
|
||||||
|
// then we read and saved our data
|
||||||
|
assertTrue(ourStore
|
||||||
|
.toString()
|
||||||
|
.contains("It worked!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void storeBufferContents(ByteBuffer byteBuffer, CharBuffer charBuffer, CharsetDecoder charsetDecoder, StringBuilder ourStore) {
|
||||||
|
charsetDecoder.decode(byteBuffer, charBuffer, true);
|
||||||
|
charBuffer.flip();
|
||||||
|
ourStore.append(charBuffer);
|
||||||
|
charBuffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,4 +9,5 @@ This module contains articles about core features in the Java language
|
|||||||
- [Java Default Parameters Using Method Overloading](https://www.baeldung.com/java-default-parameters-method-overloading)
|
- [Java Default Parameters Using Method Overloading](https://www.baeldung.com/java-default-parameters-method-overloading)
|
||||||
- [How to Return Multiple Values From a Java Method](https://www.baeldung.com/java-method-return-multiple-values)
|
- [How to Return Multiple Values From a Java Method](https://www.baeldung.com/java-method-return-multiple-values)
|
||||||
- [Guide to the Java finally Keyword](https://www.baeldung.com/java-finally-keyword)
|
- [Guide to the Java finally Keyword](https://www.baeldung.com/java-finally-keyword)
|
||||||
|
- [The Java Headless Mode](https://www.baeldung.com/java-headless-mode)
|
||||||
- [[<-- Prev]](/core-java-modules/core-java-lang)
|
- [[<-- Prev]](/core-java-modules/core-java-lang)
|
||||||
|
@ -8,4 +8,5 @@ This module contains articles about core Java non-blocking input and output (IO)
|
|||||||
- [Create a Symbolic Link with Java](https://www.baeldung.com/java-symlink)
|
- [Create a Symbolic Link with Java](https://www.baeldung.com/java-symlink)
|
||||||
- [Introduction to the Java NIO Selector](https://www.baeldung.com/java-nio-selector)
|
- [Introduction to the Java NIO Selector](https://www.baeldung.com/java-nio-selector)
|
||||||
- [Using Java MappedByteBuffer](https://www.baeldung.com/java-mapped-byte-buffer)
|
- [Using Java MappedByteBuffer](https://www.baeldung.com/java-mapped-byte-buffer)
|
||||||
|
- [How to Lock a File in Java](https://www.baeldung.com/java-lock-files)
|
||||||
- [[<-- Prev]](/core-java-modules/core-java-nio)
|
- [[<-- Prev]](/core-java-modules/core-java-nio)
|
@ -10,3 +10,4 @@ This module contains articles about performance of Java applications
|
|||||||
- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions)
|
- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions)
|
||||||
- [Monitoring Java Applications with Flight Recorder](https://www.baeldung.com/java-flight-recorder-monitoring)
|
- [Monitoring Java Applications with Flight Recorder](https://www.baeldung.com/java-flight-recorder-monitoring)
|
||||||
- [Branch Prediction in Java](https://www.baeldung.com/java-branch-prediction)
|
- [Branch Prediction in Java](https://www.baeldung.com/java-branch-prediction)
|
||||||
|
- [Capturing a Java Thread Dump](https://www.baeldung.com/java-thread-dump)
|
||||||
|
@ -8,3 +8,4 @@
|
|||||||
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
|
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
|
||||||
- [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile)
|
- [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile)
|
||||||
- [Difference Between Java Matcher find() and matches()](https://www.baeldung.com/java-matcher-find-vs-matches)
|
- [Difference Between Java Matcher find() and matches()](https://www.baeldung.com/java-matcher-find-vs-matches)
|
||||||
|
- [How to Use Regular Expressions to Replace Tokens in Strings](https://www.baeldung.com/java-regex-token-replacement)
|
||||||
|
3
core-java-modules/core-java-security-2/README.md
Normal file
3
core-java-modules/core-java-security-2/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [Guide To The Java Authentication And Authorization Service (JAAS)](https://www.baeldung.com/java-authentication-authorization-service)
|
@ -10,4 +10,5 @@ This module contains articles about string operations.
|
|||||||
- [Java String equalsIgnoreCase()](https://www.baeldung.com/java-string-equalsignorecase)
|
- [Java String equalsIgnoreCase()](https://www.baeldung.com/java-string-equalsignorecase)
|
||||||
- [Case-Insensitive String Matching in Java](https://www.baeldung.com/java-case-insensitive-string-matching)
|
- [Case-Insensitive String Matching in Java](https://www.baeldung.com/java-case-insensitive-string-matching)
|
||||||
- [L-Trim and R-Trim in Java](https://www.baeldung.com/l-trim-and-r-trim-in-java)
|
- [L-Trim and R-Trim in Java](https://www.baeldung.com/l-trim-and-r-trim-in-java)
|
||||||
|
- [L-Trim and R-Trim Alternatives in Java](https://www.baeldung.com/java-trim-alternatives)
|
||||||
- More articles: [[<-- prev]](../core-java-string-operations)
|
- More articles: [[<-- prev]](../core-java-string-operations)
|
||||||
|
@ -64,6 +64,11 @@
|
|||||||
<artifactId>jmh-generator-annprocess</artifactId>
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
<version>${jmh-generator.version}</version>
|
<version>${jmh-generator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>${commons-codec.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
@ -113,6 +118,7 @@
|
|||||||
<hibernate-validator.version>6.0.2.Final</hibernate-validator.version>
|
<hibernate-validator.version>6.0.2.Final</hibernate-validator.version>
|
||||||
<javax.el-api.version>3.0.0</javax.el-api.version>
|
<javax.el-api.version>3.0.0</javax.el-api.version>
|
||||||
<javax.el.version>2.2.6</javax.el.version>
|
<javax.el.version>2.2.6</javax.el.version>
|
||||||
|
<commons-codec.version>1.14</commons-codec.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.core-kotlin-modules</groupId>
|
<groupId>com.baeldung.core-kotlin-modules</groupId>
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
## Core Scala
|
|
||||||
|
|
||||||
This module contains articles about Scala's core features
|
|
||||||
|
|
||||||
### Relevant Articles:
|
|
||||||
|
|
||||||
- [Introduction to Scala](https://www.baeldung.com/scala-intro)
|
|
||||||
- [Regular Expressions in Scala](https://www.baeldung.com/scala/regular-expressions)
|
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>core-scala</artifactId>
|
<artifactId>core-scala</artifactId>
|
||||||
@ -51,5 +53,5 @@
|
|||||||
<scala.version>2.12.7</scala.version>
|
<scala.version>2.12.7</scala.version>
|
||||||
<scala.plugin.version>3.3.2</scala.plugin.version>
|
<scala.plugin.version>3.3.2</scala.plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
|
||||||
|
|
||||||
|
</project>
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample code demonstrating the various control structured.
|
|
||||||
*
|
|
||||||
* @author Chandra Prakash
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
object ControlStructuresDemo {
|
|
||||||
def gcd(x : Int, y : Int) : Int = {
|
|
||||||
if (y == 0) x else gcd(y, x % y)
|
|
||||||
}
|
|
||||||
|
|
||||||
def gcdIter(x : Int, y : Int) : Int = {
|
|
||||||
var a = x
|
|
||||||
var b = y
|
|
||||||
while (b > 0) {
|
|
||||||
a = a % b
|
|
||||||
val t = a
|
|
||||||
a = b
|
|
||||||
b = t
|
|
||||||
}
|
|
||||||
a
|
|
||||||
}
|
|
||||||
|
|
||||||
def rangeSum(a : Int, b : Int) = {
|
|
||||||
var sum = 0;
|
|
||||||
for (i <- a to b) {
|
|
||||||
sum += i
|
|
||||||
}
|
|
||||||
sum
|
|
||||||
}
|
|
||||||
|
|
||||||
def factorial(a : Int) : Int = {
|
|
||||||
var result = 1;
|
|
||||||
var i = 1;
|
|
||||||
do {
|
|
||||||
result *= i
|
|
||||||
i = i + 1
|
|
||||||
} while (i <= a)
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample Code demonstrating a class.
|
|
||||||
*
|
|
||||||
* @author Chandra Prakash
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Employee(val name : String,
|
|
||||||
var salary : Int,
|
|
||||||
annualIncrement : Int = 20) {
|
|
||||||
|
|
||||||
def incrementSalary() : Unit = {
|
|
||||||
salary += annualIncrement
|
|
||||||
}
|
|
||||||
|
|
||||||
override def toString =
|
|
||||||
s"Employee(name=$name, salary=$salary)"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Trait which will make the toString return upper case value.
|
|
||||||
*/
|
|
||||||
trait UpperCasePrinter {
|
|
||||||
override def toString: String = super.toString toUpperCase
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
object HelloWorld extends App {
|
|
||||||
println("Hello World!")
|
|
||||||
args foreach println
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample higher order functions.
|
|
||||||
*
|
|
||||||
* @author Chandra Prakash
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
object HigherOrderFunctions {
|
|
||||||
|
|
||||||
def mapReduce(r : (Int, Int) => Int,
|
|
||||||
i : Int,
|
|
||||||
m : Int => Int,
|
|
||||||
a : Int, b : Int): Int = {
|
|
||||||
def iter(a : Int, result : Int) : Int = {
|
|
||||||
if (a > b) result
|
|
||||||
else iter(a + 1, r(m(a), result))
|
|
||||||
}
|
|
||||||
iter(a, i)
|
|
||||||
}
|
|
||||||
|
|
||||||
def whileLoop(condition : => Boolean)(body : => Unit) : Unit =
|
|
||||||
if (condition) {
|
|
||||||
body
|
|
||||||
whileLoop(condition)(body)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An abstract class for set of integers and its implementation.
|
|
||||||
*
|
|
||||||
* @author Chandra Prakash
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
abstract class IntSet {
|
|
||||||
// add an element to the set
|
|
||||||
def incl(x : Int) : IntSet
|
|
||||||
|
|
||||||
// whether an element belongs to the set
|
|
||||||
def contains(x : Int) : Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
class EmptyIntSet extends IntSet {
|
|
||||||
|
|
||||||
def contains(x : Int) : Boolean = false
|
|
||||||
|
|
||||||
def incl(x : Int) =
|
|
||||||
new NonEmptyIntSet(x, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NonEmptyIntSet(val head : Int, val tail : IntSet)
|
|
||||||
extends IntSet {
|
|
||||||
|
|
||||||
def contains(x : Int) : Boolean =
|
|
||||||
head == x || (tail contains x)
|
|
||||||
|
|
||||||
def incl(x : Int) : IntSet =
|
|
||||||
if (this contains x) this
|
|
||||||
else new NonEmptyIntSet(x, this)
|
|
||||||
}
|
|
@ -1,137 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
// Case Class
|
|
||||||
abstract class Animal
|
|
||||||
|
|
||||||
case class Mammal(name: String, fromSea: Boolean) extends Animal
|
|
||||||
|
|
||||||
case class Bird(name: String) extends Animal
|
|
||||||
|
|
||||||
case class Fish(name: String) extends Animal
|
|
||||||
|
|
||||||
// Sealed Class
|
|
||||||
sealed abstract class CardSuit
|
|
||||||
|
|
||||||
case class Spike() extends CardSuit
|
|
||||||
|
|
||||||
case class Diamond() extends CardSuit
|
|
||||||
|
|
||||||
case class Heart() extends CardSuit
|
|
||||||
|
|
||||||
case class Club() extends CardSuit
|
|
||||||
|
|
||||||
object Person {
|
|
||||||
def apply(fullName: String) = fullName
|
|
||||||
|
|
||||||
def unapply(fullName: String): Option[String] = {
|
|
||||||
if (!fullName.isEmpty)
|
|
||||||
Some(fullName.replaceAll("(?<=\\w)(\\w+)", "."))
|
|
||||||
else
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PatternMatching {
|
|
||||||
|
|
||||||
def caseClassesPatternMatching(animal: Animal): String = {
|
|
||||||
animal match {
|
|
||||||
case Mammal(name, fromSea) => s"I'm a $name, a kind of mammal. Am I from the sea? $fromSea"
|
|
||||||
case Bird(name) => s"I'm a $name, a kind of bird"
|
|
||||||
case _ => "I'm an unknown animal"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def constantsPatternMatching(constant: Any): String = {
|
|
||||||
constant match {
|
|
||||||
case 0 => "I'm equal to zero"
|
|
||||||
case 4.5d => "I'm a double"
|
|
||||||
case false => "I'm the contrary of true"
|
|
||||||
case _ => s"I'm unknown and equal to $constant"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def sequencesPatternMatching(sequence: Any): String = {
|
|
||||||
sequence match {
|
|
||||||
case List(singleElement) => s"I'm a list with one element: $singleElement"
|
|
||||||
case List(_, _*) => s"I'm a list with one or multiple elements: $sequence"
|
|
||||||
case Vector(1, 2, _*) => s"I'm a vector: $sequence"
|
|
||||||
case _ => s"I'm an unrecognized sequence. My value: $sequence"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def tuplesPatternMatching(tuple: Any): String = {
|
|
||||||
tuple match {
|
|
||||||
case (first, second) => s"I'm a tuple with two elements: $first & $second"
|
|
||||||
case (first, second, third) => s"I'm a tuple with three elements: $first & $second & $third"
|
|
||||||
case _ => s"Unrecognized pattern. My value: $tuple"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def typedPatternMatching(any: Any): String = {
|
|
||||||
any match {
|
|
||||||
case string: String => s"I'm a string. My value: $string"
|
|
||||||
case integer: Int => s"I'm an integer. My value: $integer"
|
|
||||||
case _ => s"I'm from an unknown type. My value: $any"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def regexPatterns(toMatch: String): String = {
|
|
||||||
val numeric = """([0-9]+)""".r
|
|
||||||
val alphabetic = """([a-zA-Z]+)""".r
|
|
||||||
val alphanumeric = """([a-zA-Z0-9]+)""".r
|
|
||||||
|
|
||||||
toMatch match {
|
|
||||||
case numeric(value) => s"I'm a numeric with value $value"
|
|
||||||
case alphabetic(value) => s"I'm an alphabetic with value $value"
|
|
||||||
case alphanumeric(value) => s"I'm an alphanumeric with value $value"
|
|
||||||
case _ => s"I contain other characters than alphanumerics. My value $toMatch"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def optionsPatternMatching(option: Option[String]): String = {
|
|
||||||
option match {
|
|
||||||
case Some(value) => s"I'm not an empty option. Value $value"
|
|
||||||
case None => "I'm an empty option"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def patternGuards(toMatch: Any, maxLength: Int): String = {
|
|
||||||
toMatch match {
|
|
||||||
case list: List[Any] if (list.size <= maxLength) => "List is of acceptable size"
|
|
||||||
case list: List[Any] => "List has not an acceptable size"
|
|
||||||
case string: String if (string.length <= maxLength) => "String is of acceptable size"
|
|
||||||
case string: String => "String has not an acceptable size"
|
|
||||||
case _ => "Input is neither a List or a String"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def sealedClass(cardSuit: CardSuit): String = {
|
|
||||||
cardSuit match {
|
|
||||||
case Spike() => "Card is spike"
|
|
||||||
case Club() => "Card is club"
|
|
||||||
case Heart() => "Card is heart"
|
|
||||||
case Diamond() => "Card is diamond"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def extractors(person: Any): String = {
|
|
||||||
person match {
|
|
||||||
case Person(initials) => s"My initials are $initials"
|
|
||||||
case _ => "Could not extract initials"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def closuresPatternMatching(list: List[Any]): List[Any] = {
|
|
||||||
list.collect { case i: Int if (i < 10) => i }
|
|
||||||
}
|
|
||||||
|
|
||||||
def catchBlocksPatternMatching(exception: Exception): String = {
|
|
||||||
try {
|
|
||||||
throw exception
|
|
||||||
} catch {
|
|
||||||
case ex: IllegalArgumentException => "It's an IllegalArgumentException"
|
|
||||||
case ex: RuntimeException => "It's a RuntimeException"
|
|
||||||
case _ => "It's an unknown kind of exception"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some utility methods.
|
|
||||||
*
|
|
||||||
* @author Chandra Prakash
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
object Utils {
|
|
||||||
def average(x : Double, y : Double): Double = (x + y) / 2
|
|
||||||
|
|
||||||
def randomLessThan(d : Double): Double = {
|
|
||||||
var random = 0d
|
|
||||||
do {
|
|
||||||
random = Math.random()
|
|
||||||
} while (random >= d)
|
|
||||||
random
|
|
||||||
}
|
|
||||||
|
|
||||||
def power(x : Int, y : Int) : Int = {
|
|
||||||
def powNested(i : Int, accumulator : Int) : Int = {
|
|
||||||
if (i <= 0) accumulator
|
|
||||||
else powNested(i - 1, x * accumulator)
|
|
||||||
}
|
|
||||||
powNested(y, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
def fibonacci(n : Int) : Int = n match {
|
|
||||||
case 0 | 1 => 1
|
|
||||||
case x if x > 1 =>
|
|
||||||
fibonacci(x - 1) + fibonacci(x - 2)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
import com.baeldung.scala.ControlStructuresDemo._
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
class ControlStructuresDemoUnitTest {
|
|
||||||
@Test
|
|
||||||
def givenTwoIntegers_whenGcdCalled_thenCorrectValueReturned() = {
|
|
||||||
assertEquals(3, gcd(15, 27))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenTwoIntegers_whenGcdIterCalled_thenCorrectValueReturned() = {
|
|
||||||
assertEquals(3, gcdIter(15, 27))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenTwoIntegers_whenRangeSumcalled_thenCorrectValueReturned() = {
|
|
||||||
assertEquals(55, rangeSum(1, 10))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenPositiveInteger_whenFactorialInvoked_thenCorrectValueReturned() = {
|
|
||||||
assertEquals(720, factorial(6))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenFactorialOf0Invoked_then1Returned() = {
|
|
||||||
assertEquals(1, factorial(0))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
class EmployeeUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenEmployeeSalaryIncremented_thenCorrectSalary() = {
|
|
||||||
val employee = new Employee("John Doe", 1000)
|
|
||||||
employee.incrementSalary()
|
|
||||||
assertEquals(1020, employee.salary)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenEmployee_whenToStringCalled_thenCorrectStringReturned() = {
|
|
||||||
val employee = new Employee("John Doe", 1000)
|
|
||||||
assertEquals("Employee(name=John Doe, salary=1000)", employee.toString)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenEmployeeWithTrait_whenToStringCalled_thenCorrectStringReturned() = {
|
|
||||||
val employee =
|
|
||||||
new Employee("John Doe", 1000) with UpperCasePrinter
|
|
||||||
assertEquals("EMPLOYEE(NAME=JOHN DOE, SALARY=1000)", employee.toString)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
|
|
||||||
class HigherOrderFunctionsExamplesUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenCallingMapWithAnonymousFunction_thenTransformationIsApplied() = {
|
|
||||||
val expected = Seq("sir Alex Ferguson", "sir Bobby Charlton", "sir Frank Lampard")
|
|
||||||
|
|
||||||
val names = Seq("Alex Ferguson", "Bobby Charlton", "Frank Lampard")
|
|
||||||
val sirNames = names.map(name => "sir " + name)
|
|
||||||
|
|
||||||
assertEquals(expected, sirNames)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenCallingMapWithDefined_thenTransformationIsApplied() = {
|
|
||||||
val expected = Seq("sir Alex Ferguson", "sir Bobby Charlton", "sir Frank Lampard")
|
|
||||||
|
|
||||||
val names = Seq("Alex Ferguson", "Bobby Charlton", "Frank Lampard")
|
|
||||||
|
|
||||||
def prefixWithSir(name: String) = "sir " + name
|
|
||||||
val sirNames = names.map(prefixWithSir)
|
|
||||||
|
|
||||||
assertEquals(expected, sirNames)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenCallingFilter_thenUnecessaryElementsAreRemoved() = {
|
|
||||||
val expected = Seq("John O'Shea", "John Hartson")
|
|
||||||
|
|
||||||
val names = Seq("John O'Shea", "Aiden McGeady", "John Hartson")
|
|
||||||
val johns = names.filter(name => name.matches("^John .*"))
|
|
||||||
|
|
||||||
assertEquals(expected, johns)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenCallingReduce_thenProperSumIsCalculated() = {
|
|
||||||
val expected = 2750
|
|
||||||
|
|
||||||
val earnings = Seq(1000, 1300, 450)
|
|
||||||
val sumEarnings = earnings.reduce((acc, x) => acc + x)
|
|
||||||
|
|
||||||
assertEquals(expected, sumEarnings)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenCallingFold_thenNumberOfWordsShouldBeCalculated() = {
|
|
||||||
val expected = 6
|
|
||||||
|
|
||||||
val strings = Seq("bunch of words", "just me", "it")
|
|
||||||
val sumEarnings = strings.foldLeft(0)((acc, x) => acc + x.split(" ").size)
|
|
||||||
|
|
||||||
assertEquals(expected, sumEarnings)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenCallingOwnHigherOrderFunction_thenProperFunctionIsReturned() = {
|
|
||||||
def mathOperation(name: String): (Int, Int) => Int = (x: Int, y: Int) => {
|
|
||||||
name match {
|
|
||||||
case "addition" => x + y
|
|
||||||
case "multiplication" => x * y
|
|
||||||
case "division" => x/y
|
|
||||||
case "subtraction" => x - y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def add: (Int, Int) => Int = mathOperation("addition")
|
|
||||||
def mul: (Int, Int) => Int = mathOperation("multiplication")
|
|
||||||
def div: (Int, Int) => Int = mathOperation("division")
|
|
||||||
def sub: (Int, Int) => Int = mathOperation("subtraction")
|
|
||||||
|
|
||||||
assertEquals(15, add(10, 5))
|
|
||||||
assertEquals(50, mul(10, 5))
|
|
||||||
assertEquals(2, div(10, 5))
|
|
||||||
assertEquals(5, sub(10, 5))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
import com.baeldung.scala.HigherOrderFunctions.mapReduce
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
class HigherOrderFunctionsUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenCalledWithSumAndSquareFunctions_thenCorrectValueReturned() = {
|
|
||||||
def square(x : Int) = x * x
|
|
||||||
|
|
||||||
def sum(x : Int, y : Int) = x + y
|
|
||||||
|
|
||||||
def sumSquares(a : Int, b : Int) =
|
|
||||||
mapReduce(sum, 0, square, a, b)
|
|
||||||
|
|
||||||
assertEquals(385, sumSquares(1, 10))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenComputingSumOfSquaresWithAnonymousFunctions_thenCorrectValueReturned() = {
|
|
||||||
def sumSquares(a : Int, b : Int) =
|
|
||||||
mapReduce((x, y) => x + y, 0, x => x * x, a, b)
|
|
||||||
|
|
||||||
assertEquals(385, sumSquares(1, 10))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenCurriedFunctions_whenInvoked_thenCorrectValueReturned() = {
|
|
||||||
// a curried function
|
|
||||||
def sum(f : Int => Int)(a : Int,
|
|
||||||
b : Int) : Int =
|
|
||||||
if (a > b) 0 else f(a) + sum(f)(a + 1, b)
|
|
||||||
|
|
||||||
// another curried function
|
|
||||||
def mod(n : Int)(x : Int) = x % n
|
|
||||||
|
|
||||||
// application of a curried function
|
|
||||||
assertEquals(1, mod(5)(6))
|
|
||||||
|
|
||||||
// partial application of curried function
|
|
||||||
// trailing underscore is required to make function type explicit
|
|
||||||
val sumMod5 = sum(mod(5)) _
|
|
||||||
|
|
||||||
assertEquals(10, sumMod5(6, 10))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
import org.junit.Assert.assertFalse
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
class IntSetUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenSetof1To10_whenContains11Called_thenFalse() = {
|
|
||||||
|
|
||||||
// Set up a set containing integers 1 to 10.
|
|
||||||
val set1To10 =
|
|
||||||
Range(1, 10)
|
|
||||||
.foldLeft(new EmptyIntSet() : IntSet) {
|
|
||||||
(x, y) => x incl y
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse(set1To10 contains 11)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,208 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException
|
|
||||||
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
class PatternMatchingUnitTest {
|
|
||||||
@Test
|
|
||||||
def whenAMammalIsGivenToTheMatchExpression_ThenItsRecognizedAsMammal(): Unit = {
|
|
||||||
val result = new PatternMatching().caseClassesPatternMatching(Mammal("Lion", fromSea = false))
|
|
||||||
assertEquals("I'm a Lion, a kind of mammal. Am I from the sea? false", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenABirdIsGivenToTheMatchExpression_ThenItsRecognizedAsBird(): Unit = {
|
|
||||||
val result = new PatternMatching().caseClassesPatternMatching(Bird("Pigeon"))
|
|
||||||
assertEquals("I'm a Pigeon, a kind of bird", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnUnkownAnimalIsGivenToTheMatchExpression_TheDefaultClauseIsUsed(): Unit = {
|
|
||||||
val result = new PatternMatching().caseClassesPatternMatching(Fish("Tuna"))
|
|
||||||
assertEquals("I'm an unknown animal", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenTheConstantZeroIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().constantsPatternMatching(0)
|
|
||||||
assertEquals("I'm equal to zero", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenFourAndAHalfIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().constantsPatternMatching(4.5d)
|
|
||||||
assertEquals("I'm a double", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenTheBooleanFalseIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().constantsPatternMatching(false)
|
|
||||||
assertEquals("I'm the contrary of true", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnUnkownConstantIsPassed_ThenTheDefaultPatternIsUsed(): Unit = {
|
|
||||||
val result = new PatternMatching().constantsPatternMatching(true)
|
|
||||||
assertEquals("I'm unknown and equal to true", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenASingleElementListIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().sequencesPatternMatching(List("String"))
|
|
||||||
assertEquals("I'm a list with one element: String", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAMultipleElementsListIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().sequencesPatternMatching(List("Multiple", "Elements"))
|
|
||||||
assertEquals("I'm a list with one or multiple elements: List(Multiple, Elements)", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAVectorBeginningWithOneAndTwoIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().sequencesPatternMatching(Vector(1, 2, 3))
|
|
||||||
assertEquals("I'm a vector: Vector(1, 2, 3)", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenANotMatchingVectorIsPassed_ThenItShouldntMatchAndEnterTheDefaultClause(): Unit = {
|
|
||||||
val result = new PatternMatching().sequencesPatternMatching(Vector(2, 1))
|
|
||||||
assertEquals("I'm an unrecognized sequence. My value: Vector(2, 1)", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnEmptyListIsPassed_ThenItShouldntMatchAndEnterTheDefaultClause(): Unit = {
|
|
||||||
val result = new PatternMatching().sequencesPatternMatching(List())
|
|
||||||
assertEquals("I'm an unrecognized sequence. My value: List()", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenATwoElementsTupleIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().tuplesPatternMatching(("First", "Second"))
|
|
||||||
assertEquals("I'm a tuple with two elements: First & Second", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAThreeElementsTupleIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().tuplesPatternMatching(("First", "Second", "Third"))
|
|
||||||
assertEquals("I'm a tuple with three elements: First & Second & Third", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnoterKindOfTupleIsPassed_ThenItShouldntMatchAndReturnTheDefaultPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().tuplesPatternMatching(("First"))
|
|
||||||
assertEquals("Unrecognized pattern. My value: First", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAStringConsistingOfNumericsOnlyIsPassed_ThenItShouldMatchTheNumericRegex(): Unit = {
|
|
||||||
val result = new PatternMatching().regexPatterns("123")
|
|
||||||
assertEquals("I'm a numeric with value 123", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAStringConsistignOfAlphabeticsOnlyIsPassed_ThenItShouldMatchTheAlphabeticRegex(): Unit = {
|
|
||||||
val result = new PatternMatching().regexPatterns("abc")
|
|
||||||
assertEquals("I'm an alphabetic with value abc", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAStringConsistignOfAlphanumericsOnlyIsPassed_ThenItShouldMatchTheAlphanumericRegex(): Unit = {
|
|
||||||
val result = new PatternMatching().regexPatterns("abc123")
|
|
||||||
assertEquals("I'm an alphanumeric with value abc123", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnotherTypeOfStringIsPassed_ThenItShouldntMatchAndReturnTheDefaultPattern(): Unit = {
|
|
||||||
val result = new PatternMatching().regexPatterns("abc_123")
|
|
||||||
assertEquals("I contain other characters than alphanumerics. My value abc_123", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAFilledOptionIsPassed_ThenItShouldMatchTheSomeClause(): Unit = {
|
|
||||||
val result = new PatternMatching().optionsPatternMatching(Option.apply("something"))
|
|
||||||
assertEquals("I'm not an empty option. Value something", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnEmptyOptionIsPassed_ThenItShouldMatchTheNoneClause(): Unit = {
|
|
||||||
val result = new PatternMatching().optionsPatternMatching(Option.empty)
|
|
||||||
assertEquals("I'm an empty option", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAListWithAcceptedSizeIsPassed_ThenThePositiveMessageIsSent(): Unit = {
|
|
||||||
val result = new PatternMatching().patternGuards(List(1, 2), 3)
|
|
||||||
assertEquals("List is of acceptable size", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAListWithAnUnacceptedSizeIsPassed_ThenTheNegativeMessageIsSent(): Unit = {
|
|
||||||
val result = new PatternMatching().patternGuards(List(1, 2, 3, 4), 3)
|
|
||||||
assertEquals("List has not an acceptable size", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAStringWithAcceptedSizeIsPassed_ThenThePositiveMessageIsSent(): Unit = {
|
|
||||||
val result = new PatternMatching().patternGuards("OK", 3)
|
|
||||||
assertEquals("String is of acceptable size", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAStringWithAnUnacceptedSizeIsPassed_ThenTheNegativeMessageIsSent(): Unit = {
|
|
||||||
val result = new PatternMatching().patternGuards("Not OK", 3)
|
|
||||||
assertEquals("String has not an acceptable size", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnObjectWhichIsNotAListOrAStringIsPassed_thenTheDefaultClauseIsUsed(): Unit = {
|
|
||||||
val result = new PatternMatching().patternGuards(1, 1)
|
|
||||||
assertEquals("Input is neither a List or a String", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenACardSuitIsPassed_ThenTheCorrespondingMatchCaseClauseIsUsed(): Unit = {
|
|
||||||
assertEquals("Card is spike", new PatternMatching().sealedClass(Spike()))
|
|
||||||
assertEquals("Card is club", new PatternMatching().sealedClass(Club()))
|
|
||||||
assertEquals("Card is heart", new PatternMatching().sealedClass(Heart()))
|
|
||||||
assertEquals("Card is diamond", new PatternMatching().sealedClass(Diamond()))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnObjectWithExtractorIsPassed_ThenTheExtractedValueIsUsedInTheCaseClause(): Unit = {
|
|
||||||
val person = Person("John Smith")
|
|
||||||
val result = new PatternMatching().extractors(person)
|
|
||||||
assertEquals("My initials are J. S.", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnObjectWithExtractorIsPassed_AndTheValueIsEmpty_ThenTheDefaultCaseClauseIsUsed(): Unit = {
|
|
||||||
val person = Person("")
|
|
||||||
val result = new PatternMatching().extractors(person)
|
|
||||||
assertEquals("Could not extract initials", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAListOfRandomElementsIsPassed_ThenOnlyTheIntegersBelowTenAreReturned(): Unit = {
|
|
||||||
val input = List(1, 2, "5", 11, true)
|
|
||||||
val result = new PatternMatching().closuresPatternMatching(input)
|
|
||||||
assertEquals(List(1, 2), result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAnExceptionIsPassed_ThenTheCorrespondingMessageIsReturned(): Unit = {
|
|
||||||
val pm = new PatternMatching()
|
|
||||||
|
|
||||||
val iae = new IllegalArgumentException()
|
|
||||||
val re = new RuntimeException()
|
|
||||||
val fnfe = new FileNotFoundException()
|
|
||||||
|
|
||||||
assertEquals("It's an IllegalArgumentException", pm.catchBlocksPatternMatching(iae))
|
|
||||||
assertEquals("It's a RuntimeException", pm.catchBlocksPatternMatching(re))
|
|
||||||
assertEquals("It's an unknown kind of exception", pm.catchBlocksPatternMatching(fnfe))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
|||||||
package com.baeldung.scala
|
|
||||||
|
|
||||||
import com.baeldung.scala.Utils.{average, fibonacci, power, randomLessThan}
|
|
||||||
import org.junit.Assert.{assertEquals, assertTrue}
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
class UtilsUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenAverageCalled_thenCorrectValueReturned(): Unit = {
|
|
||||||
assertEquals(15.0, average(10, 20), 1e-5)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenRandomLessThanInvokedWithANumber_thenARandomLessThanItReturned: Unit = {
|
|
||||||
val d = 0.1
|
|
||||||
assertTrue(randomLessThan(d) < d)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenPowerInvokedWith2And3_then8Returned: Unit = {
|
|
||||||
assertEquals(8, power(2, 3))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def whenFibonacciCalled_thenCorrectValueReturned: Unit = {
|
|
||||||
assertEquals(1, fibonacci(0))
|
|
||||||
assertEquals(1, fibonacci(1))
|
|
||||||
assertEquals(fibonacci(6),
|
|
||||||
fibonacci(4) + fibonacci(5))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
package com.baeldung.scala.regex
|
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
|
|
||||||
class RegexUnitTest {
|
|
||||||
private val polishPostalCode = "([0-9]{2})\\-([0-9]{3})".r
|
|
||||||
private val timestamp = "([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{3})".r
|
|
||||||
private val timestampUnanchored = timestamp.unanchored
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenRegularExpression_whenCallingFindFirstIn_thenShouldFindCorrectMatches(): Unit = {
|
|
||||||
val postCode = polishPostalCode.findFirstIn("Warsaw 01-011, Jerusalem Avenue")
|
|
||||||
assertEquals(Some("01-011"), postCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenRegularExpression_whenCallingFindFirstMatchIn_thenShouldFindCorrectMatches(): Unit = {
|
|
||||||
val postCodes = polishPostalCode.findFirstMatchIn("Warsaw 01-011, Jerusalem Avenue")
|
|
||||||
assertEquals(Some("011"), for (m <- postCodes) yield m.group(2))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenRegularExpression_whenCallingFindAllIn_thenShouldFindCorrectMatches(): Unit = {
|
|
||||||
val postCodes = polishPostalCode.findAllIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue")
|
|
||||||
.toList
|
|
||||||
assertEquals(List("01-011", "30-059"), postCodes)
|
|
||||||
|
|
||||||
polishPostalCode.findAllIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenRegularExpression_whenCallingFindAlMatchlIn_thenShouldFindCorrectMatches(): Unit = {
|
|
||||||
val postCodes = polishPostalCode.findAllMatchIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue")
|
|
||||||
.toList
|
|
||||||
val postalDistricts = for (m <- postCodes) yield m.group(1)
|
|
||||||
assertEquals(List("01", "30"), postalDistricts)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenRegularExpression_whenExtractingValues_thenShouldExtractCorrectValues(): Unit = {
|
|
||||||
val description = "11:34:01.411" match {
|
|
||||||
case timestamp(hour, minutes, _, _) => s"It's $minutes minutes after $hour"
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("It's 34 minutes after 11", description)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenUnanchoredRegularExpression_whenExtractingValues_thenShouldExtractCorrectValues(): Unit = {
|
|
||||||
val description = "Timestamp: 11:34:01.411 error appeared" match {
|
|
||||||
case timestampUnanchored(hour, minutes, _, _) => s"It's $minutes minutes after $hour"
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("It's 34 minutes after 11", description)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenRegularExpression_whenCallingReplaceAllIn_thenShouldReplaceText(): Unit = {
|
|
||||||
val minutes = timestamp.replaceAllIn("11:34:01.311", m => m.group(2))
|
|
||||||
|
|
||||||
assertEquals("34", minutes)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
def givenRegularExpression_whenCallingReplaceAllInWithMatcher_thenShouldReplaceText(): Unit = {
|
|
||||||
val secondsThatDayInTotal = timestamp.replaceAllIn("11:34:01.311", _ match {
|
|
||||||
case timestamp(hours, minutes, seconds, _) => s"$hours-$minutes"
|
|
||||||
})
|
|
||||||
|
|
||||||
assertEquals("11-34", secondsThatDayInTotal)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>couchbase</artifactId>
|
<artifactId>couchbase</artifactId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.pmd</groupId>
|
<groupId>com.baeldung.pmd</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>dagger</artifactId>
|
<artifactId>dagger</artifactId>
|
||||||
|
@ -9,3 +9,4 @@ This module contains articles about data structures in Java
|
|||||||
- [Circular Linked List Java Implementation](https://www.baeldung.com/java-circular-linked-list)
|
- [Circular Linked List Java Implementation](https://www.baeldung.com/java-circular-linked-list)
|
||||||
- [How to Print a Binary Tree Diagram](https://www.baeldung.com/java-print-binary-tree-diagram)
|
- [How to Print a Binary Tree Diagram](https://www.baeldung.com/java-print-binary-tree-diagram)
|
||||||
- [Introduction to Big Queue](https://www.baeldung.com/java-big-queue)
|
- [Introduction to Big Queue](https://www.baeldung.com/java-big-queue)
|
||||||
|
- [Guide to AVL Trees in Java](https://www.baeldung.com/java-avl-trees)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>data-structures</artifactId>
|
<artifactId>data-structures</artifactId>
|
||||||
|
@ -1 +1,3 @@
|
|||||||
## Relevant Articles
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [DDD Bounded Contexts and Java Modules](https://www.baeldung.com/java-modules-ddd-bounded-contexts)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.dddmodules.infrastructure</groupId>
|
<groupId>com.baeldung.dddmodules.infrastructure</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.dddmodules.mainapp</groupId>
|
<groupId>com.baeldung.dddmodules.mainapp</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.dddmodules.ordercontext</groupId>
|
<groupId>com.baeldung.dddmodules.ordercontext</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.dddmodules</groupId>
|
<groupId>com.baeldung.dddmodules</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.dddmodules.sharedkernel</groupId>
|
<groupId>com.baeldung.dddmodules.sharedkernel</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.dddmodules.shippingcontext</groupId>
|
<groupId>com.baeldung.dddmodules.shippingcontext</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.ddd</groupId>
|
<groupId>com.baeldung.ddd</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.deeplearning4j</groupId>
|
<groupId>com.baeldung.deeplearning4j</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>disruptor</artifactId>
|
<artifactId>disruptor</artifactId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>dozer</artifactId>
|
<artifactId>dozer</artifactId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>drools</artifactId>
|
<artifactId>drools</artifactId>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -48,8 +49,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
<mainClass>com.baeldung.dropwizard.introduction.IntroductionApplication</mainClass>
|
<mainClass>com.baeldung.dropwizard.introduction.IntroductionApplication</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>dubbo</artifactId>
|
<artifactId>dubbo</artifactId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.ethereum</groupId>
|
<groupId>com.baeldung.ethereum</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
<project
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.feign</groupId>
|
<groupId>com.baeldung.feign</groupId>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>google-cloud</artifactId>
|
<artifactId>google-cloud</artifactId>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<!-- POM file generated with GWT webAppCreator -->
|
<!-- POM file generated with GWT webAppCreator -->
|
||||||
@ -53,8 +54,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes"
|
<!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
|
||||||
update them in DevMode -->
|
|
||||||
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
|
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
@ -76,8 +76,7 @@
|
|||||||
<moduleName>com.baeldung.Google_web_toolkit</moduleName>
|
<moduleName>com.baeldung.Google_web_toolkit</moduleName>
|
||||||
<moduleShortName>Google_web_toolkit</moduleShortName>
|
<moduleShortName>Google_web_toolkit</moduleShortName>
|
||||||
<failOnError>true</failOnError>
|
<failOnError>true</failOnError>
|
||||||
<!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if
|
<!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use a different source language for java compilation -->
|
||||||
you use a different source language for java compilation -->
|
|
||||||
<sourceLevel>${maven.compiler.source}</sourceLevel>
|
<sourceLevel>${maven.compiler.source}</sourceLevel>
|
||||||
<!-- Compiler configuration -->
|
<!-- Compiler configuration -->
|
||||||
<compilerArgs>
|
<compilerArgs>
|
||||||
@ -109,9 +108,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
||||||
<!-- Setting maven.compiler.source to something different to 1.8 needs
|
<!-- Setting maven.compiler.source to something different to 1.8 needs that you configure the sourceLevel in gwt-maven-plugin since GWT compiler 2.8 requires 1.8 (see gwt-maven-plugin
|
||||||
that you configure the sourceLevel in gwt-maven-plugin since GWT compiler
|
block below) -->
|
||||||
2.8 requires 1.8 (see gwt-maven-plugin block below) -->
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
|
||||||
|
3
gradle-6/README.md
Normal file
3
gradle-6/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [What’s New in Gradle 6.0](https://www.baeldung.com/gradle-6-features)
|
3
gradle/gradle-to-maven/README.md
Normal file
3
gradle/gradle-to-maven/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [Converting Gradle Build File to Maven POM](https://www.baeldung.com/gradle-build-to-maven-pom)
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.graphql</groupId>
|
<groupId>com.baeldung.graphql</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>grpc</artifactId>
|
<artifactId>grpc</artifactId>
|
||||||
|
@ -13,4 +13,4 @@ This module contains articles about Gson
|
|||||||
- [Convert String to JsonObject with Gson](https://www.baeldung.com/gson-string-to-jsonobject)
|
- [Convert String to JsonObject with Gson](https://www.baeldung.com/gson-string-to-jsonobject)
|
||||||
- [Mapping Multiple JSON Fields to a Single Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field)
|
- [Mapping Multiple JSON Fields to a Single Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field)
|
||||||
- [Serializing and Deserializing a List with Gson](https://www.baeldung.com/gson-list)
|
- [Serializing and Deserializing a List with Gson](https://www.baeldung.com/gson-list)
|
||||||
|
- [Compare Two JSON Objects with Gson](https://www.baeldung.com/gson-compare-json-objects)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>guava-collections</artifactId>
|
<artifactId>guava-collections</artifactId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.examples.guice</groupId>
|
<groupId>com.baeldung.examples.guice</groupId>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>hazelcast</artifactId>
|
<artifactId>hazelcast</artifactId>
|
||||||
@ -32,7 +34,7 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- hazelcast jet-->
|
<!-- hazelcast jet -->
|
||||||
<hazelcast.jet.version>0.6</hazelcast.jet.version>
|
<hazelcast.jet.version>0.6</hazelcast.jet.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -4,3 +4,5 @@ This module contains articles about image processing.
|
|||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Working with Images in Java](https://www.baeldung.com/java-images)
|
- [Working with Images in Java](https://www.baeldung.com/java-images)
|
||||||
|
- [Intro to OpenCV with Java](https://www.baeldung.com/java-opencv)
|
||||||
|
- [Optical Character Recognition with Tesseract](https://www.baeldung.com/java-ocr-tesseract)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -13,10 +14,6 @@
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<unboundid.ldapsdk.version>4.0.4</unboundid.ldapsdk.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.unboundid</groupId>
|
<groupId>com.unboundid</groupId>
|
||||||
@ -52,4 +49,8 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<unboundid.ldapsdk.version>4.0.4</unboundid.ldapsdk.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
- [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers)
|
- [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers)
|
||||||
- [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long)
|
- [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long)
|
||||||
|
- [Check for null Before Calling Parse in Double.parseDouble](https://www.baeldung.com/java-check-null-parse-double)
|
||||||
|
@ -12,7 +12,9 @@ import javax.batch.runtime.StepExecution;
|
|||||||
import com.baeldung.batch.understanding.BatchTestHelper;
|
import com.baeldung.batch.understanding.BatchTestHelper;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
|
||||||
|
@Disabled("Should be fixed in BAEL-3812")
|
||||||
class CustomCheckPointUnitTest {
|
class CustomCheckPointUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception {
|
public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception {
|
||||||
|
@ -13,7 +13,9 @@ import javax.batch.runtime.JobExecution;
|
|||||||
import javax.batch.runtime.StepExecution;
|
import javax.batch.runtime.StepExecution;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
|
||||||
|
@Disabled("Should be fixed in BAEL-3812")
|
||||||
class JobSequenceUnitTest {
|
class JobSequenceUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoSteps_thenBatch_CompleteWithSuccess() throws Exception {
|
public void givenTwoSteps_thenBatch_CompleteWithSuccess() throws Exception {
|
||||||
|
@ -14,7 +14,9 @@ import javax.batch.runtime.Metric;
|
|||||||
import javax.batch.runtime.StepExecution;
|
import javax.batch.runtime.StepExecution;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
|
||||||
|
@Disabled("Should be fixed in BAEL-3812")
|
||||||
class SimpleChunkUnitTest {
|
class SimpleChunkUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenChunk_thenBatch_CompletesWithSucess() throws Exception {
|
public void givenChunk_thenBatch_CompletesWithSucess() throws Exception {
|
||||||
|
@ -8,6 +8,12 @@
|
|||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>Bookstore</name>
|
<name>Bookstore</name>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>jhipster-5</artifactId>
|
||||||
|
<groupId>com.baeldung.jhipster</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<!-- jhipster-needle-maven-repository -->
|
<!-- jhipster-needle-maven-repository -->
|
||||||
</repositories>
|
</repositories>
|
||||||
|
@ -37,7 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
*
|
*
|
||||||
* @see WebConfigurer
|
* @see WebConfigurer
|
||||||
*/
|
*/
|
||||||
public class WebConfigurerTest {
|
public class WebConfigurerUnitTest {
|
||||||
|
|
||||||
private WebConfigurer webConfigurer;
|
private WebConfigurer webConfigurer;
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ public class WebConfigurerTest {
|
|||||||
props.getCors().setMaxAge(1800L);
|
props.getCors().setMaxAge(1800L);
|
||||||
props.getCors().setAllowCredentials(true);
|
props.getCors().setAllowCredentials(true);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController())
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController())
|
||||||
.addFilters(webConfigurer.corsFilter())
|
.addFilters(webConfigurer.corsFilter())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ public class WebConfigurerTest {
|
|||||||
props.getCors().setMaxAge(1800L);
|
props.getCors().setMaxAge(1800L);
|
||||||
props.getCors().setAllowCredentials(true);
|
props.getCors().setAllowCredentials(true);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController())
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController())
|
||||||
.addFilters(webConfigurer.corsFilter())
|
.addFilters(webConfigurer.corsFilter())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ public class WebConfigurerTest {
|
|||||||
public void testCorsFilterDeactivated() throws Exception {
|
public void testCorsFilterDeactivated() throws Exception {
|
||||||
props.getCors().setAllowedOrigins(null);
|
props.getCors().setAllowedOrigins(null);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController())
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController())
|
||||||
.addFilters(webConfigurer.corsFilter())
|
.addFilters(webConfigurer.corsFilter())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ public class WebConfigurerTest {
|
|||||||
public void testCorsFilterDeactivated2() throws Exception {
|
public void testCorsFilterDeactivated2() throws Exception {
|
||||||
props.getCors().setAllowedOrigins(new ArrayList<>());
|
props.getCors().setAllowedOrigins(new ArrayList<>());
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController())
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController())
|
||||||
.addFilters(webConfigurer.corsFilter())
|
.addFilters(webConfigurer.corsFilter())
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class WebConfigurerTestController {
|
public class WebConfigurerUnitTestController {
|
||||||
|
|
||||||
@GetMapping("/api/test-cors")
|
@GetMapping("/api/test-cors")
|
||||||
public void testCorsOnApiPath() {
|
public void testCorsOnApiPath() {
|
@ -33,7 +33,7 @@ import static com.baeldung.jhipster5.repository.CustomAuditEventRepository.EVENT
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class CustomAuditEventRepositoryIntTest {
|
public class CustomAuditEventRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PersistenceAuditEventRepository persistenceAuditEventRepository;
|
private PersistenceAuditEventRepository persistenceAuditEventRepository;
|
@ -28,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class DomainUserDetailsServiceIntTest {
|
public class DomainUserDetailsServiceIntegrationTest {
|
||||||
|
|
||||||
private static final String USER_ONE_LOGIN = "test-user-one";
|
private static final String USER_ONE_LOGIN = "test-user-one";
|
||||||
private static final String USER_ONE_EMAIL = "test-user-one@localhost";
|
private static final String USER_ONE_EMAIL = "test-user-one@localhost";
|
@ -20,7 +20,7 @@ import java.util.Collections;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class JWTFilterTest {
|
public class JWTFilterUnitTest {
|
||||||
|
|
||||||
private TokenProvider tokenProvider;
|
private TokenProvider tokenProvider;
|
||||||
|
|
@ -22,7 +22,7 @@ import io.jsonwebtoken.security.Keys;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TokenProviderTest {
|
public class TokenProviderUnitTest {
|
||||||
|
|
||||||
private final long ONE_MINUTE = 60000;
|
private final long ONE_MINUTE = 60000;
|
||||||
private Key key;
|
private Key key;
|
@ -31,7 +31,7 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
public class MailServiceIntTest {
|
public class MailServiceIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JHipsterProperties jHipsterProperties;
|
private JHipsterProperties jHipsterProperties;
|
@ -38,7 +38,7 @@ import static org.mockito.Mockito.when;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class UserServiceIntTest {
|
public class UserServiceIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
public class UserMapperTest {
|
public class UserMapperUnitTest {
|
||||||
|
|
||||||
private static final String DEFAULT_LOGIN = "johndoe";
|
private static final String DEFAULT_LOGIN = "johndoe";
|
||||||
|
|
@ -49,7 +49,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
public class AccountResourceIntTest {
|
public class AccountResourceIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
@ -35,7 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class AuditResourceIntTest {
|
public class AuditResourceIntegrationTest {
|
||||||
|
|
||||||
private static final String SAMPLE_PRINCIPAL = "SAMPLE_PRINCIPAL";
|
private static final String SAMPLE_PRINCIPAL = "SAMPLE_PRINCIPAL";
|
||||||
private static final String SAMPLE_TYPE = "SAMPLE_TYPE";
|
private static final String SAMPLE_TYPE = "SAMPLE_TYPE";
|
@ -43,7 +43,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
public class BookResourceIntTest {
|
public class BookResourceIntegrationTest {
|
||||||
|
|
||||||
private static final String DEFAULT_TITLE = "AAAAAAAAAA";
|
private static final String DEFAULT_TITLE = "AAAAAAAAAA";
|
||||||
private static final String UPDATED_TITLE = "BBBBBBBBBB";
|
private static final String UPDATED_TITLE = "BBBBBBBBBB";
|
@ -27,7 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
public class LogsResourceIntTest {
|
public class LogsResourceIntegrationTest {
|
||||||
|
|
||||||
private MockMvc restLogsMockMvc;
|
private MockMvc restLogsMockMvc;
|
||||||
|
|
@ -33,7 +33,7 @@ import static org.hamcrest.Matchers.not;
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
public class UserJWTControllerIntTest {
|
public class UserJWTControllerIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenProvider tokenProvider;
|
private TokenProvider tokenProvider;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user