This commit is contained in:
ajay74984 2020-03-24 17:58:54 +01:00
commit 9fe2ea2d71
488 changed files with 11596 additions and 1955 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -41,11 +41,6 @@
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>${guava.version}</version> <version>${guava.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.junit.platform</groupId> <groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId> <artifactId>junit-platform-commons</artifactId>
@ -78,7 +73,6 @@
<commons-codec.version>1.11</commons-codec.version> <commons-codec.version>1.11</commons-codec.version>
<commons-math3.version>3.6.1</commons-math3.version> <commons-math3.version>3.6.1</commons-math3.version>
<guava.version>28.1-jre</guava.version> <guava.version>28.1-jre</guava.version>
<jackson.version>2.10.2</jackson.version>
<junit.platform.version>1.6.0</junit.platform.version> <junit.platform.version>1.6.0</junit.platform.version>
</properties> </properties>

View File

@ -1,61 +0,0 @@
package com.baeldung.algorithms.boruvka;
public class BoruvkaMST {
private static Tree mst = new Tree();
private static int totalWeight;
public BoruvkaMST(Graph graph) {
DisjointSet dSet = new DisjointSet(graph.getNodes());
// repeat at most log N times or until we have N-1 edges
for (int t = 1; t < graph.getNodes() && mst.getEdgeCount() < graph.getNodes() - 1; t = t + t) {
// foreach tree in forest, find closest edge
Edge[] closestEdgeArray = new Edge[graph.getNodes()];
for (Edge edge : graph.getAllEdges()) {
int first = edge.getFirst();
int second = edge.getSecond();
int firstParent = dSet.getParent(first);
int secondParent = dSet.getParent(second);
if (firstParent == secondParent) {
continue; // same tree
}
if (closestEdgeArray[firstParent] == null || edge.getWeight() < closestEdgeArray[firstParent].getWeight()) {
closestEdgeArray[firstParent] = edge;
}
if (closestEdgeArray[secondParent] == null || edge.getWeight() < closestEdgeArray[secondParent].getWeight()) {
closestEdgeArray[secondParent] = edge;
}
}
// add newly discovered edges to MST
for (int i = 0; i < graph.getNodes(); i++) {
Edge edge = closestEdgeArray[i];
if (edge != null) {
int first = edge.getFirst();
int second = edge.getSecond();
// don't add the same edge twice
if (dSet.getParent(first) != dSet.getParent(second)) {
mst.addEdge(edge);
totalWeight += edge.getWeight();
dSet.union(first, second);
}
}
}
}
}
public Iterable<Edge> getMST() {
return mst;
}
public int getTotalWeight() {
return totalWeight;
}
public String toString() {
return "MST: " + mst.toString() + " | Total Weight: " + totalWeight;
}
}

View File

@ -1,49 +0,0 @@
package com.baeldung.algorithms.boruvka;
import java.util.Arrays;
public class DisjointSet {
private int[] nodeParents;
private int[] nodeRanks;
public DisjointSet(int n) {
nodeParents = new int[n];
nodeRanks = new int[n];
for (int i = 0; i < n; i++) {
nodeParents[i] = i;
nodeRanks[i] = 0;
}
}
public int getParent(int node) {
while (node != nodeParents[node]) {
node = nodeParents[node];
}
return node;
}
public void union(int node1, int node2) {
int node1Parent = getParent(node1);
int node2Parent = getParent(node2);
if (node1Parent == node2Parent) {
return;
}
if (nodeRanks[node1Parent] < nodeRanks[node2Parent]) {
nodeParents[node1Parent] = node2Parent;
}
else if (nodeRanks[node1Parent] > nodeRanks[node2Parent]) {
nodeParents[node2Parent] = node1Parent;
}
else {
nodeParents[node2Parent] = node1Parent;
nodeRanks[node1Parent]++;
}
}
public String toString() {
return "Parent: " + Arrays.toString(nodeParents) + "Rank: " + Arrays.toString(nodeRanks);
}
}

View File

@ -1,40 +0,0 @@
package com.baeldung.algorithms.boruvka;
public class Edge {
private final int first;
private final int second;
private final int weight;
public Edge(int first, int second, int weight) {
this.first = first;
this.second = second;
this.weight = weight;
}
public double getWeight() {
return weight;
}
public int getFirst() {
return first;
}
public int getSecond() {
return second;
}
public int getOtherNode(int firstNode) {
int secondNode = 0;
if (firstNode == first)
secondNode = second;
else if (firstNode == second)
secondNode = first;
return secondNode;
}
public String toString() {
return String.format("%d-%d %d", first, second, weight);
}
}

View File

@ -1,64 +0,0 @@
package com.baeldung.algorithms.boruvka;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
public class Graph {
private int nodes;
private int edges;
private Tree[] trees;
public Graph(Input jsonGraph) throws JsonParseException, JsonMappingException, IOException {
nodes = jsonGraph.getNodes();
trees = (Tree[]) new Tree[nodes];
for (int i = 0; i < nodes; i++) {
trees[i] = new Tree();
}
int edgesFromInput = jsonGraph.getEdges();
for (int i = 0; i < edgesFromInput; i++) {
int first = jsonGraph.getEdgeList()
.get(i)
.getFirst();
int second = jsonGraph.getEdgeList()
.get(i)
.getSecond();
int weight = jsonGraph.getEdgeList()
.get(i)
.getWeight();
Edge edge = new Edge(first, second, weight);
trees[first].addEdge(edge);
trees[second].addEdge(edge);
edges++;
}
}
public int getNodes() {
return nodes;
}
public int getEdges() {
return edges;
}
public Iterable<Edge> iterableTree(int i) {
return trees[i];
}
public Iterable<Edge> getAllEdges() {
Iterable<Edge> list = new Tree();
for (int i = 0; i < nodes; i++) {
for (Edge edge : iterableTree(i)) {
if (edge.getOtherNode(i) > i) {
((Tree) list).addEdge(edge);
}
}
}
return list;
}
}

View File

@ -1,65 +0,0 @@
package com.baeldung.algorithms.boruvka;
import java.util.List;
public class Input {
private int nodes;
private int edges;
private List<E> edgeList;
public int getNodes() {
return nodes;
}
public void setNodes(int nodes) {
this.nodes = nodes;
}
public int getEdges() {
return edges;
}
public void setEdges(int edges) {
this.edges = edges;
}
public List<E> getEdgeList() {
return edgeList;
}
public void setEdgeList(List<E> edgeList) {
this.edgeList = edgeList;
}
static class E {
private int first;
private int second;
private int weight;
public int getFirst() {
return first;
}
public void setFirst(int first) {
this.first = first;
}
public int getSecond() {
return second;
}
public void setSecond(int second) {
this.second = second;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
}
}

View File

@ -1,63 +0,0 @@
package com.baeldung.algorithms.boruvka;
import java.util.Iterator;
public class Tree implements Iterable<Edge> {
private Node root;
private int edgeCount;
private static class Node {
private Edge edge;
private Node next;
public String toString() {
String nextStr = next != null ? next.toString() : "";
return edge.toString() + " | " + nextStr;
}
}
public Tree() {
root = null;
edgeCount = 0;
}
public int getEdgeCount() {
return edgeCount;
}
public void addEdge(Edge edge) {
Node oldRoot = root;
root = new Node();
root.edge = edge;
root.next = oldRoot;
edgeCount++;
}
public String toString() {
String rootStr = root != null ? root.toString() : "";
return "Tree: " + rootStr + "Size: " + edgeCount;
}
public Iterator<Edge> iterator() {
return new LinkedIterator(root);
}
private class LinkedIterator implements Iterator<Edge> {
private Node current;
public LinkedIterator(Node root) {
current = root;
}
public boolean hasNext() {
return current != null;
}
public Edge next() {
Edge edge = current.edge;
current = current.next;
return edge;
}
}
}

View File

@ -1,48 +0,0 @@
package com.baeldung.algorithms.boruvka;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class BoruvkaUnitTest {
private Input input;
private static String INPUT_JSON = "/input.json";
@Before
public void convertInputJsonToObject() throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
StringBuilder jsonStr = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(BoruvkaMST.class.getResourceAsStream(INPUT_JSON)))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
jsonStr.append(line)
.append("\n");
}
}
input = mapper.readValue(jsonStr.toString(), Input.class);
}
@Test
public void givenInputGraph_whenBoruvkaPerformed_thenMinimumSpanningTree() throws JsonParseException, JsonMappingException, IOException {
Graph graph = new Graph(input);
BoruvkaMST boruvkaMST = new BoruvkaMST(graph);
Tree mst = (Tree) boruvkaMST.getMST();
assertEquals(30, boruvkaMST.getTotalWeight());
assertEquals(4, mst.getEdgeCount());
}
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>algorithms-miscellaneous-6</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>algorithms-miscellaneous-6</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<guava.version>28.1-jre</guava.version>
</properties>
</project>

