[model] Clean Java classes.
This commit is contained in:
parent
c9ff67b10e
commit
2f936d44ec
@ -170,7 +170,7 @@ public class AccessRestrictions {
|
||||
* Create a new AccessRestrictions instances with the given restrictions.
|
||||
*
|
||||
* @param restrictions Map of restrictions for this instance of
|
||||
* AccessRestrictions.
|
||||
* AccessRestrictions.
|
||||
*/
|
||||
public AccessRestrictions(EnumMap<AccessMode, AccessRestriction> restrictions) {
|
||||
this.restrictions = restrictions;
|
||||
@ -191,7 +191,7 @@ public class AccessRestrictions {
|
||||
* Check if the restriction associated with the given mode is one of the given
|
||||
* restrictions.
|
||||
*
|
||||
* @param mode Mode for which to check the restrictions.
|
||||
* @param mode Mode for which to check the restrictions.
|
||||
* @param restrictions List of queried restrictions for the mode.
|
||||
*
|
||||
* @return {@code true} if the restriction of the given mode is one of the given
|
||||
@ -205,7 +205,7 @@ public class AccessRestrictions {
|
||||
* Check if the restriction for the given mode corresponds to the given
|
||||
* restriction.
|
||||
*
|
||||
* @param mode Mode for which the restriction should be checked.
|
||||
* @param mode Mode for which the restriction should be checked.
|
||||
* @param restriction Restriction to check against.
|
||||
*
|
||||
* @return {@code true} if the restriction of the given mode corresponds to the
|
||||
@ -219,7 +219,7 @@ public class AccessRestrictions {
|
||||
* Check if the restriction associated to each given mode is one of the
|
||||
* restrictions. The restriction may not be the same for all modes.
|
||||
*
|
||||
* @param modes Modes for which restrictions should be checked.
|
||||
* @param modes Modes for which restrictions should be checked.
|
||||
* @param restrictions Set of wanted restrictions for the modes.
|
||||
*
|
||||
* @return {@code true} if all the given modes are allowed for any of the given
|
||||
@ -227,10 +227,6 @@ public class AccessRestrictions {
|
||||
*/
|
||||
public boolean areAllAllowedForAny(EnumSet<AccessMode> modes,
|
||||
EnumSet<AccessRestriction> restrictions) {
|
||||
boolean allowed = true;
|
||||
for (AccessMode mode: modes) {
|
||||
allowed = allowed && isAllowedForAny(mode, restrictions);
|
||||
}
|
||||
return allowed;
|
||||
return modes.stream().allMatch(mode -> isAllowedForAny(mode, restrictions));
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ class ArcBackward extends Arc {
|
||||
|
||||
@Override
|
||||
public List<Point> getPoints() {
|
||||
List<Point> pts = new ArrayList<>(this.originalArc.getPoints());
|
||||
// There does not seem to be a cleaner way to do this using Java 8 streams.
|
||||
final List<Point> pts = new ArrayList<>(this.originalArc.getPoints());
|
||||
Collections.reverse(pts);
|
||||
return pts;
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ public final class Graph {
|
||||
/**
|
||||
* Create a new graph with the given ID, name, nodes and information.
|
||||
*
|
||||
* @param mapId ID of the map corresponding to this graph.
|
||||
* @param mapName Name of the map corresponding to this graph.
|
||||
* @param nodes List of nodes for this graph.
|
||||
* @param mapId ID of the map corresponding to this graph.
|
||||
* @param mapName Name of the map corresponding to this graph.
|
||||
* @param nodes List of nodes for this graph.
|
||||
* @param graphStatistics Information for this graph.
|
||||
*/
|
||||
public Graph(String mapId, String mapName, List<Node> nodes, GraphStatistics graphStatistics) {
|
||||
@ -98,20 +98,20 @@ public final class Graph {
|
||||
* @return Transpose graph of this graph.
|
||||
*/
|
||||
public Graph transpose() {
|
||||
ArrayList<Node> trNodes = new ArrayList<>(nodes.size());
|
||||
final ArrayList<Node> trNodes = new ArrayList<>(nodes.size());
|
||||
for (Node node: nodes) {
|
||||
trNodes.add(new Node(node.getId(), node.getPoint()));
|
||||
}
|
||||
for (Node node: nodes) {
|
||||
Node orig = trNodes.get(node.getId());
|
||||
final Node orig = trNodes.get(node.getId());
|
||||
for (Arc arc: node.getSuccessors()) {
|
||||
if (arc.getRoadInformation().isOneWay()) {
|
||||
Node dest = trNodes.get(arc.getDestination().getId());
|
||||
final Node dest = trNodes.get(arc.getDestination().getId());
|
||||
dest.addSuccessor(new ArcBackward(new ArcForward(orig, dest, arc.getLength(),
|
||||
arc.getRoadInformation(), arc.getPoints())));
|
||||
}
|
||||
else if (arc instanceof ArcForward) {
|
||||
Node dest = trNodes.get(arc.getDestination().getId());
|
||||
final Node dest = trNodes.get(arc.getDestination().getId());
|
||||
Arc newArc = new ArcForward(orig, dest, arc.getLength(),
|
||||
arc.getRoadInformation(), arc.getPoints());
|
||||
dest.addSuccessor(new ArcBackward(newArc));
|
||||
|
@ -33,23 +33,23 @@ public final class Node implements Comparable<Node> {
|
||||
* corresponding backward arc is created and add to destination.
|
||||
* </p>
|
||||
*
|
||||
* @param origin Origin of the arc.
|
||||
* @param destination Destination of the arc.
|
||||
* @param length Length of the arc.
|
||||
* @param origin Origin of the arc.
|
||||
* @param destination Destination of the arc.
|
||||
* @param length Length of the arc.
|
||||
* @param roadInformation Information corresponding to the arc.
|
||||
* @param points Points for the arc.
|
||||
* @param points Points for the arc.
|
||||
*
|
||||
* @return The newly created forward arc (origin to destination).
|
||||
*/
|
||||
public static Arc linkNodes(Node origin, Node destination, float length,
|
||||
RoadInformation roadInformation, ArrayList<Point> points) {
|
||||
Arc arc = null;
|
||||
final Arc arc;
|
||||
if (roadInformation.isOneWay()) {
|
||||
arc = new ArcForward(origin, destination, length, roadInformation, points);
|
||||
origin.addSuccessor(arc);
|
||||
}
|
||||
else {
|
||||
Arc d2o;
|
||||
final Arc d2o;
|
||||
if (origin.getId() < destination.getId()) {
|
||||
arc = new ArcForward(origin, destination, length, roadInformation, points);
|
||||
d2o = new ArcBackward(arc);
|
||||
@ -78,7 +78,7 @@ public final class Node implements Comparable<Node> {
|
||||
* Create a new Node with the given ID corresponding to the given Point with an
|
||||
* empty list of successors.
|
||||
*
|
||||
* @param id ID of the node.
|
||||
* @param id ID of the node.
|
||||
* @param point Position of the node.
|
||||
*/
|
||||
public Node(int id, Point point) {
|
||||
|
@ -12,7 +12,7 @@ public class BadFormatException extends IOException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1270945933549613579L;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -7,15 +7,15 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.model.AccessRestrictions;
|
||||
import org.insa.graphs.model.AccessRestrictions.AccessMode;
|
||||
import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
|
||||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.GraphStatistics;
|
||||
import org.insa.graphs.model.GraphStatistics.BoundingBox;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Point;
|
||||
import org.insa.graphs.model.RoadInformation;
|
||||
import org.insa.graphs.model.AccessRestrictions.AccessMode;
|
||||
import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
|
||||
import org.insa.graphs.model.GraphStatistics.BoundingBox;
|
||||
import org.insa.graphs.model.RoadInformation.RoadType;
|
||||
|
||||
/**
|
||||
@ -32,7 +32,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
protected static final int MAP_ID_FIELD_LENGTH = 32;
|
||||
|
||||
// List of observers
|
||||
protected List<GraphReaderObserver> observers = new ArrayList<>();
|
||||
protected final List<GraphReaderObserver> observers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Parse the given long value into a new instance of AccessRestrictions.
|
||||
@ -63,7 +63,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
AccessMode.MOTORCAR, AccessMode.HEAVY_GOODS, null, AccessMode.PUBLIC_TRANSPORT };
|
||||
|
||||
// fill maps...
|
||||
EnumMap<AccessMode, AccessRestriction> restrictions = new EnumMap<>(AccessMode.class);
|
||||
final EnumMap<AccessMode, AccessRestriction> restrictions = new EnumMap<>(AccessMode.class);
|
||||
long copyAccess = access;
|
||||
for (AccessMode mode: allModes) {
|
||||
if (mode == null) {
|
||||
@ -155,11 +155,12 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
checkVersionOrThrow(dis.readInt());
|
||||
|
||||
// Read map id.
|
||||
String mapId;
|
||||
String mapName = "";
|
||||
final String mapId;
|
||||
final String mapName;
|
||||
|
||||
if (getCurrentVersion() < 6) {
|
||||
mapId = "0x" + Integer.toHexString(dis.readInt());
|
||||
mapName = ""; // No map name for older versions.
|
||||
}
|
||||
else {
|
||||
mapId = readFixedLengthString(MAP_ID_FIELD_LENGTH, "UTF-8");
|
||||
@ -169,15 +170,15 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
observers.forEach((observer) -> observer.notifyStartReading(mapId));
|
||||
|
||||
// Number of descriptors and nodes.
|
||||
int nbDesc = dis.readInt();
|
||||
int nbNodes = dis.readInt();
|
||||
final int nbDesc = dis.readInt();
|
||||
final int nbNodes = dis.readInt();
|
||||
|
||||
// Number of successors for each nodes.
|
||||
int[] nbSuccessors = new int[nbNodes];
|
||||
final int[] nbSuccessors = new int[nbNodes];
|
||||
int nbTotalSuccessors = 0;
|
||||
|
||||
// Construct an array list with initial capacity of nbNodes.
|
||||
ArrayList<Node> nodes = new ArrayList<Node>(nbNodes);
|
||||
final ArrayList<Node> nodes = new ArrayList<Node>(nbNodes);
|
||||
|
||||
// Read nodes.
|
||||
float minLongitude = Float.POSITIVE_INFINITY, minLatitude = Float.POSITIVE_INFINITY,
|
||||
@ -185,8 +186,8 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
observers.forEach((observer) -> observer.notifyStartReadingNodes(nbNodes));
|
||||
for (int node = 0; node < nbNodes; ++node) {
|
||||
// Read longitude / latitude.
|
||||
float longitude = ((float) dis.readInt()) / 1E6f;
|
||||
float latitude = ((float) dis.readInt()) / 1E6f;
|
||||
final float longitude = ((float) dis.readInt()) / 1E6f;
|
||||
final float latitude = ((float) dis.readInt()) / 1E6f;
|
||||
|
||||
// Update minimum / maximum.
|
||||
minLongitude = Math.min(longitude, minLongitude);
|
||||
@ -208,7 +209,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
checkByteOrThrow(255);
|
||||
|
||||
// Read descriptors.
|
||||
RoadInformation[] descs = new RoadInformation[nbDesc];
|
||||
final RoadInformation[] descs = new RoadInformation[nbDesc];
|
||||
|
||||
// Read
|
||||
observers.forEach((observer) -> observer.notifyStartReadingDescriptors(nbDesc));
|
||||
@ -234,10 +235,10 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
|
||||
|
||||
// Read target node number.
|
||||
int destNode = this.read24bits();
|
||||
final int destNode = this.read24bits();
|
||||
|
||||
// Read information number.
|
||||
int descrNum = this.read24bits();
|
||||
final int descrNum = this.read24bits();
|
||||
|
||||
// Length of the arc.
|
||||
float length;
|
||||
@ -253,10 +254,10 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
nodes.get(destNode).getPoint()));
|
||||
|
||||
// Number of segments.
|
||||
int nbSegments = dis.readUnsignedShort();
|
||||
final int nbSegments = dis.readUnsignedShort();
|
||||
|
||||
// Chain of points corresponding to the segments.
|
||||
ArrayList<Point> points = new ArrayList<Point>(nbSegments + 2);
|
||||
final ArrayList<Point> points = new ArrayList<Point>(nbSegments + 2);
|
||||
points.add(nodes.get(node).getPoint());
|
||||
|
||||
for (int seg = 0; seg < nbSegments; ++seg) {
|
||||
@ -271,12 +272,12 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
|
||||
points.add(nodes.get(destNode).getPoint());
|
||||
|
||||
RoadInformation info = descs[descrNum];
|
||||
Node orig = nodes.get(node);
|
||||
Node dest = nodes.get(destNode);
|
||||
final RoadInformation info = descs[descrNum];
|
||||
final Node orig = nodes.get(node);
|
||||
final Node dest = nodes.get(destNode);
|
||||
|
||||
// Add successor to initial arc.
|
||||
Arc arc = Node.linkNodes(orig, dest, length, info, points);
|
||||
final Arc arc = Node.linkNodes(orig, dest, length, info, points);
|
||||
if (info.isOneWay()) {
|
||||
nbOneWayRoad++;
|
||||
}
|
||||
@ -289,8 +290,6 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
|
||||
observers.forEach((observer) -> observer.notifyEndReading());
|
||||
|
||||
this.dis.close();
|
||||
|
||||
return new Graph(mapId, mapName, nodes,
|
||||
new GraphStatistics(
|
||||
new BoundingBox(new Point(minLongitude, maxLatitude),
|
||||
|
@ -35,27 +35,25 @@ public class BinaryPathReader extends BinaryReader implements PathReader {
|
||||
checkVersionOrThrow(dis.readInt());
|
||||
|
||||
// Read map ID and check against graph.
|
||||
String mapId = readFixedLengthString(BinaryGraphReader.MAP_ID_FIELD_LENGTH, "UTF-8");
|
||||
final String mapId = readFixedLengthString(BinaryGraphReader.MAP_ID_FIELD_LENGTH, "UTF-8");
|
||||
|
||||
if (!mapId.equals(graph.getMapId())) {
|
||||
throw new MapMismatchException(mapId, graph.getMapId());
|
||||
}
|
||||
|
||||
// Number of nodes in the path (without first and last).
|
||||
int nbNodes = dis.readInt();
|
||||
final int nbNodes = dis.readInt();
|
||||
|
||||
// Skip (duplicate) first and last node
|
||||
readNode(graph);
|
||||
readNode(graph);
|
||||
|
||||
// Read intermediate nodes:
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
final ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
for (int i = 0; i < nbNodes; ++i) {
|
||||
nodes.add(readNode(graph));
|
||||
}
|
||||
|
||||
this.dis.close();
|
||||
|
||||
return Path.createFastestPathFromNodes(graph, nodes);
|
||||
}
|
||||
|
||||
@ -66,7 +64,7 @@ public class BinaryPathReader extends BinaryReader implements PathReader {
|
||||
*
|
||||
* @return The next node in the input stream.
|
||||
*
|
||||
* @throws IOException if something occurs while reading the note.
|
||||
* @throws IOException if something occurs while reading the note.
|
||||
* @throws IndexOutOfBoundsException if the node is not in the graph.
|
||||
*/
|
||||
protected Node readNode(Graph graph) throws IOException {
|
||||
|
@ -30,7 +30,7 @@ public class BinaryPathWriter extends BinaryWriter implements PathWriter {
|
||||
dos.writeInt(BinaryPathReader.VERSION);
|
||||
|
||||
// Write map id.
|
||||
byte[] bytes = Arrays.copyOf(path.getGraph().getMapId().getBytes("UTF-8"),
|
||||
final byte[] bytes = Arrays.copyOf(path.getGraph().getMapId().getBytes("UTF-8"),
|
||||
BinaryGraphReader.MAP_ID_FIELD_LENGTH);
|
||||
dos.write(bytes);
|
||||
|
||||
@ -48,7 +48,6 @@ public class BinaryPathWriter extends BinaryWriter implements PathWriter {
|
||||
}
|
||||
|
||||
dos.flush();
|
||||
dos.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
|
||||
* the given magic number and at least the given minimum version.
|
||||
*
|
||||
* @param magicNumber Magic number of files to be read.
|
||||
* @param minVersion Minimum version of files to be read.
|
||||
* @param dis Input stream from which to read.
|
||||
* @param minVersion Minimum version of files to be read.
|
||||
* @param dis Input stream from which to read.
|
||||
*/
|
||||
protected BinaryReader(int magicNumber, int minVersion, DataInputStream dis) {
|
||||
this.magicNumber = magicNumber;
|
||||
@ -44,7 +44,7 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
|
||||
* @param version Version to check.
|
||||
*
|
||||
* @throws BadVersionException if the given version is not greater than the
|
||||
* minimum version.
|
||||
* minimum version.
|
||||
*/
|
||||
protected void checkVersionOrThrow(int version) throws BadVersionException {
|
||||
if (version < this.minVersion) {
|
||||
@ -80,7 +80,7 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
|
||||
*
|
||||
* @param b Byte to check.
|
||||
*
|
||||
* @throws IOException if an error occurs while reading the byte.
|
||||
* @throws IOException if an error occurs while reading the byte.
|
||||
* @throws BadFormatException if the byte read is not the expected one.
|
||||
*/
|
||||
protected void checkByteOrThrow(int b) throws IOException {
|
||||
@ -93,7 +93,7 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
|
||||
* Read a byte array of fixed length from the input and convert it to a string
|
||||
* using the given charset, removing any trailing '\0'.
|
||||
*
|
||||
* @param length Number of bytes to read.
|
||||
* @param length Number of bytes to read.
|
||||
* @param charset Charset to use to convert the bytes into a string.
|
||||
*
|
||||
* @return The convert string.
|
||||
|
@ -15,12 +15,12 @@ public class MapMismatchException extends IOException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// Actual and expected map ID.
|
||||
private String actualMapId, expectedMapId;
|
||||
private final String actualMapId, expectedMapId;
|
||||
|
||||
/**
|
||||
* Create a new MapMismatchException with the given IDs.
|
||||
*
|
||||
* @param actualMapId Actual map ID found when reading the path.
|
||||
* @param actualMapId Actual map ID found when reading the path.
|
||||
* @param expectedMapId Expected map ID from the graph.
|
||||
*/
|
||||
public MapMismatchException(String actualMapId, String expectedMapId) {
|
||||
|
24
pom.xml
24
pom.xml
@ -18,18 +18,18 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
Loading…
Reference in New Issue
Block a user