Skip to content

Commit 9d0cb1e

Browse files
yasin3061maibin
authored andcommitted
BAEL-722 Intro to JSONassert (eugenp#1437)
* [email protected] Evaluation article on Different Types of Bean Injection in Spring * Revert "[email protected]" This reverts commit 963cc51. * Fixing compilation error and removing unused import * Introduction to Java9 StackWalking API - [email protected] Code examples for the article "Introduction to Java9 StackWalking API" * BAEL-608 Introduction to Java9 StackWalking API * BAEL-608 Introduction to Java9 StackWalking API changing the test names to BDD style * BAEL-608 Introduction to Java9 StackWalking API correcting the typo * BAEL-608 Introduction to Java9 StackWalking API improving method names * BAEL-608 Introduction to Java9 StackWalking API test method names improvements * BAEL-718 Quick intro to javatuples * merging pom from master * BAEL-722 Intro to JSONassert
1 parent 22b5c49 commit 9d0cb1e

27 files changed

+753
-632
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
package com.baeldung.algorithms.ga.dijkstra;
2-
3-
import java.util.HashSet;
4-
import java.util.LinkedList;
5-
import java.util.Map.Entry;
6-
import java.util.Set;
7-
8-
public class Dijkstra {
9-
10-
public static Graph calculateShortestPathFromSource(Graph graph, Node source) {
11-
12-
source.setDistance(0);
13-
14-
Set<Node> settledNodes = new HashSet<>();
15-
Set<Node> unsettledNodes = new HashSet<>();
16-
unsettledNodes.add(source);
17-
18-
while (unsettledNodes.size() != 0) {
19-
Node currentNode = getLowestDistanceNode(unsettledNodes);
20-
unsettledNodes.remove(currentNode);
21-
for (Entry<Node, Integer> adjacencyPair : currentNode.getAdjacentNodes().entrySet()) {
22-
Node adjacentNode = adjacencyPair.getKey();
23-
Integer edgeWeigh = adjacencyPair.getValue();
24-
25-
if (!settledNodes.contains(adjacentNode)) {
26-
CalculateMinimumDistance(adjacentNode, edgeWeigh, currentNode);
27-
unsettledNodes.add(adjacentNode);
28-
}
29-
}
30-
settledNodes.add(currentNode);
31-
}
32-
return graph;
33-
}
34-
35-
private static void CalculateMinimumDistance(Node evaluationNode, Integer edgeWeigh, Node sourceNode) {
36-
Integer sourceDistance = sourceNode.getDistance();
37-
if (sourceDistance + edgeWeigh < evaluationNode.getDistance()) {
38-
evaluationNode.setDistance(sourceDistance + edgeWeigh);
39-
LinkedList<Node> shortestPath = new LinkedList<>(sourceNode.getShortestPath());
40-
shortestPath.add(sourceNode);
41-
evaluationNode.setShortestPath(shortestPath);
42-
}
43-
}
44-
45-
private static Node getLowestDistanceNode(Set<Node> unsettledNodes) {
46-
Node lowestDistanceNode = null;
47-
int lowestDistance = Integer.MAX_VALUE;
48-
for (Node node : unsettledNodes) {
49-
int nodeDistance = node.getDistance();
50-
if (nodeDistance < lowestDistance) {
51-
lowestDistance = nodeDistance;
52-
lowestDistanceNode = node;
53-
}
54-
}
55-
return lowestDistanceNode;
56-
}
57-
}
1+
package com.baeldung.algorithms.ga.dijkstra;
2+
3+
import java.util.HashSet;
4+
import java.util.LinkedList;
5+
import java.util.Map.Entry;
6+
import java.util.Set;
7+
8+
public class Dijkstra {
9+
10+
public static Graph calculateShortestPathFromSource(Graph graph, Node source) {
11+
12+
source.setDistance(0);
13+
14+
Set<Node> settledNodes = new HashSet<>();
15+
Set<Node> unsettledNodes = new HashSet<>();
16+
unsettledNodes.add(source);
17+
18+
while (unsettledNodes.size() != 0) {
19+
Node currentNode = getLowestDistanceNode(unsettledNodes);
20+
unsettledNodes.remove(currentNode);
21+
for (Entry<Node, Integer> adjacencyPair : currentNode.getAdjacentNodes().entrySet()) {
22+
Node adjacentNode = adjacencyPair.getKey();
23+
Integer edgeWeigh = adjacencyPair.getValue();
24+
25+
if (!settledNodes.contains(adjacentNode)) {
26+
CalculateMinimumDistance(adjacentNode, edgeWeigh, currentNode);
27+
unsettledNodes.add(adjacentNode);
28+
}
29+
}
30+
settledNodes.add(currentNode);
31+
}
32+
return graph;
33+
}
34+
35+
private static void CalculateMinimumDistance(Node evaluationNode, Integer edgeWeigh, Node sourceNode) {
36+
Integer sourceDistance = sourceNode.getDistance();
37+
if (sourceDistance + edgeWeigh < evaluationNode.getDistance()) {
38+
evaluationNode.setDistance(sourceDistance + edgeWeigh);
39+
LinkedList<Node> shortestPath = new LinkedList<>(sourceNode.getShortestPath());
40+
shortestPath.add(sourceNode);
41+
evaluationNode.setShortestPath(shortestPath);
42+
}
43+
}
44+
45+
private static Node getLowestDistanceNode(Set<Node> unsettledNodes) {
46+
Node lowestDistanceNode = null;
47+
int lowestDistance = Integer.MAX_VALUE;
48+
for (Node node : unsettledNodes) {
49+
int nodeDistance = node.getDistance();
50+
if (nodeDistance < lowestDistance) {
51+
lowestDistance = nodeDistance;
52+
lowestDistanceNode = node;
53+
}
54+
}
55+
return lowestDistanceNode;
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package com.baeldung.algorithms.ga.dijkstra;
2-
3-
import java.util.HashSet;
4-
import java.util.Set;
5-
6-
public class Graph {
7-
8-
private Set<Node> nodes = new HashSet<>();
9-
10-
public void addNode(Node nodeA) {
11-
nodes.add(nodeA);
12-
}
13-
14-
public Set<Node> getNodes() {
15-
return nodes;
16-
}
17-
18-
public void setNodes(Set<Node> nodes) {
19-
this.nodes = nodes;
20-
}
21-
}
1+
package com.baeldung.algorithms.ga.dijkstra;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class Graph {
7+
8+
private Set<Node> nodes = new HashSet<>();
9+
10+
public void addNode(Node nodeA) {
11+
nodes.add(nodeA);
12+
}
13+
14+
public Set<Node> getNodes() {
15+
return nodes;
16+
}
17+
18+
public void setNodes(Set<Node> nodes) {
19+
this.nodes = nodes;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
package com.baeldung.algorithms.ga.dijkstra;
2-
3-
import java.util.HashMap;
4-
import java.util.LinkedList;
5-
import java.util.List;
6-
import java.util.Map;
7-
8-
public class Node {
9-
10-
private String name;
11-
12-
private LinkedList<Node> shortestPath = new LinkedList<>();
13-
14-
private Integer distance = Integer.MAX_VALUE;
15-
16-
private Map<Node, Integer> adjacentNodes = new HashMap<>();
17-
18-
public Node(String name) {
19-
this.name = name;
20-
}
21-
22-
public void addDestination(Node destination, int distance) {
23-
adjacentNodes.put(destination, distance);
24-
}
25-
26-
public String getName() {
27-
return name;
28-
}
29-
30-
public void setName(String name) {
31-
this.name = name;
32-
}
33-
34-
public Map<Node, Integer> getAdjacentNodes() {
35-
return adjacentNodes;
36-
}
37-
38-
public void setAdjacentNodes(Map<Node, Integer> adjacentNodes) {
39-
this.adjacentNodes = adjacentNodes;
40-
}
41-
42-
public Integer getDistance() {
43-
return distance;
44-
}
45-
46-
public void setDistance(Integer distance) {
47-
this.distance = distance;
48-
}
49-
50-
public List<Node> getShortestPath() {
51-
return shortestPath;
52-
}
53-
54-
public void setShortestPath(LinkedList<Node> shortestPath) {
55-
this.shortestPath = shortestPath;
56-
}
57-
58-
}
1+
package com.baeldung.algorithms.ga.dijkstra;
2+
3+
import java.util.HashMap;
4+
import java.util.LinkedList;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
public class Node {
9+
10+
private String name;
11+
12+
private LinkedList<Node> shortestPath = new LinkedList<>();
13+
14+
private Integer distance = Integer.MAX_VALUE;
15+
16+
private Map<Node, Integer> adjacentNodes = new HashMap<>();
17+
18+
public Node(String name) {
19+
this.name = name;
20+
}
21+
22+
public void addDestination(Node destination, int distance) {
23+
adjacentNodes.put(destination, distance);
24+
}
25+
26+
public String getName() {
27+
return name;
28+
}
29+
30+
public void setName(String name) {
31+
this.name = name;
32+
}
33+
34+
public Map<Node, Integer> getAdjacentNodes() {
35+
return adjacentNodes;
36+
}
37+
38+
public void setAdjacentNodes(Map<Node, Integer> adjacentNodes) {
39+
this.adjacentNodes = adjacentNodes;
40+
}
41+
42+
public Integer getDistance() {
43+
return distance;
44+
}
45+
46+
public void setDistance(Integer distance) {
47+
this.distance = distance;
48+
}
49+
50+
public List<Node> getShortestPath() {
51+
return shortestPath;
52+
}
53+
54+
public void setShortestPath(LinkedList<Node> shortestPath) {
55+
this.shortestPath = shortestPath;
56+
}
57+
58+
}

core-java/0.004102810554955205

Whitespace-only changes.

core-java/0.04832801936270381

Whitespace-only changes.

core-java/0.5633433244738808

Whitespace-only changes.

core-java/0.6256429734439612

Whitespace-only changes.

core-java/0.8260098203820962

Whitespace-only changes.

core-java/0.9799201796740292

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
2-
package com.baeldung.examples;
3-
4-
import com.baeldung.examples.guice.Communication;
5-
import com.baeldung.examples.guice.binding.AOPModule;
6-
import com.baeldung.examples.guice.modules.BasicModule;
7-
import com.google.inject.Guice;
8-
import com.google.inject.Injector;
9-
import java.util.Scanner;
10-
11-
/**
12-
*
13-
* @author baeldung
14-
*/
15-
public class RunGuice {
16-
17-
public static void main(String[] args) {
18-
Injector injector = Guice.createInjector(new BasicModule(), new AOPModule());
19-
Communication comms = injector.getInstance(Communication.class);
20-
Scanner scanner = new Scanner(System.in);
21-
while (true) {
22-
String input = scanner.nextLine();
23-
if (input.equalsIgnoreCase("q")) {
24-
System.exit(0);
25-
} else {
26-
comms.sendMessage(input);
27-
}
28-
29-
}
30-
31-
}
32-
}
1+
2+
package com.baeldung.examples;
3+
4+
import com.baeldung.examples.guice.Communication;
5+
import com.baeldung.examples.guice.binding.AOPModule;
6+
import com.baeldung.examples.guice.modules.BasicModule;
7+
import com.google.inject.Guice;
8+
import com.google.inject.Injector;
9+
import java.util.Scanner;
10+
11+
/**
12+
*
13+
* @author baeldung
14+
*/
15+
public class RunGuice {
16+
17+
public static void main(String[] args) {
18+
Injector injector = Guice.createInjector(new BasicModule(), new AOPModule());
19+
Communication comms = injector.getInstance(Communication.class);
20+
Scanner scanner = new Scanner(System.in);
21+
while (true) {
22+
String input = scanner.nextLine();
23+
if (input.equalsIgnoreCase("q")) {
24+
System.exit(0);
25+
} else {
26+
comms.sendMessage(input);
27+
}
28+
29+
}
30+
31+
}
32+
}

0 commit comments

Comments
 (0)