View File

@ -0,0 +1,84 @@
package com.baeldung.algorithms.boruvka;
import com.google.common.graph.EndpointPair;
import com.google.common.graph.MutableValueGraph;
import com.google.common.graph.ValueGraphBuilder;
public class BoruvkaMST {
private static MutableValueGraph<Integer, Integer> mst = ValueGraphBuilder.undirected()
.build();
private static int totalWeight;
public BoruvkaMST(MutableValueGraph<Integer, Integer> graph) {
int size = graph.nodes().size();
UnionFind uf = new UnionFind(size);
// repeat at most log N times or until we have N-1 edges
for (int t = 1; t < size && mst.edges().size() < size - 1; t = t + t) {
EndpointPair<Integer>[] closestEdgeArray = new EndpointPair[size];
// foreach tree in graph, find closest edge
for (EndpointPair<Integer> edge : graph.edges()) {
int u = edge.nodeU();
int v = edge.nodeV();
int uParent = uf.find(u);
int vParent = uf.find(v);
if (uParent == vParent) {
continue; // same tree
}
int weight = graph.edgeValueOrDefault(u, v, 0);
if (closestEdgeArray[uParent] == null) {
closestEdgeArray[uParent] = edge;
}
if (closestEdgeArray[vParent] == null) {
closestEdgeArray[vParent] = edge;
}
int uParentWeight = graph.edgeValueOrDefault(closestEdgeArray[uParent].nodeU(), closestEdgeArray[uParent].nodeV(), 0);
int vParentWeight = graph.edgeValueOrDefault(closestEdgeArray[vParent].nodeU(), closestEdgeArray[vParent].nodeV(), 0);
if (weight < uParentWeight) {
closestEdgeArray[uParent] = edge;
}
if (weight < vParentWeight) {
closestEdgeArray[vParent] = edge;
}
}
// add newly discovered edges to MST
for (int i = 0; i < size; i++) {
EndpointPair<Integer> edge = closestEdgeArray[i];
if (edge != null) {
int u = edge.nodeU();
int v = edge.nodeV();
int weight = graph.edgeValueOrDefault(u, v, 0);
// don't add the same edge twice
if (uf.find(u) != uf.find(v)) {
mst.putEdgeValue(u, v, weight);
totalWeight += weight;
uf.union(u, v);
}
}
}
}
}
public MutableValueGraph<Integer, Integer> getMST() {
return mst;
}
public int getTotalWeight() {
return totalWeight;
}
public String toString() {
return "MST: " + mst.toString() + " | Total Weight: " + totalWeight;
}
}

