Return unmodifiable iterators from Node and Graph. Make Node and Graph final.
This commit is contained in:
parent
bdb378c079
commit
5b733e25c7
@ -1,6 +1,7 @@
|
|||||||
package org.insa.graph;
|
package org.insa.graph;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
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.
|
* 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.
|
// Map identifier.
|
||||||
private final String mapId;
|
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) {
|
public Graph(String mapId, String mapName, List<Node> nodes, GraphStatistics graphStatistics) {
|
||||||
this.mapId = mapId;
|
this.mapId = mapId;
|
||||||
this.mapName = mapName;
|
this.mapName = mapName;
|
||||||
this.nodes = nodes;
|
this.nodes = Collections.unmodifiableList(nodes);
|
||||||
this.graphStatistics = graphStatistics;
|
this.graphStatistics = graphStatistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import java.util.Iterator;
|
|||||||
* Nodes are comparable based on their ID.
|
* 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),
|
* 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
|
@Override
|
||||||
public Iterator<Arc> iterator() {
|
public Iterator<Arc> iterator() {
|
||||||
return this.successors.iterator();
|
return Collections.unmodifiableList(this.successors).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user