summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-03-22 12:28:35 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-03-22 12:28:35 -0400
commit01cb9f504c860bc1c037a44f3a76bf342a293d46 (patch)
tree02d1d34de0828159bbda93e881c93a6b45720f32 /BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
parent4685955a62c430007c5c8ed2b915ffc618d30aca (diff)
General formatting cleanup and documentation update
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java16
1 files changed, 7 insertions, 9 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
index 3b54b27..2f2ac04 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
@@ -35,7 +35,7 @@ public class Graph<T> {
* Create a new graph
*/
public Graph() {
- graph = new HashMap<T, Map<T, Integer>>();
+ graph = new HashMap<>();
}
/**
@@ -121,20 +121,18 @@ public class Graph<T> {
* Uses Prim's algorothm to calculate a MST for the graph. If the graph
* is non-connected, this will lead to unpredictable results.
*
- * @param graph
- * a connected graph.
* @return a list of edges that constitute the MST
*/
public List<Edge<T>> getMinSpanTree() {
// Set of all of the currently available edges
- Queue<Edge<T>> availEdges = new PriorityQueue<Edge<T>>(10,
+ Queue<Edge<T>> availEdges = new PriorityQueue<>(10,
(e1, e2) -> e1.getDistance() - e2.getDistance());
// The MST of the graph
- List<Edge<T>> minEdges = new ArrayList<Edge<T>>();
+ List<Edge<T>> minEdges = new ArrayList<>();
// The set of all of the visited vertices.
- Set<T> visited = new HashSet<T>();
+ Set<T> visited = new HashSet<>();
// Start at the initial vertex and visit it
IHolder<T> src = new GenHolder<>(getInitial());
@@ -146,12 +144,11 @@ public class Graph<T> {
forAllEdgesMatchingAt(src.unwrap(vl -> vl),
(tgt, weight) -> !visited.contains(tgt),
- (tgt, weight) -> availEdges.add(new Edge<T>(
+ (tgt, weight) -> availEdges.add(new Edge<>(
src.unwrap(vl -> vl), tgt, weight)));
// Get the edge with the minimum distance
- IHolder<Edge<T>> minEdge = new GenHolder<>(
- availEdges.poll());
+ IHolder<Edge<T>> minEdge = new GenHolder<>(availEdges.poll());
// Only consider edges where we haven't visited the target of
// the edge
@@ -240,6 +237,7 @@ public class Graph<T> {
/**
* Create a graph from a list of edges
+ * @param <E> The type of data stored in the edges
*
* @param edges
* The list of edges to build from