View File

@ -0,0 +1,39 @@
package com.baeldung.algorithms.boruvka;
public class UnionFind {
private int[] parents;
private int[] ranks;
public UnionFind(int n) {
parents = new int[n];
ranks = new int[n];
for (int i = 0; i < n; i++) {
parents[i] = i;
ranks[i] = 0;
}
}
public int find(int u) {
while (u != parents[u]) {
u = parents[u];
}
return u;
}
public void union(int u, int v) {
int uParent = find(u);
int vParent = find(v);
if (uParent == vParent) {
return;
}
if (ranks[uParent] < ranks[vParent]) {
parents[uParent] = vParent;
} else if (ranks[uParent] > ranks[vParent]) {
parents[vParent] = uParent;
} else {
parents[vParent] = uParent;
ranks[uParent]++;
}
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.algorithms.gradientdescent;
import java.util.function.Function;
public class GradientDescent {
private final double precision = 0.000001;
public double findLocalMinimum(Function<Double, Double> f, double initialX) {
double stepCoefficient = 0.1;
double previousStep = 1.0;
double currentX = initialX;
double previousX = initialX;
double previousY = f.apply(previousX);
int iter = 100;
currentX += stepCoefficient * previousY;
while (previousStep > precision && iter > 0) {
iter--;
double currentY = f.apply(currentX);
if (currentY > previousY) {
stepCoefficient = -stepCoefficient / 2;
}
previousX = currentX;
currentX += stepCoefficient * previousY;
previousY = currentY;
previousStep = StrictMath.abs(currentX - previousX);
}
return currentX;
}
}

View File

@ -0,0 +1,37 @@
package com.baeldung.algorithms.boruvka;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Before;
import org.junit.Test;
import com.google.common.graph.MutableValueGraph;
import com.google.common.graph.ValueGraphBuilder;
public class BoruvkaUnitTest {
private MutableValueGraph<Integer, Integer> graph;
@Before
public void setup() {
graph = ValueGraphBuilder.undirected()
.build();
graph.putEdgeValue(0, 1, 8);
graph.putEdgeValue(0, 2, 5);
graph.putEdgeValue(1, 2, 9);
graph.putEdgeValue(1, 3, 11);
graph.putEdgeValue(2, 3, 15);
graph.putEdgeValue(2, 4, 10);
graph.putEdgeValue(3, 4, 7);
}
@Test
public void givenInputGraph_whenBoruvkaPerformed_thenMinimumSpanningTree() {
BoruvkaMST boruvkaMST = new BoruvkaMST(graph);
MutableValueGraph<Integer, Integer> mst = boruvkaMST.getMST();
assertEquals(30, boruvkaMST.getTotalWeight());
assertEquals(4, mst.edges().size());
}
}

View File

@ -0,0 +1,20 @@
package com.baeldung.algorithms.gradientdescent;
import static org.junit.Assert.assertTrue;
import java.util.function.Function;
import org.junit.Test;
public class GradientDescentUnitTest {
@Test
public void givenFunction_whenStartingPointIsOne_thenLocalMinimumIsFound() {
Function<Double, Double> df = x ->
StrictMath.abs(StrictMath.pow(x, 3)) - (3 * StrictMath.pow(x, 2)) + x;
GradientDescent gd = new GradientDescent();
double res = gd.findLocalMinimum(df, 1);
assertTrue(res > 1.78);
assertTrue(res < 1.84);
}
}

View File

@ -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>

View File

@ -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());
}
}

