Skip to content

Commit

Permalink
BAEL-722 Intro to JSONassert (eugenp#1437)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
yasin3061 authored and maibin committed Mar 19, 2017
1 parent 22b5c49 commit 9d0cb1e
Show file tree
Hide file tree
Showing 27 changed files with 753 additions and 632 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
package com.baeldung.algorithms.ga.dijkstra;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Set;

public class Dijkstra {

public static Graph calculateShortestPathFromSource(Graph graph, Node source) {

source.setDistance(0);

Set<Node> settledNodes = new HashSet<>();
Set<Node> unsettledNodes = new HashSet<>();
unsettledNodes.add(source);

while (unsettledNodes.size() != 0) {
Node currentNode = getLowestDistanceNode(unsettledNodes);
unsettledNodes.remove(currentNode);
for (Entry<Node, Integer> adjacencyPair : currentNode.getAdjacentNodes().entrySet()) {
Node adjacentNode = adjacencyPair.getKey();
Integer edgeWeigh = adjacencyPair.getValue();

if (!settledNodes.contains(adjacentNode)) {
CalculateMinimumDistance(adjacentNode, edgeWeigh, currentNode);
unsettledNodes.add(adjacentNode);
}
}
settledNodes.add(currentNode);
}
return graph;
}

private static void CalculateMinimumDistance(Node evaluationNode, Integer edgeWeigh, Node sourceNode) {
Integer sourceDistance = sourceNode.getDistance();
if (sourceDistance + edgeWeigh < evaluationNode.getDistance()) {
evaluationNode.setDistance(sourceDistance + edgeWeigh);
LinkedList<Node> shortestPath = new LinkedList<>(sourceNode.getShortestPath());
shortestPath.add(sourceNode);
evaluationNode.setShortestPath(shortestPath);
}
}

private static Node getLowestDistanceNode(Set<Node> unsettledNodes) {
Node lowestDistanceNode = null;
int lowestDistance = Integer.MAX_VALUE;
for (Node node : unsettledNodes) {
int nodeDistance = node.getDistance();
if (nodeDistance < lowestDistance) {
lowestDistance = nodeDistance;
lowestDistanceNode = node;
}
}
return lowestDistanceNode;
}
}
package com.baeldung.algorithms.ga.dijkstra;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Set;

public class Dijkstra {

public static Graph calculateShortestPathFromSource(Graph graph, Node source) {

source.setDistance(0);

Set<Node> settledNodes = new HashSet<>();
Set<Node> unsettledNodes = new HashSet<>();
unsettledNodes.add(source);

while (unsettledNodes.size() != 0) {
Node currentNode = getLowestDistanceNode(unsettledNodes);
unsettledNodes.remove(currentNode);
for (Entry<Node, Integer> adjacencyPair : currentNode.getAdjacentNodes().entrySet()) {
Node adjacentNode = adjacencyPair.getKey();
Integer edgeWeigh = adjacencyPair.getValue();

if (!settledNodes.contains(adjacentNode)) {
CalculateMinimumDistance(adjacentNode, edgeWeigh, currentNode);
unsettledNodes.add(adjacentNode);
}
}
settledNodes.add(currentNode);
}
return graph;
}

private static void CalculateMinimumDistance(Node evaluationNode, Integer edgeWeigh, Node sourceNode) {
Integer sourceDistance = sourceNode.getDistance();
if (sourceDistance + edgeWeigh < evaluationNode.getDistance()) {
evaluationNode.setDistance(sourceDistance + edgeWeigh);
LinkedList<Node> shortestPath = new LinkedList<>(sourceNode.getShortestPath());
shortestPath.add(sourceNode);
evaluationNode.setShortestPath(shortestPath);
}
}

private static Node getLowestDistanceNode(Set<Node> unsettledNodes) {
Node lowestDistanceNode = null;
int lowestDistance = Integer.MAX_VALUE;
for (Node node : unsettledNodes) {
int nodeDistance = node.getDistance();
if (nodeDistance < lowestDistance) {
lowestDistance = nodeDistance;
lowestDistanceNode = node;
}
}
return lowestDistanceNode;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.baeldung.algorithms.ga.dijkstra;

import java.util.HashSet;
import java.util.Set;

public class Graph {

private Set<Node> nodes = new HashSet<>();

public void addNode(Node nodeA) {
nodes.add(nodeA);
}

public Set<Node> getNodes() {
return nodes;
}

public void setNodes(Set<Node> nodes) {
this.nodes = nodes;
}
}
package com.baeldung.algorithms.ga.dijkstra;

import java.util.HashSet;
import java.util.Set;

public class Graph {

private Set<Node> nodes = new HashSet<>();

public void addNode(Node nodeA) {
nodes.add(nodeA);
}

public Set<Node> getNodes() {
return nodes;
}

public void setNodes(Set<Node> nodes) {
this.nodes = nodes;
}
}
116 changes: 58 additions & 58 deletions algorithms/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
package com.baeldung.algorithms.ga.dijkstra;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Node {

private String name;

private LinkedList<Node> shortestPath = new LinkedList<>();

private Integer distance = Integer.MAX_VALUE;

private Map<Node, Integer> adjacentNodes = new HashMap<>();

public Node(String name) {
this.name = name;
}

public void addDestination(Node destination, int distance) {
adjacentNodes.put(destination, distance);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Map<Node, Integer> getAdjacentNodes() {
return adjacentNodes;
}

public void setAdjacentNodes(Map<Node, Integer> adjacentNodes) {
this.adjacentNodes = adjacentNodes;
}

public Integer getDistance() {
return distance;
}

public void setDistance(Integer distance) {
this.distance = distance;
}

public List<Node> getShortestPath() {
return shortestPath;
}

public void setShortestPath(LinkedList<Node> shortestPath) {
this.shortestPath = shortestPath;
}

}
package com.baeldung.algorithms.ga.dijkstra;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Node {

private String name;

private LinkedList<Node> shortestPath = new LinkedList<>();

private Integer distance = Integer.MAX_VALUE;

private Map<Node, Integer> adjacentNodes = new HashMap<>();

public Node(String name) {
this.name = name;
}

public void addDestination(Node destination, int distance) {
adjacentNodes.put(destination, distance);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Map<Node, Integer> getAdjacentNodes() {
return adjacentNodes;
}

public void setAdjacentNodes(Map<Node, Integer> adjacentNodes) {
this.adjacentNodes = adjacentNodes;
}

public Integer getDistance() {
return distance;
}

public void setDistance(Integer distance) {
this.distance = distance;
}

public List<Node> getShortestPath() {
return shortestPath;
}

public void setShortestPath(LinkedList<Node> shortestPath) {
this.shortestPath = shortestPath;
}

}
Empty file removed core-java/0.004102810554955205
Empty file.
Empty file removed core-java/0.04832801936270381
Empty file.
Empty file removed core-java/0.5633433244738808
Empty file.
Empty file removed core-java/0.6256429734439612
Empty file.
Empty file removed core-java/0.8260098203820962
Empty file.
Empty file removed core-java/0.9799201796740292
Empty file.
64 changes: 32 additions & 32 deletions guice/src/main/java/com/baeldung/examples/RunGuice.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@

package com.baeldung.examples;

import com.baeldung.examples.guice.Communication;
import com.baeldung.examples.guice.binding.AOPModule;
import com.baeldung.examples.guice.modules.BasicModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.Scanner;

/**
*
* @author baeldung
*/
public class RunGuice {

public static void main(String[] args) {
Injector injector = Guice.createInjector(new BasicModule(), new AOPModule());
Communication comms = injector.getInstance(Communication.class);
Scanner scanner = new Scanner(System.in);
while (true) {
String input = scanner.nextLine();
if (input.equalsIgnoreCase("q")) {
System.exit(0);
} else {
comms.sendMessage(input);
}

}

}
}

package com.baeldung.examples;

import com.baeldung.examples.guice.Communication;
import com.baeldung.examples.guice.binding.AOPModule;
import com.baeldung.examples.guice.modules.BasicModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.Scanner;

/**
*
* @author baeldung
*/
public class RunGuice {

public static void main(String[] args) {
Injector injector = Guice.createInjector(new BasicModule(), new AOPModule());
Communication comms = injector.getInstance(Communication.class);
Scanner scanner = new Scanner(System.in);
while (true) {
String input = scanner.nextLine();
if (input.equalsIgnoreCase("q")) {
System.exit(0);
} else {
comms.sendMessage(input);
}

}

}
}
Loading

0 comments on commit 9d0cb1e

Please sign in to comment.