Skip to content

Commit 130d087

Browse files
committed
Merge branch 'eugenmaster'
2 parents fa83a46 + 44fb994 commit 130d087

File tree

575 files changed

+18744
-3210
lines changed

Some content is hidden

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

575 files changed

+18744
-3210
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ In additional to Spring, the following technologies are in focus: `core Java`, `
2020

2121
Building the project
2222
====================
23-
To do the full build, do: `mvn install -Pdefault -Dgib.enabled=false`
23+
To do the full build, do: `mvn clean install`
2424

2525

2626
Building a single module
2727
====================
28-
To build a specific module run the command: `mvn clean install -Dgib.enabled=false` in the module directory
28+
To build a specific module run the command: `mvn clean install` in the module directory
2929

3030

3131
Running a Spring Boot module
3232
====================
33-
To run a Spring Boot module run the command: `mvn spring-boot:run -Dgib.enabled=false` in the module directory
33+
To run a Spring Boot module run the command: `mvn spring-boot:run` in the module directory
34+
35+
#Running Tests
36+
37+
The command `mvn clean install` will run the unit tests in a module.
38+
To run the integration tests, use the command `mvn clean install -Pintegration-lite-first`
3439

3540

3641

algorithms-miscellaneous-2/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
1616
- [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings)
1717
- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
18+
- [Reversing a Binary Tree in Java](https://www.baeldung.com/java-reversing-a-binary-tree)
19+
- [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers)

algorithms-miscellaneous-3/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
- [Implementing Simple State Machines with Java Enums](https://www.baeldung.com/java-enum-simple-state-machine)
55
- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic)
66
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
7-
- [An Introduction to the Theory of Big-O Notation](http://www.baeldung.com/big-o-notation)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.baeldung.algorithms.graphcycledetection.domain;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Graph {
7+
8+
private List<Vertex> vertices;
9+
10+
public Graph() {
11+
this.vertices = new ArrayList<>();
12+
}
13+
14+
public Graph(List<Vertex> vertices) {
15+
this.vertices = vertices;
16+
}
17+
18+
public void addVertex(Vertex vertex) {
19+
this.vertices.add(vertex);
20+
}
21+
22+
public void addEdge(Vertex from, Vertex to) {
23+
from.addNeighbour(to);
24+
}
25+
26+
public boolean hasCycle() {
27+
for (Vertex vertex : vertices) {
28+
if (!vertex.isVisited() && hasCycle(vertex)) {
29+
return true;
30+
}
31+
}
32+
return false;
33+
}
34+
35+
public boolean hasCycle(Vertex sourceVertex) {
36+
sourceVertex.setBeingVisited(true);
37+
38+
for (Vertex neighbour : sourceVertex.getAdjacencyList()) {
39+
if (neighbour.isBeingVisited()) {
40+
// backward edge exists
41+
return true;
42+
} else if (!neighbour.isVisited() && hasCycle(neighbour)) {
43+
return true;
44+
}
45+
}
46+
47+
sourceVertex.setBeingVisited(false);
48+
sourceVertex.setVisited(true);
49+
return false;
50+
}
51+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.baeldung.algorithms.graphcycledetection.domain;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Vertex {
7+
8+
private String label;
9+
10+
private boolean visited;
11+
12+
private boolean beingVisited;
13+
14+
private List<Vertex> adjacencyList;
15+
16+
public Vertex(String label) {
17+
this.label = label;
18+
this.adjacencyList = new ArrayList<>();
19+
}
20+
21+
public String getLabel() {
22+
return label;
23+
}
24+
25+
public void setLabel(String label) {
26+
this.label = label;
27+
}
28+
29+
public boolean isVisited() {
30+
return visited;
31+
}
32+
33+
public void setVisited(boolean visited) {
34+
this.visited = visited;
35+
}
36+
37+
public boolean isBeingVisited() {
38+
return beingVisited;
39+
}
40+
41+
public void setBeingVisited(boolean beingVisited) {
42+
this.beingVisited = beingVisited;
43+
}
44+
45+
public List<Vertex> getAdjacencyList() {
46+
return adjacencyList;
47+
}
48+
49+
public void setAdjacencyList(List<Vertex> adjacencyList) {
50+
this.adjacencyList = adjacencyList;
51+
}
52+
53+
public void addNeighbour(Vertex adjacent) {
54+
this.adjacencyList.add(adjacent);
55+
}
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.baeldung.algorithms.graphcycledetection;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
8+
import com.baeldung.algorithms.graphcycledetection.domain.Graph;
9+
import com.baeldung.algorithms.graphcycledetection.domain.Vertex;
10+
11+
public class GraphCycleDetectionUnitTest {
12+
13+
@Test
14+
public void givenGraph_whenCycleExists_thenReturnTrue() {
15+
16+
Vertex vertexA = new Vertex("A");
17+
Vertex vertexB = new Vertex("B");
18+
Vertex vertexC = new Vertex("C");
19+
Vertex vertexD = new Vertex("D");
20+
21+
Graph graph = new Graph();
22+
graph.addVertex(vertexA);
23+
graph.addVertex(vertexB);
24+
graph.addVertex(vertexC);
25+
graph.addVertex(vertexD);
26+
27+
graph.addEdge(vertexA, vertexB);
28+
graph.addEdge(vertexB, vertexC);
29+
graph.addEdge(vertexC, vertexA);
30+
graph.addEdge(vertexD, vertexC);
31+
32+
assertTrue(graph.hasCycle());
33+
}
34+
35+
@Test
36+
public void givenGraph_whenNoCycleExists_thenReturnFalse() {
37+
38+
Vertex vertexA = new Vertex("A");
39+
Vertex vertexB = new Vertex("B");
40+
Vertex vertexC = new Vertex("C");
41+
Vertex vertexD = new Vertex("D");
42+
43+
Graph graph = new Graph();
44+
graph.addVertex(vertexA);
45+
graph.addVertex(vertexB);
46+
graph.addVertex(vertexC);
47+
graph.addVertex(vertexD);
48+
49+
graph.addEdge(vertexA, vertexB);
50+
graph.addEdge(vertexB, vertexC);
51+
graph.addEdge(vertexA, vertexC);
52+
graph.addEdge(vertexD, vertexC);
53+
54+
assertFalse(graph.hasCycle());
55+
}
56+
}

apache-geode/src/test/java/com/baeldung/geode/GeodeSamplesIntegrationTest.java renamed to apache-geode/src/test/java/com/baeldung/geode/GeodeSamplesLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import static org.junit.Assert.assertEquals;
2323

24-
public class GeodeSamplesIntegrationTest {
24+
public class GeodeSamplesLiveTest {
2525

2626
ClientCache cache = null;
2727
Region<String, String> region = null;

apache-olingo/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Relevant articles:
2+
3+
- [OData Protocol Guide](https://www.baeldung.com/odata)

apache-olingo/olingo2/pom.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
<artifactId>spring-boot-configuration-processor</artifactId>
4545
<optional>true</optional>
4646
</dependency>
47-
<dependency>
48-
<groupId>org.projectlombok</groupId>
49-
<artifactId>lombok</artifactId>
50-
<optional>true</optional>
51-
</dependency>
5247
<dependency>
5348
<groupId>org.springframework.boot</groupId>
5449
<artifactId>spring-boot-starter-test</artifactId>
@@ -68,16 +63,6 @@
6863
</exclusion>
6964
</exclusions>
7065
</dependency>
71-
<dependency>
72-
<groupId>org.apache.olingo</groupId>
73-
<artifactId>olingo-odata2-api</artifactId>
74-
<version>${olingo2.version}</version>
75-
</dependency>
76-
<dependency>
77-
<groupId>org.apache.olingo</groupId>
78-
<artifactId>olingo-odata2-jpa-processor-api</artifactId>
79-
<version>${olingo2.version}</version>
80-
</dependency>
8166
<dependency>
8267
<groupId>org.apache.olingo</groupId>
8368
<artifactId>olingo-odata2-jpa-processor-core</artifactId>

apache-olingo/olingo2/src/main/java/org/baeldung/examples/olingo2/domain/CarMaker.java

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,104 @@
1212
import javax.persistence.Table;
1313
import javax.validation.constraints.NotNull;
1414

15-
import lombok.Data;
16-
1715
@Entity
18-
@Data
19-
@Table(name="car_maker")
16+
@Table(name = "car_maker")
2017
public class CarMaker {
21-
18+
2219
@Id
23-
@GeneratedValue(strategy=GenerationType.IDENTITY)
20+
@GeneratedValue(strategy = GenerationType.IDENTITY)
2421
private Long id;
25-
22+
2623
@NotNull
27-
@Column(name="name")
24+
@Column(name = "name")
2825
private String name;
29-
30-
@OneToMany(mappedBy="maker",
31-
orphanRemoval = true,
32-
cascade=CascadeType.ALL)
26+
27+
@OneToMany(mappedBy = "maker", orphanRemoval = true, cascade = CascadeType.ALL)
3328
private List<CarModel> models;
34-
29+
30+
/**
31+
* @return the id
32+
*/
33+
public Long getId() {
34+
return id;
35+
}
36+
37+
/**
38+
* @param id the id to set
39+
*/
40+
public void setId(Long id) {
41+
this.id = id;
42+
}
43+
44+
/**
45+
* @return the name
46+
*/
47+
public String getName() {
48+
return name;
49+
}
50+
51+
/**
52+
* @param name the name to set
53+
*/
54+
public void setName(String name) {
55+
this.name = name;
56+
}
57+
58+
/**
59+
* @return the models
60+
*/
61+
public List<CarModel> getModels() {
62+
return models;
63+
}
64+
65+
/**
66+
* @param models the models to set
67+
*/
68+
public void setModels(List<CarModel> models) {
69+
this.models = models;
70+
}
71+
72+
/* (non-Javadoc)
73+
* @see java.lang.Object#hashCode()
74+
*/
75+
@Override
76+
public int hashCode() {
77+
final int prime = 31;
78+
int result = 1;
79+
result = prime * result + ((id == null) ? 0 : id.hashCode());
80+
result = prime * result + ((models == null) ? 0 : models.hashCode());
81+
result = prime * result + ((name == null) ? 0 : name.hashCode());
82+
return result;
83+
}
84+
85+
/* (non-Javadoc)
86+
* @see java.lang.Object#equals(java.lang.Object)
87+
*/
88+
@Override
89+
public boolean equals(Object obj) {
90+
if (this == obj)
91+
return true;
92+
if (obj == null)
93+
return false;
94+
if (getClass() != obj.getClass())
95+
return false;
96+
CarMaker other = (CarMaker) obj;
97+
if (id == null) {
98+
if (other.id != null)
99+
return false;
100+
} else if (!id.equals(other.id))
101+
return false;
102+
if (models == null) {
103+
if (other.models != null)
104+
return false;
105+
} else if (!models.equals(other.models))
106+
return false;
107+
if (name == null) {
108+
if (other.name != null)
109+
return false;
110+
} else if (!name.equals(other.name))
111+
return false;
112+
return true;
113+
}
35114

36115
}

0 commit comments

Comments
 (0)