View File

@ -1,14 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.concurrent.lock</groupId> <groupId>com.baeldung.concurrent.lock</groupId>
<artifactId>core-java-concurrency-collections-2</artifactId> <artifactId>core-java-concurrency-collections-2</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<properties>
<jmh.version>1.21</jmh.version>
<guava.version>28.2-jre</guava.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
@ -40,4 +38,10 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<properties>
<jmh.version>1.21</jmh.version>
<guava.version>28.2-jre</guava.version>
</properties>
</project> </project>

View File

@ -0,0 +1,35 @@
package com.baeldung.datetime.dayofweek;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class DayOfWeekExtractor {
public static int getDayNumberOld(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_WEEK);
}
public static String getDayStringOld(Date date, Locale locale ) {
DateFormat formatter = new SimpleDateFormat("EEEE", locale);
return formatter.format(date);
}
public static int getDayNumberNew(LocalDate date) {
DayOfWeek day = date.getDayOfWeek();
return day.getValue();
}
public static String getDayStringNew(LocalDate date, Locale locale ) {
DayOfWeek day = date.getDayOfWeek();
return day.getDisplayName(TextStyle.FULL, locale);
}
}

View File

@ -0,0 +1,52 @@
package com.baeldung.datetime.dayofweek;
import static org.assertj.core.api.Assertions.assertThat;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Locale;
import org.junit.Test;
public class DayOfWeekExtractorUnitTest {
private DateFormat oldDateParser = new SimpleDateFormat("yyyy-MM-dd");
@Test
public void givenFeb29_2020_thenOldSaturdayNumber() throws ParseException {
assertThat(DayOfWeekExtractor.getDayNumberOld(oldDateParser.parse("2020-02-29")) == Calendar.SATURDAY);
}
@Test
public void givenFeb29_2020_and_localeUS_thenOldSaturdayText() throws ParseException {
assertThat("Saturday".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.US)) );
}
@Test
public void givenFeb29_2020_and_localeDE_thenOldSaturdayText() throws ParseException {
assertThat("Samstag".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.GERMANY)) );
}
@Test
public void givenFeb29_2020_thenNewSaturdayNumber() throws ParseException {
assertThat(DayOfWeekExtractor.getDayNumberNew(LocalDate.parse("2020-02-29")) == Calendar.SATURDAY);
}
@Test
public void givenFeb29_2020_and_localeUS_thenNewSaturdayText() throws ParseException {
assertThat("Saturday".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.US)) );
}
@Test
public void givenFeb29_2020_and_localeDE_thenNewSaturdayText() throws ParseException {
assertThat("Samstag".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.GERMANY)) );
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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)

