Return unmodifiable iterators from Node and Graph. Make Node and Graph final.

This commit is contained in:
Holt59 2018-03-22 20:05:42 +01:00
parent bdb378c079
commit 5b733e25c7
2 changed files with 5 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package org.insa.graph;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@ -11,7 +12,7 @@ import java.util.List;
* holds a list of nodes and each node holds a list of its successors.
*
*/
public class Graph implements Iterable<Node> {
public final class Graph implements Iterable<Node> {
// Map identifier.
private final String mapId;
@ -36,7 +37,7 @@ public class Graph implements Iterable<Node> {
public Graph(String mapId, String mapName, List<Node> nodes, GraphStatistics graphStatistics) {
this.mapId = mapId;
this.mapName = mapName;
this.nodes = nodes;
this.nodes = Collections.unmodifiableList(nodes);
this.graphStatistics = graphStatistics;
}

View file

@ -13,7 +13,7 @@ import java.util.Iterator;
* Nodes are comparable based on their ID.
*
*/
public class Node implements Comparable<Node>, Iterable<Arc> {
public final class Node implements Comparable<Node>, Iterable<Arc> {
/**
* Link the two given nodes with one or two arcs (depending on roadInformation),
@ -109,7 +109,7 @@ public class Node implements Comparable<Node>, Iterable<Arc> {
@Override
public Iterator<Arc> iterator() {
return this.successors.iterator();
return Collections.unmodifiableList(this.successors).iterator();
}
/**