summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
diff options
context:
space:
mode:
authorEVE <EVE@EVE-PC>2017-03-13 16:42:21 -0400
committerEVE <EVE@EVE-PC>2017-03-13 16:42:21 -0400
commit27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd (patch)
tree847fb52acb091c1c613d37b8477094d5762c6988 /BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
parentaa807a96cae2c47259fb38f710640883060339e9 (diff)
Formatting
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java48
1 files changed, 19 insertions, 29 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java b/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
index c04aa23..5640ab6 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
@@ -20,20 +20,19 @@ 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
*/
public static AdjacencyMap<Integer> fromStream(InputStream stream) {
if (stream == null) {
- throw new NullPointerException(
- "Input source must not be null");
+ throw new NullPointerException("Input source must not be null");
}
// Create the adjacency map
@@ -51,8 +50,7 @@ public class AdjacencyMap<T> {
vertexCount = Integer.parseInt(possible);
} catch (NumberFormatException nfex) {
InputMismatchException imex = new InputMismatchException(
- "The first line must contain the number of vertices. "
- + possible
+ "The first line must contain the number of vertices. " + possible
+ " is not a valid number");
imex.initCause(nfex);
@@ -61,8 +59,7 @@ public class AdjacencyMap<T> {
}
if (vertexCount <= 0) {
- throw new InputMismatchException(
- "The number of vertices must be greater than 0");
+ throw new InputMismatchException("The number of vertices must be greater than 0");
}
IList<Integer> vertices = new FunctionalList<>();
@@ -81,14 +78,12 @@ public class AdjacencyMap<T> {
return adjacency;
}
- private static void readRow(AdjacencyMap<Integer> adjacency,
- int vertexCount, IHolder<Integer> row, String strang) {
+ private static void readRow(AdjacencyMap<Integer> adjacency, int vertexCount, IHolder<Integer> row,
+ String strang) {
String[] parts = strang.split(" ");
if (parts.length != vertexCount) {
- throw new InputMismatchException(
- "Must specify a weight for all " + vertexCount
- + " vertices");
+ throw new InputMismatchException("Must specify a weight for all " + vertexCount + " vertices");
}
int column = 0;
@@ -124,7 +119,7 @@ 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(IList<T> vertices) {
if (vertices == null) {
@@ -167,27 +162,23 @@ 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(T source, T target, int weight) {
if (source == null) {
- throw new NullPointerException(
- "Source vertex must not be null");
- } else if (target== null) {
- throw new NullPointerException(
- "Target vertex must not be null");
+ throw new NullPointerException("Source vertex must not be null");
+ } else if (target == null) {
+ throw new NullPointerException("Target vertex must not be null");
}
if (!adjacency.containsKey(source)) {
- throw new IllegalArgumentException("Source vertex "
- + source + " isn't present in map");
+ throw new IllegalArgumentException("Source vertex " + source + " isn't present in map");
} else if (!adjacency.containsKey(target)) {
- throw new IllegalArgumentException("Target vertex "
- + target+ " isn't present in map");
+ throw new IllegalArgumentException("Target vertex " + target + " isn't present in map");
}
adjacency.get(source).put(target, weight);
@@ -214,12 +205,11 @@ 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(OutputStream sink) {
if (sink == null) {
- throw new NullPointerException(
- "Output source must not be null");
+ throw new NullPointerException("Output source must not be null");
}
PrintStream outputPrinter = new PrintStream(sink);