View File

@ -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>

View File

@ -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
}
}

View File

@ -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
}

View File

@ -1,6 +0,0 @@
package com.baeldung.scala
object HelloWorld extends App {
println("Hello World!")
args foreach println
}

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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"
}
}
}

View File

@ -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)
}
}

View File

@ -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))
}
}

View File

@ -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)
}
}

View File

@ -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))
}
}

View File

@ -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))
}
}

View File

@ -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)
}
}

View File

@ -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))
}
}

View File

@ -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))
}
}

View File

@ -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)
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -1,4 +1,4 @@
organization in ThisBuild := "org.baeldung" organization in ThisBuild := "com.baeldung"
// the Scala version that will be used for cross-compiled libraries // the Scala version that will be used for cross-compiled libraries
scalaVersion in ThisBuild := "2.11.8" scalaVersion in ThisBuild := "2.11.8"

View File

@ -1,4 +1,4 @@
package org.baeldung.lagom.helloworld.greeting.api; package com.baeldung.lagom.helloworld.greeting.api;
import static com.lightbend.lagom.javadsl.api.Service.named; import static com.lightbend.lagom.javadsl.api.Service.named;
import static com.lightbend.lagom.javadsl.api.Service.restCall; import static com.lightbend.lagom.javadsl.api.Service.restCall;

View File

@ -1,4 +1,4 @@
package org.baeldung.lagom.helloworld.greeting.impl; package com.baeldung.lagom.helloworld.greeting.impl;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

View File

@ -1,9 +1,9 @@
package org.baeldung.lagom.helloworld.greeting.impl; package com.baeldung.lagom.helloworld.greeting.impl;
import java.util.Optional; import java.util.Optional;
import org.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand; import com.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand;
import org.baeldung.lagom.helloworld.greeting.impl.GreetingEvent.ReceivedGreetingEvent; import com.baeldung.lagom.helloworld.greeting.impl.GreetingEvent.ReceivedGreetingEvent;
import com.lightbend.lagom.javadsl.persistence.PersistentEntity; import com.lightbend.lagom.javadsl.persistence.PersistentEntity;

View File

@ -1,4 +1,4 @@
package org.baeldung.lagom.helloworld.greeting.impl; package com.baeldung.lagom.helloworld.greeting.impl;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.lightbend.lagom.serialization.Jsonable; import com.lightbend.lagom.serialization.Jsonable;

View File

@ -1,12 +1,12 @@
package org.baeldung.lagom.helloworld.greeting.impl; package com.baeldung.lagom.helloworld.greeting.impl;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.baeldung.lagom.helloworld.greeting.api.GreetingService; import com.baeldung.lagom.helloworld.greeting.api.GreetingService;
import org.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand; import com.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand;
import org.baeldung.lagom.helloworld.weather.api.WeatherService; import com.baeldung.lagom.helloworld.weather.api.WeatherService;
import org.baeldung.lagom.helloworld.weather.api.WeatherStats; import com.baeldung.lagom.helloworld.weather.api.WeatherStats;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.lightbend.lagom.javadsl.api.ServiceCall; import com.lightbend.lagom.javadsl.api.ServiceCall;

View File

@ -1,7 +1,7 @@
package org.baeldung.lagom.helloworld.greeting.impl; package com.baeldung.lagom.helloworld.greeting.impl;
import org.baeldung.lagom.helloworld.greeting.api.GreetingService; import com.baeldung.lagom.helloworld.greeting.api.GreetingService;
import org.baeldung.lagom.helloworld.weather.api.WeatherService; import com.baeldung.lagom.helloworld.weather.api.WeatherService;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport; import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport;

View File

@ -1,4 +1,4 @@
package org.baeldung.lagom.helloworld.greeting.impl; package com.baeldung.lagom.helloworld.greeting.impl;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

View File

@ -1 +1 @@
play.modules.enabled += org.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule play.modules.enabled += com.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule

View File

@ -1 +1 @@
play.modules.enabled += org.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule play.modules.enabled += com.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule

View File

@ -1 +1 @@
play.modules.enabled += org.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule play.modules.enabled += com.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule

View File

