summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
committerbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
commitdf94066e3af02ff02d5ab4d033a3d603f743234c (patch)
tree168a1edaf58d386c175ffb601e9d4da8e13d31e2 /base/src/main/java/bjc/utils/graph/AdjacencyMap.java
parentae51c587c53f7ca311e556e3cbd0c5566d6c2843 (diff)
Formatting pass
Diffstat (limited to 'base/src/main/java/bjc/utils/graph/AdjacencyMap.java')
-rw-r--r--base/src/main/java/bjc/utils/graph/AdjacencyMap.java53
1 files changed, 25 insertions, 28 deletions
diff --git a/base/src/main/java/bjc/utils/graph/AdjacencyMap.java b/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
index 1598b25..965eccc 100644
--- a/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
+++ b/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
@@ -20,25 +20,24 @@ import bjc.utils.funcutils.FuncUtils;
* @author ben
*
* @param <T>
- * The type of the nodes in the graph
+ * The type of the nodes in the graph
*/
public class AdjacencyMap<T> {
/**
* Create an adjacency map from a stream of text
*
* @param stream
- * The stream of text to read in
+ * The stream of text to read in
*
- * @return
- * An adjacency map defined by the text
+ * @return An adjacency map defined by the text
*/
public static AdjacencyMap<Integer> fromStream(final InputStream stream) {
- if (stream == null) throw new NullPointerException("Input source must not be null");
+ if(stream == null) throw new NullPointerException("Input source must not be null");
/* Create the adjacency map. */
AdjacencyMap<Integer> adjacency;
- try (Scanner input = new Scanner(stream)) {
+ try(Scanner input = new Scanner(stream)) {
input.useDelimiter("\n");
int vertexCount;
@@ -48,8 +47,8 @@ public class AdjacencyMap<T> {
try {
/* First, read in number of vertices. */
vertexCount = Integer.parseInt(possible);
- } catch (final NumberFormatException nfex) {
- String msg = String.format(
+ } catch(final NumberFormatException nfex) {
+ String msg = String.format(
"The first line must contain the number of vertices. %s is not a valid number",
possible);
@@ -60,7 +59,7 @@ public class AdjacencyMap<T> {
throw imex;
}
- if (vertexCount <= 0)
+ if(vertexCount <= 0)
throw new InputMismatchException("The number of vertices must be greater than 0");
final IList<Integer> vertices = new FunctionalList<>();
@@ -84,7 +83,7 @@ public class AdjacencyMap<T> {
final IHolder<Integer> row, final String strang) {
final String[] parts = strang.split(" ");
- if (parts.length != vertexCount) {
+ if(parts.length != vertexCount) {
String msg = String.format("Must specify a weight for all %d vertices", vertexCount);
throw new InputMismatchException(msg);
@@ -92,12 +91,12 @@ public class AdjacencyMap<T> {
int column = 0;
- for (final String part : parts) {
+ for(final String part : parts) {
int weight;
try {
weight = Integer.parseInt(part);
- } catch (final NumberFormatException nfex) {
+ } catch(final NumberFormatException nfex) {
String msg = String.format("%d is not a valid weight.", part);
final InputMismatchException imex = new InputMismatchException(msg);
@@ -121,10 +120,10 @@ public class AdjacencyMap<T> {
* Create a new map from a set of vertices
*
* @param vertices
- * The set of vertices to create a map from
+ * The set of vertices to create a map from
*/
public AdjacencyMap(final IList<T> vertices) {
- if (vertices == null) throw new NullPointerException("Vertices must not be null");
+ if(vertices == null) throw new NullPointerException("Vertices must not be null");
vertices.forEach(vertex -> {
final IMap<T, Integer> row = new FunctionalMap<>();
@@ -140,8 +139,7 @@ public class AdjacencyMap<T> {
/**
* Check if the graph is directed
*
- * @return
- * Whether or not the graph is directed
+ * @return Whether or not the graph is directed
*/
public boolean isDirected() {
final IHolder<Boolean> result = new Identity<>(true);
@@ -150,7 +148,7 @@ public class AdjacencyMap<T> {
sourceValue.forEach((targetKey, targetValue) -> {
final int inverseValue = adjacency.get(targetKey).get(sourceKey);
- if (targetValue != inverseValue) {
+ if(targetValue != inverseValue) {
result.replace(false);
}
});
@@ -163,24 +161,24 @@ public class AdjacencyMap<T> {
* Set the weight of an edge.
*
* @param source
- * The source node of the edge.
+ * The source node of the edge.
* @param target
- * The target node of the edge.
+ * The target node of the edge.
* @param weight
- * The weight of the edge.
+ * The weight of the edge.
*/
public void setWeight(final T source, final T target, final int weight) {
- if (source == null) {
+ if(source == null) {
throw new NullPointerException("Source vertex must not be null");
- } else if (target == null) {
+ } else if(target == null) {
throw new NullPointerException("Target vertex must not be null");
}
- if (!adjacency.containsKey(source)) {
+ if(!adjacency.containsKey(source)) {
String msg = String.format("Source vertex %s isn't present in map", source);
throw new IllegalArgumentException(msg);
- } else if (!adjacency.containsKey(target)) {
+ } else if(!adjacency.containsKey(target)) {
String msg = String.format("Target vertex %s isn't present in map", target);
throw new IllegalArgumentException(msg);
@@ -192,8 +190,7 @@ public class AdjacencyMap<T> {
/**
* Convert this to a different graph representation.
*
- * @return
- * The new representation of this graph.
+ * @return The new representation of this graph.
*/
public Graph<T> toGraph() {
final Graph<T> ret = new Graph<>();
@@ -211,10 +208,10 @@ public class AdjacencyMap<T> {
* Convert an adjacency map back into a stream.
*
* @param sink
- * The stream to convert to.
+ * The stream to convert to.
*/
public void toStream(final OutputStream sink) {
- if (sink == null) throw new NullPointerException("Output source must not be null");
+ if(sink == null) throw new NullPointerException("Output source must not be null");
final PrintStream outputPrinter = new PrintStream(sink);