@ -1,4 +1,4 @@
package org.baeldung.lagom.helloworld.weather.api; package com.baeldung.lagom.helloworld.weather.api;
import static com.lightbend.lagom.javadsl.api.Service.named; import static com.lightbend.lagom.javadsl.api.Service.named;
import static com.lightbend.lagom.javadsl.api.Service.*; import static com.lightbend.lagom.javadsl.api.Service.*;

View File

@ -1,4 +1,4 @@
package org.baeldung.lagom.helloworld.weather.api; package com.baeldung.lagom.helloworld.weather.api;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;

View File

@ -1 +1 @@
play.modules.enabled += org.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule play.modules.enabled += com.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule

View File

@ -1,9 +1,9 @@
package org.baeldung.lagom.helloworld.weather.impl; package com.baeldung.lagom.helloworld.weather.impl;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import org.baeldung.lagom.helloworld.weather.api.WeatherService; import com.baeldung.lagom.helloworld.weather.api.WeatherService;
import org.baeldung.lagom.helloworld.weather.api.WeatherStats; import com.baeldung.lagom.helloworld.weather.api.WeatherStats;
import com.lightbend.lagom.javadsl.api.ServiceCall; import com.lightbend.lagom.javadsl.api.ServiceCall;

View File

@ -1,6 +1,6 @@
package org.baeldung.lagom.helloworld.weather.impl; package com.baeldung.lagom.helloworld.weather.impl;
import org.baeldung.lagom.helloworld.weather.api.WeatherService; import com.baeldung.lagom.helloworld.weather.api.WeatherService;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport; import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport;

View File

@ -1 +1 @@
play.modules.enabled += org.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule play.modules.enabled += com.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule

View File

@ -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>machine-learning</artifactId> <artifactId>machine-learning</artifactId>
@ -13,23 +15,6 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<kotlin.version>1.3.50</kotlin.version>
<dl4j.version>0.9.1</dl4j.version>
<clean.plugin.version>3.1.0</clean.plugin.version>
<resources.plugin.version>3.0.2</resources.plugin.version>
<jar.plugin.version>3.0.2</jar.plugin.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version>
<surefire.plugin.version>2.22.1</surefire.plugin.version>
<install.plugin.version>2.5.2</install.plugin.version>
<deploy.plugin.version>2.8.2</deploy.plugin.version>
<site.plugin.version>3.7.1</site.plugin.version>
<report.plugin.version>3.0.0</report.plugin.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
@ -158,4 +143,21 @@
</plugins> </plugins>
</build> </build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<kotlin.version>1.3.50</kotlin.version>
<dl4j.version>0.9.1</dl4j.version>
<clean.plugin.version>3.1.0</clean.plugin.version>
<resources.plugin.version>3.0.2</resources.plugin.version>
<jar.plugin.version>3.0.2</jar.plugin.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version>
<surefire.plugin.version>2.22.1</surefire.plugin.version>
<install.plugin.version>2.5.2</install.plugin.version>
<deploy.plugin.version>2.8.2</deploy.plugin.version>
<site.plugin.version>3.7.1</site.plugin.version>
<report.plugin.version>3.0.0</report.plugin.version>
</properties>
</project> </project>

View File

@ -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>
@ -8,11 +9,6 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<properties>
<commons.lang3.version>3.9</commons.lang3.version>
<junit.version>4.12</junit.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
@ -47,4 +43,9 @@
</plugins> </plugins>
</build> </build>
<properties>
<commons.lang3.version>3.9</commons.lang3.version>
<junit.version>4.12</junit.version>
</properties>
</project> </project>

View File

@ -1,4 +1,6 @@
<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>${groupId}</groupId> <groupId>${groupId}</groupId>
@ -6,18 +8,6 @@
<version>${version}</version> <version>${version}</version>
<packaging>war</packaging> <packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<liberty-maven-plugin.version>${liberty-plugin-version}</liberty-maven-plugin.version>
<defaultHttpPort>9080</defaultHttpPort>
<defaultHttpsPort>9443</defaultHttpsPort>
<cdi.api.version>2.0</cdi.api.version>
<rsapi.api.version>2.1</rsapi.api.version>
</properties>
<build> <build>
<finalName>${artifactId}</finalName> <finalName>${artifactId}</finalName>
<plugins> <plugins>
@ -80,4 +70,16 @@
</dependencies> </dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<liberty-maven-plugin.version>${liberty-plugin-version}</liberty-maven-plugin.version>
<defaultHttpPort>9080</defaultHttpPort>
<defaultHttpsPort>9443</defaultHttpsPort>
<cdi.api.version>2.0</cdi.api.version>
<rsapi.api.version>2.1</rsapi.api.version>
</properties>
</project> </project>

View File

@ -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.userdaomodule</groupId> <groupId>com.baeldung.userdaomodule</groupId>
@ -14,11 +16,6 @@
<version>1.0</version> <version>1.0</version>
</parent> </parent>
<properties>
<entitymodule.version>1.0</entitymodule.version>
<daomodule.version>1.0</daomodule.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.baeldung.entitymodule</groupId> <groupId>com.baeldung.entitymodule</groupId>
@ -37,4 +34,9 @@
</dependency> </dependency>
</dependencies> </dependencies>
<properties>
<entitymodule.version>1.0</entitymodule.version>
<daomodule.version>1.0</daomodule.version>
</properties>
</project> </project>

View File

@ -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/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>
@ -10,19 +12,34 @@
<url>http://www.ninjaframework.org</url> <url>http://www.ninjaframework.org</url>
<properties> <dependencies>
<ninja.version>6.5.0</ninja.version> <dependency>
<jetty.version>9.4.18.v20190429</jetty.version> <groupId>org.webjars</groupId>
<bootstrap.version>3.3.4</bootstrap.version> <artifactId>bootstrap</artifactId>
<jquery.version>2.1.3</jquery.version> <version>${bootstrap.version}</version>
<h2.version>1.4.186</h2.version> </dependency>
<compiler.plugin.version>3.2</compiler.plugin.version> <dependency>
<source.version>1.8</source.version> <groupId>org.webjars</groupId>
<target.version>1.8</target.version> <artifactId>jquery</artifactId>
<enforcer.plugin.version>1.3.1</enforcer.plugin.version> <version>${jquery.version}</version>
<deploy.plugin.version>2.8.2</deploy.plugin.version> </dependency>
<shade.plugin.version>2.2</shade.plugin.version> <dependency>
</properties> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-standalone</artifactId>
<version>${ninja.version}</version>
</dependency>
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-test-utilities</artifactId>
<version>${ninja.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
@ -131,10 +148,8 @@
</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>ninja.standalone.NinjaJetty</mainClass> <mainClass>ninja.standalone.NinjaJetty</mainClass>
</transformer> </transformer>
</transformers> </transformers>
@ -161,32 +176,19 @@
</resource> </resource>
</resources> </resources>
</build> </build>
<dependencies>
<dependency> <properties>
<groupId>org.webjars</groupId> <ninja.version>6.5.0</ninja.version>
<artifactId>bootstrap</artifactId> <jetty.version>9.4.18.v20190429</jetty.version>
<version>${bootstrap.version}</version> <bootstrap.version>3.3.4</bootstrap.version>
</dependency> <jquery.version>2.1.3</jquery.version>
<dependency> <h2.version>1.4.186</h2.version>
<groupId>org.webjars</groupId> <compiler.plugin.version>3.2</compiler.plugin.version>
<artifactId>jquery</artifactId> <source.version>1.8</source.version>
<version>${jquery.version}</version> <target.version>1.8</target.version>
</dependency> <enforcer.plugin.version>1.3.1</enforcer.plugin.version>
<dependency> <deploy.plugin.version>2.8.2</deploy.plugin.version>
<groupId>com.h2database</groupId> <shade.plugin.version>2.2</shade.plugin.version>
<artifactId>h2</artifactId> </properties>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-standalone</artifactId>
<version>${ninja.version}</version>
</dependency>
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-test-utilities</artifactId>
<version>${ninja.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project> </project>

View File

@ -13,12 +13,6 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.pdfbox</groupId> <groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-tools</artifactId> <artifactId>pdfbox-tools</artifactId>
@ -86,7 +80,6 @@
<poi-scratchpad.version>3.15</poi-scratchpad.version> <poi-scratchpad.version>3.15</poi-scratchpad.version>
<batik-transcoder.version>1.8</batik-transcoder.version> <batik-transcoder.version>1.8</batik-transcoder.version>
<poi-ooxml.version>3.15</poi-ooxml.version> <poi-ooxml.version>3.15</poi-ooxml.version>
<commons-codec.version>1.14</commons-codec.version>
</properties> </properties>
</project> </project>

View File

@ -0,0 +1,10 @@
## Hibernate Annotations
This module contains articles about Hibernate Annotations.
### Relevant Articles:
- [Custom Types in Hibernate and the @Type Annotation](https://www.baeldung.com/hibernate-custom-types)
- [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column)
- [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby)
- [Hibernate One to Many Annotation Tutorial](http://www.baeldung.com/hibernate-one-to-many)
- [Hibernate @WhereJoinTable Annotation](https://www.baeldung.com/hibernate-wherejointable)

View File

@ -2,9 +2,9 @@
<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>hibernate5-2</artifactId> <artifactId>hibernate-annotations</artifactId>
<version>0.1-SNAPSHOT</version> <version>0.1-SNAPSHOT</version>
<name>hibernate5-2</name> <name>hibernate-annotations</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Hibernate tutorial illustrating the use of named parameters</description> <description>Hibernate tutorial illustrating the use of named parameters</description>
@ -20,32 +20,6 @@
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
<version>${hibernate-core.version}</version> <version>${hibernate-core.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
@ -58,8 +32,33 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version> <version>${commons.lang3.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-testing</artifactId>
<version>${hibernate-core.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>${hibernate-core.version}</version>
</dependency>
<dependency>
<groupId>org.opengeo</groupId>
<artifactId>geodb</artifactId>
<version>${geodb.version}</version>
</dependency>
</dependencies> </dependencies>
<repositories>
<repository>
<id>geodb-repo</id>
<name>GeoDB repository</name>
<url>http://repo.boundlessgeo.com/main/</url>
</repository>
</repositories>
<properties> <properties>
<hibernate-core.version>5.4.7.Final</hibernate-core.version> <hibernate-core.version>5.4.7.Final</hibernate-core.version>
<h2.version>1.4.200</h2.version> <h2.version>1.4.200</h2.version>
@ -69,6 +68,7 @@
<hibernate.core.version>5.4.7.Final</hibernate.core.version> <hibernate.core.version>5.4.7.Final</hibernate.core.version>
<h2.version>1.4.200</h2.version> <h2.version>1.4.200</h2.version>
<commons.lang3.version>3.8.1</commons.lang3.version> <commons.lang3.version>3.8.1</commons.lang3.version>
<geodb.version>0.9</geodb.version>
</properties> </properties>
</project> </project>

View File

@ -0,0 +1,73 @@
package com.baeldung.hibernate;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
import com.baeldung.hibernate.joincolumn.Email;
import com.baeldung.hibernate.joincolumn.Office;
import com.baeldung.hibernate.joincolumn.OfficeAddress;
public class HibernateUtil {
private static String PROPERTY_FILE_NAME;
public static SessionFactory getSessionFactory() throws IOException {
return getSessionFactory(null);
}
public static SessionFactory getSessionFactory(String propertyFileName) throws IOException {
PROPERTY_FILE_NAME = propertyFileName;
ServiceRegistry serviceRegistry = configureServiceRegistry();
return makeSessionFactory(serviceRegistry);
}
public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException {
ServiceRegistry serviceRegistry = configureServiceRegistry(properties);
return makeSessionFactory(serviceRegistry);
}
private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) {
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
metadataSources.addPackage("com.baeldung.hibernate.pojo");
metadataSources.addAnnotatedClass(com.baeldung.hibernate.joincolumn.OfficialEmployee.class);
metadataSources.addAnnotatedClass(Email.class);
metadataSources.addAnnotatedClass(Office.class);
metadataSources.addAnnotatedClass(OfficeAddress.class);
Metadata metadata = metadataSources.getMetadataBuilder()
.build();
return metadata.getSessionFactoryBuilder()
.build();
}
private static ServiceRegistry configureServiceRegistry() throws IOException {
return configureServiceRegistry(getProperties());
}
private static ServiceRegistry configureServiceRegistry(Properties properties) throws IOException {
return new StandardServiceRegistryBuilder().applySettings(properties)
.build();
}
public static Properties getProperties() throws IOException {
Properties properties = new Properties();
URL propertiesURL = Thread.currentThread()
.getContextClassLoader()
.getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties"));
try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) {
properties.load(inputStream);
}
return properties;
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.hibernate;
public class UnsupportedTenancyException extends Exception {
public UnsupportedTenancyException (String message) {
super(message);
}
}

Some files were not shown because too many files have changed in this diff Show More