[clean] Apply formatting and add formatter configuration.

This commit is contained in:
Mikael Capelle 2021-07-08 13:53:33 +02:00 committed by Mikael CAPELLE
parent 2f936d44ec
commit 730cda6426
86 changed files with 1460 additions and 1214 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ doc
*.jar
.settings
.classpath
.vscode
# Editor specific files and folders
*~

View File

@ -1,8 +1,5 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@ -62,10 +62,8 @@ public abstract class AbstractAlgorithm<Observer> {
}
/**
* Run the algorithm and return the solution.
*
* This methods internally time the call to doRun() and update the result of the
* call with the computed solving time.
* Run the algorithm and return the solution. This methods internally time the call
* to doRun() and update the result of the call with the computed solving time.
*
* @return The solution found by the algorithm (may not be a feasible solution).
*/
@ -79,8 +77,8 @@ public abstract class AbstractAlgorithm<Observer> {
/**
* Abstract method that should be implemented by child class.
*
* @return The solution found, must not be null (use an infeasible or unknown
* status if necessary).
* @return The solution found, must not be null (use an infeasible or unknown status
* if necessary).
*/
protected abstract AbstractSolution doRun();

View File

@ -5,10 +5,9 @@ import org.insa.graphs.model.Graph;
import org.insa.graphs.model.GraphStatistics;
/**
* Base class for algorithm input data classes. This class contains the basic
* data that are required by most graph algorithms, i.e. a graph, a mode (time /
* length) and a filter for the arc.
*
* Base class for algorithm input data classes. This class contains the basic data that
* are required by most graph algorithms, i.e. a graph, a mode (time / length) and a
* filter for the arc.
*/
public abstract class AbstractInputData {
@ -46,13 +45,11 @@ public abstract class AbstractInputData {
}
/**
* Retrieve the cost associated with the given arc according to the underlying
* arc inspector.
* Retrieve the cost associated with the given arc according to the underlying arc
* inspector.
*
* @param arc Arc for which cost should be retrieved.
*
* @return Cost for the given arc.
*
* @see ArcInspector
*/
public double getCost(Arc arc) {
@ -61,7 +58,6 @@ public abstract class AbstractInputData {
/**
* @return Mode associated with this input data.
*
* @see Mode
*/
public Mode getMode() {
@ -70,9 +66,9 @@ public abstract class AbstractInputData {
/**
* Retrieve the maximum speed associated with this input data, or
* {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is associated. The maximum
* speed associated with input data is different from the maximum speed
* associated with graph (accessible via {@link Graph#getGraphInformation()}).
* {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is associated. The maximum speed
* associated with input data is different from the maximum speed associated with
* graph (accessible via {@link Graph#getGraphInformation()}).
*
* @return The maximum speed for this inspector, or
* {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is set.
@ -85,9 +81,7 @@ public abstract class AbstractInputData {
* Check if the given arc is allowed for the filter corresponding to this input.
*
* @param arc Arc to check.
*
* @return true if the given arc is allowed.
*
* @see ArcInspector
*/
public boolean isAllowed(Arc arc) {

View File

@ -3,16 +3,14 @@ package org.insa.graphs.algorithm;
import java.time.Duration;
/**
* Base class for solution classes returned by the algorithm. This class
* contains the basic information that any solution should have: status of the
* solution (unknown, infeasible, etc.), solving time and the original input
* data.
* Base class for solution classes returned by the algorithm. This class contains the
* basic information that any solution should have: status of the solution (unknown,
* infeasible, etc.), solving time and the original input data.
*/
public abstract class AbstractSolution {
/**
* Possible status for a solution.
*
*/
public enum Status {
UNKNOWN, INFEASIBLE, FEASIBLE, OPTIMAL,
@ -39,7 +37,6 @@ public abstract class AbstractSolution {
}
/**
*
* @param data
* @param status
*/

View File

@ -5,9 +5,8 @@ import org.insa.graphs.model.Arc;
import org.insa.graphs.model.GraphStatistics;
/**
* This class can be used to indicate to an algorithm which arcs can be used and
* the costs of the usable arcs..
*
* This class can be used to indicate to an algorithm which arcs can be used and the
* costs of the usable arcs..
*/
public interface ArcInspector {
@ -15,7 +14,6 @@ public interface ArcInspector {
* Check if the given arc can be used (is allowed).
*
* @param arc Arc to check.
*
* @return true if the given arc is allowed.
*/
public boolean isAllowed(Arc arc);
@ -24,7 +22,6 @@ public interface ArcInspector {
* Find the cost of the given arc.
*
* @param arc Arc for which the cost should be returned.
*
* @return Cost of the arc.
*/
public double getCost(Arc arc);

View File

@ -52,9 +52,10 @@ public class ArcInspectorFactory {
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.MOTORCAR,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
@ -110,9 +111,10 @@ public class ArcInspectorFactory {
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.MOTORCAR,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
@ -141,15 +143,16 @@ public class ArcInspectorFactory {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.FOOT, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.FOOT,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getTravelTime(
Math.min(getMaximumSpeed(), arc.getRoadInformation().getMaximumSpeed()));
return arc.getTravelTime(Math.min(getMaximumSpeed(),
arc.getRoadInformation().getMaximumSpeed()));
}
@Override

View File

@ -2,7 +2,8 @@ package org.insa.graphs.algorithm.carpooling;
import org.insa.graphs.algorithm.AbstractAlgorithm;
public abstract class CarPoolingAlgorithm extends AbstractAlgorithm<CarPoolingObserver> {
public abstract class CarPoolingAlgorithm
extends AbstractAlgorithm<CarPoolingObserver> {
protected CarPoolingAlgorithm(CarPoolingData data) {
super(data);

View File

@ -2,7 +2,8 @@ package org.insa.graphs.algorithm.packageswitch;
import org.insa.graphs.algorithm.AbstractAlgorithm;
public abstract class PackageSwitchAlgorithm extends AbstractAlgorithm<PackageSwitchObserver> {
public abstract class PackageSwitchAlgorithm
extends AbstractAlgorithm<PackageSwitchObserver> {
/**
* Create a new PackageSwitchAlgorithm with the given data.

View File

@ -41,8 +41,8 @@ public class BellmanFordAlgorithm extends ShortestPathAlgorithm {
boolean found = false;
for (int i = 0; !found && i < nbNodes; ++i) {
found = true;
for (Node node: graph.getNodes()) {
for (Arc arc: node.getSuccessors()) {
for (Node node : graph.getNodes()) {
for (Arc arc : node.getSuccessors()) {
// Small test to check allowed roads...
if (!data.isAllowed(arc)) {
@ -54,14 +54,16 @@ public class BellmanFordAlgorithm extends ShortestPathAlgorithm {
double oldDistance = distances[arc.getDestination().getId()];
double newDistance = distances[node.getId()] + w;
if (Double.isInfinite(oldDistance) && Double.isFinite(newDistance)) {
if (Double.isInfinite(oldDistance)
&& Double.isFinite(newDistance)) {
notifyNodeReached(arc.getDestination());
}
// Check if new distances would be better, if so update...
if (newDistance < oldDistance) {
found = false;
distances[arc.getDestination().getId()] = distances[node.getId()] + w;
distances[arc.getDestination().getId()] =
distances[node.getId()] + w;
predecessorArcs[arc.getDestination().getId()] = arc;
}
}
@ -91,7 +93,8 @@ public class BellmanFordAlgorithm extends ShortestPathAlgorithm {
Collections.reverse(arcs);
// Create the final solution.
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs));
solution = new ShortestPathSolution(data, Status.OPTIMAL,
new Path(graph, arcs));
}
return solution;

View File

@ -3,7 +3,8 @@ package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.algorithm.AbstractAlgorithm;
import org.insa.graphs.model.Node;
public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPathObserver> {
public abstract class ShortestPathAlgorithm
extends AbstractAlgorithm<ShortestPathObserver> {
protected ShortestPathAlgorithm(ShortestPathData data) {
super(data);
@ -28,7 +29,7 @@ public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPa
* @param node Origin.
*/
public void notifyOriginProcessed(Node node) {
for (ShortestPathObserver obs: getObservers()) {
for (ShortestPathObserver obs : getObservers()) {
obs.notifyOriginProcessed(node);
}
}
@ -39,19 +40,19 @@ public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPa
* @param node Node that has been reached.
*/
public void notifyNodeReached(Node node) {
for (ShortestPathObserver obs: getObservers()) {
for (ShortestPathObserver obs : getObservers()) {
obs.notifyNodeReached(node);
}
}
/**
* Notify all observers that a node has been marked, i.e. its final value has
* been set.
* Notify all observers that a node has been marked, i.e. its final value has been
* set.
*
* @param node Node that has been marked.
*/
public void notifyNodeMarked(Node node) {
for (ShortestPathObserver obs: getObservers()) {
for (ShortestPathObserver obs : getObservers()) {
obs.notifyNodeMarked(node);
}
}
@ -62,7 +63,7 @@ public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPa
* @param node Destination.
*/
public void notifyDestinationReached(Node node) {
for (ShortestPathObserver obs: getObservers()) {
for (ShortestPathObserver obs : getObservers()) {
obs.notifyDestinationReached(node);
}
}

View File

@ -16,10 +16,11 @@ public class ShortestPathData extends AbstractInputData {
* @param graph Graph in which the path should be looked for.
* @param origin Origin node of the path.
* @param destination Destination node of the path.
* @param arcInspector Filter for arcs (used to allow only a specific set of
* arcs in the graph to be used).
* @param arcInspector Filter for arcs (used to allow only a specific set of arcs in
* the graph to be used).
*/
public ShortestPathData(Graph graph, Node origin, Node destination, ArcInspector arcInspector) {
public ShortestPathData(Graph graph, Node origin, Node destination,
ArcInspector arcInspector) {
super(graph, arcInspector);
this.origin = origin;
this.destination = destination;
@ -41,7 +42,7 @@ public class ShortestPathData extends AbstractInputData {
@Override
public String toString() {
return "Shortest-path from #" + origin.getId() + " to #" + destination.getId() + " ["
+ this.arcInspector.toString().toLowerCase() + "]";
return "Shortest-path from #" + origin.getId() + " to #" + destination.getId()
+ " [" + this.arcInspector.toString().toLowerCase() + "]";
}
}

View File

@ -4,34 +4,33 @@ import org.insa.graphs.model.Node;
public interface ShortestPathObserver {
/**
* Notify the observer that the origin has been processed.
*
* @param node Origin.
*/
public void notifyOriginProcessed(Node node);
/**
* Notify the observer that the origin has been processed.
*
* @param node Origin.
*/
public void notifyOriginProcessed(Node node);
/**
* Notify the observer that a node has been reached for the first
* time.
*
* @param node Node that has been reached.
*/
public void notifyNodeReached(Node node);
/**
* Notify the observer that a node has been reached for the first time.
*
* @param node Node that has been reached.
*/
public void notifyNodeReached(Node node);
/**
* Notify the observer that a node has been marked, i.e. its final
* value has been set.
*
* @param node Node that has been marked.
*/
public void notifyNodeMarked(Node node);
/**
* Notify the observer that a node has been marked, i.e. its final value has been
* set.
*
* @param node Node that has been marked.
*/
public void notifyNodeMarked(Node node);
/**
* Notify the observer that the destination has been reached.
*
* @param node Destination.
*/
public void notifyDestinationReached(Node node);
/**
* Notify the observer that the destination has been reached.
*
* @param node Destination.
*/
public void notifyDestinationReached(Node node);
}

View File

@ -11,8 +11,7 @@ public class ShortestPathSolution extends AbstractSolution {
private final Path path;
/**
* Create a new infeasible shortest-path solution for the given input and
* status.
* Create a new infeasible shortest-path solution for the given input and status.
*
* @param data Original input data for this solution.
* @param status Status of the solution (UNKNOWN / INFEASIBLE).
@ -51,15 +50,17 @@ public class ShortestPathSolution extends AbstractSolution {
String info = null;
if (!isFeasible()) {
info = String.format("No path found from node #%d to node #%d",
getInputData().getOrigin().getId(), getInputData().getDestination().getId());
getInputData().getOrigin().getId(),
getInputData().getDestination().getId());
}
else {
double cost = 0;
for (Arc arc: getPath().getArcs()) {
for (Arc arc : getPath().getArcs()) {
cost += getInputData().getCost(arc);
}
info = String.format("Found a path from node #%d to node #%d",
getInputData().getOrigin().getId(), getInputData().getDestination().getId());
getInputData().getOrigin().getId(),
getInputData().getDestination().getId());
if (getInputData().getMode() == Mode.LENGTH) {
info = String.format("%s, %.4f kilometers", info, cost / 1000.0);
}

View File

@ -3,10 +3,8 @@ package org.insa.graphs.algorithm.utils;
import java.util.ArrayList;
/**
* Implements a binary heap containing elements of type E.
*
* Note that all comparisons are based on the compareTo method, hence E must
* implement Comparable
* Implements a binary heap containing elements of type E. Note that all comparisons are
* based on the compareTo method, hence E must implement Comparable
*
* @author Mark Allen Weiss
* @author DLB
@ -74,9 +72,8 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
private void percolateUp(int index) {
E x = this.array.get(index);
for (; index > 0
&& x.compareTo(this.array.get(indexParent(index))) < 0; index = indexParent(
index)) {
for (; index > 0 && x.compareTo(this.array.get(indexParent(index))) < 0; index =
indexParent(index)) {
E moving_val = this.array.get(indexParent(index));
this.arraySet(index, moving_val);
}
@ -168,9 +165,8 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
/**
* Creates a multi-lines string representing a sorted view of this binary heap.
*
* @param maxElement Maximum number of elements to display. or {@code -1} to
* display all the elements.
*
* @param maxElement Maximum number of elements to display. or {@code -1} to display
* all the elements.
* @return a string containing a sorted view this binary heap.
*/
public String toStringSorted(int maxElement) {
@ -190,7 +186,6 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
* Creates a multi-lines string representing a tree view of this binary heap.
*
* @param maxDepth Maximum depth of the tree to display.
*
* @return a string containing a tree view of this binary heap.
*/
public String toStringTree(int maxDepth) {

View File

@ -7,7 +7,6 @@ public class BinaryHeapFormatter {
/**
* This class is used by {@link #toStringTree}, and simply contains three string
* accumulating. This is an immutable class.
*
*/
private static class Context {
@ -23,8 +22,8 @@ public class BinaryHeapFormatter {
/**
* Creaet a new {@code Context}.
*
* @param acu The accumulated string.
* @param margin The current margin.
* @param acu The accumulated string.
* @param margin The current margin.
* @param lastMargin The last margin used.
*/
public Context(String acu, String margin, String lastMargin) {
@ -37,7 +36,6 @@ public class BinaryHeapFormatter {
* Creates a new context by appending newlines to this context.
*
* @param n Number of newlines to append.
*
* @return a new context with {@code n} newlines appended.
*/
public Context appendNewlines(int n) {
@ -45,8 +43,8 @@ public class BinaryHeapFormatter {
return this;
}
else {
return (new Context(this.acu + "\n" + this.margin, this.margin, this.lastmargin)
.appendNewlines(n - 1));
return (new Context(this.acu + "\n" + this.margin, this.margin,
this.lastmargin).appendNewlines(n - 1));
}
}
@ -54,31 +52,31 @@ public class BinaryHeapFormatter {
* Creates a new context by appending the given string to this context.
*
* @param count Number of spaces to add to the margin, or {@code null} to use
* the length of the string.
* @param text String to append.
*
* the length of the string.
* @param text String to append.
* @return a new context with {@code text} appended.
*/
public Context appendText(Integer count, String text) {
int cnt = (count == null) ? text.length() : count;
final String spaces = new String(new char[cnt]).replace('\0', ' ');
return new Context(this.acu + text, this.margin + spaces, this.lastmargin + spaces);
return new Context(this.acu + text, this.margin + spaces,
this.lastmargin + spaces);
}
/**
* Creates a new context by appending a branch to this context.
*
* @param n Number of spaces to add to the margin, or {@code null} to use
* the length of the string.
* @param n Number of spaces to add to the margin, or {@code null} to use the
* length of the string.
* @param label Name of the branch.
*
* @return a new context with the branch appended.
*/
public Context appendBranch(Integer count, String label) {
final Context ctxt = this.appendText(count, label);
if (count == null) {
return new Context(ctxt.acu + "_", ctxt.margin + "|", ctxt.margin + " ");
return new Context(ctxt.acu + "_", ctxt.margin + "|",
ctxt.margin + " ");
}
else {
return new Context(ctxt.acu, ctxt.margin + "|", ctxt.margin + " ")
@ -89,8 +87,8 @@ public class BinaryHeapFormatter {
}
/*
* Input : ready to write the current node at the current context position.
* Output : the last character of acu is the last character of the current node.
* Input : ready to write the current node at the current context position. Output :
* the last character of acu is the last character of the current node.
*/
protected static <E extends Comparable<E>> Context toStringLoop(BinaryHeap<E> heap,
Context ctxt, int node, int max_depth) {
@ -122,13 +120,16 @@ public class BinaryHeapFormatter {
int child = childs.get(ch);
if (is_last) {
Context ctxt3 = new Context(ctxt2.acu, ctxt2.lastmargin, ctxt2.lastmargin);
ctxt2 = new Context(toStringLoop(heap, ctxt3.appendText(null, "___"), child,
max_depth - 1).acu, ctxt2.margin, ctxt2.lastmargin);
Context ctxt3 =
new Context(ctxt2.acu, ctxt2.lastmargin, ctxt2.lastmargin);
ctxt2 = new Context(toStringLoop(heap,
ctxt3.appendText(null, "___"), child, max_depth - 1).acu,
ctxt2.margin, ctxt2.lastmargin);
}
else {
ctxt2 = new Context(toStringLoop(heap, ctxt2.appendText(null, "___"), child,
max_depth - 1).acu, ctxt2.margin, ctxt2.lastmargin).appendNewlines(2);
ctxt2 = new Context(toStringLoop(heap,
ctxt2.appendText(null, "___"), child, max_depth - 1).acu,
ctxt2.margin, ctxt2.lastmargin).appendNewlines(2);
}
}
@ -137,28 +138,25 @@ public class BinaryHeapFormatter {
}
/**
* Creates a multi-lines string representing a tree view of the given binary
* heap.
* Creates a multi-lines string representing a tree view of the given binary heap.
*
* @param heap The binary heap to display.
* @param heap The binary heap to display.
* @param maxDepth Maximum depth of the tree to display.
*
* @return a string containing a tree view of the given binary heap.
*/
public static <E extends Comparable<E>> String toStringTree(BinaryHeap<E> heap, int maxDepth) {
public static <E extends Comparable<E>> String toStringTree(BinaryHeap<E> heap,
int maxDepth) {
final Context init_context = new Context(" ", " ", " ");
final Context result = toStringLoop(heap, init_context, 0, maxDepth);
return result.acu;
}
/**
* Creates a multi-lines string representing a sorted view of the given binary
* heap.
*
* @param heap The binary heap to display.
* @param maxElement Maximum number of elements to display. or {@code -1} to
* display all the elements.
* Creates a multi-lines string representing a sorted view of the given binary heap.
*
* @param heap The binary heap to display.
* @param maxElement Maximum number of elements to display. or {@code -1} to display
* all the elements.
* @return a string containing a sorted view the given binary heap.
*/
public static <E extends Comparable<E>> String toStringSorted(BinaryHeap<E> heap,
@ -174,7 +172,8 @@ public class BinaryHeapFormatter {
truncate = ", only " + max_elements + " elements are shown";
}
result += "======== Sorted HEAP (size = " + heap.size() + truncate + ") ========\n\n";
result += "======== Sorted HEAP (size = " + heap.size() + truncate
+ ") ========\n\n";
while (!copy.isEmpty() && max_elements-- != 0) {
result += copy.deleteMin() + "\n";

View File

@ -10,7 +10,6 @@ public class EmptyPriorityQueueException extends RuntimeException {
/**
*
*/
public EmptyPriorityQueueException() {
}
public EmptyPriorityQueueException() {}
}

View File

@ -1,16 +1,13 @@
package org.insa.graphs.algorithm.utils;
/**
* Interface representing a basic priority queue.
*
* Implementation should enforce the required complexity of each method.
*
* Interface representing a basic priority queue. Implementation should enforce the
* required complexity of each method.
*/
public interface PriorityQueue<E extends Comparable<E>> {
/**
* Check if the priority queue is empty.
*
* <p>
* <b>Complexity:</b> <i>O(1)</i>
* </p>
@ -21,7 +18,6 @@ public interface PriorityQueue<E extends Comparable<E>> {
/**
* Get the number of elements in this queue.
*
* <p>
* <b>Complexity:</b> <i>O(1)</i>
* </p>
@ -32,7 +28,6 @@ public interface PriorityQueue<E extends Comparable<E>> {
/**
* Insert the given element into the queue.
*
* <p>
* <b>Complexity:</b> <i>O(log n)</i>
* </p>
@ -43,7 +38,6 @@ public interface PriorityQueue<E extends Comparable<E>> {
/**
* Remove the given element from the priority queue.
*
* <p>
* <b>Complexity:</b> <i>O(log n)</i>
* </p>
@ -54,26 +48,22 @@ public interface PriorityQueue<E extends Comparable<E>> {
/**
* Retrieve (but not remove) the smallest item in the queue.
*
* <p>
* <b>Complexity:</b> <i>O(1)</i>
* </p>
*
* @return The smallest item in the queue.
*
* @throws EmptyPriorityQueueException if this queue is empty.
*/
public E findMin() throws EmptyPriorityQueueException;
/**
* Remove and return the smallest item from the priority queue.
*
* <p>
* <b>Complexity:</b> <i>O(log n)</i>
* </p>
*
* @return The smallest item in the queue.
*
* @throws EmptyPriorityQueueException if this queue is empty.
*/
public E deleteMin() throws EmptyPriorityQueueException;

View File

@ -6,25 +6,25 @@ import org.insa.graphs.model.Node;
public interface WeaklyConnectedComponentObserver {
/**
* Notify that the algorithm is entering a new component.
*
* @param curNode Starting node for the component.
*/
public void notifyStartComponent(Node curNode);
/**
* Notify that the algorithm is entering a new component.
*
* @param curNode Starting node for the component.
*/
public void notifyStartComponent(Node curNode);
/**
* Notify that a new node has been found for the current component.
*
* @param node New node found for the current component.
*/
public void notifyNewNodeInComponent(Node node);
/**
* Notify that a new node has been found for the current component.
*
* @param node New node found for the current component.
*/
public void notifyNewNodeInComponent(Node node);
/**
* Notify that the algorithm has computed a new component.
*
* @param nodes List of nodes in the component.
*/
public void notifyEndComponent(ArrayList<Node> nodes);
/**
* Notify that the algorithm has computed a new component.
*
* @param nodes List of nodes in the component.
*/
public void notifyEndComponent(ArrayList<Node> nodes);
}

View File

@ -5,32 +5,33 @@ import java.util.ArrayList;
import org.insa.graphs.model.Node;
public class WeaklyConnectedComponentTextObserver implements WeaklyConnectedComponentObserver {
public class WeaklyConnectedComponentTextObserver
implements WeaklyConnectedComponentObserver {
// Number of the current component.
private int numComponent = 1;
// Number of the current component.
private int numComponent = 1;
// Output stream
PrintStream stream;
// Output stream
PrintStream stream;
public WeaklyConnectedComponentTextObserver(PrintStream stream) {
this.stream = stream;
}
public WeaklyConnectedComponentTextObserver(PrintStream stream) {
this.stream = stream;
}
@Override
public void notifyStartComponent(Node curNode) {
stream.print("Entering component #" + numComponent + " from node #" + curNode.getId() + "... ");
}
@Override
public void notifyStartComponent(Node curNode) {
stream.print("Entering component #" + numComponent + " from node #"
+ curNode.getId() + "... ");
}
@Override
public void notifyNewNodeInComponent(Node node) {
}
@Override
public void notifyNewNodeInComponent(Node node) {}
@Override
public void notifyEndComponent(ArrayList<Node> nodes) {
stream.println(nodes.size() + " nodes found.");
stream.flush();
numComponent += 1;
}
@Override
public void notifyEndComponent(ArrayList<Node> nodes) {
stream.println(nodes.size() + " nodes found.");
stream.flush();
numComponent += 1;
}
}

View File

@ -38,19 +38,18 @@ public class WeaklyConnectedComponentsAlgorithm
* @param curNode Starting node for the component.
*/
protected void notifyStartComponent(Node curNode) {
for (WeaklyConnectedComponentObserver obs: getObservers()) {
for (WeaklyConnectedComponentObserver obs : getObservers()) {
obs.notifyStartComponent(curNode);
}
}
/**
* Notify all observers that a new node has been found for the current
* component.
* Notify all observers that a new node has been found for the current component.
*
* @param node New node found for the current component.
*/
protected void notifyNewNodeInComponent(Node node) {
for (WeaklyConnectedComponentObserver obs: getObservers()) {
for (WeaklyConnectedComponentObserver obs : getObservers()) {
obs.notifyNewNodeInComponent(node);
}
}
@ -61,7 +60,7 @@ public class WeaklyConnectedComponentsAlgorithm
* @param nodes List of nodes in the component.
*/
protected void notifyEndComponent(ArrayList<Node> nodes) {
for (WeaklyConnectedComponentObserver obs: getObservers()) {
for (WeaklyConnectedComponentObserver obs : getObservers()) {
obs.notifyEndComponent(nodes);
}
}
@ -77,8 +76,8 @@ public class WeaklyConnectedComponentsAlgorithm
res.add(new HashSet<Integer>());
}
for (Node node: getInputData().getGraph().getNodes()) {
for (Arc arc: node.getSuccessors()) {
for (Node node : getInputData().getGraph().getNodes()) {
for (Arc arc : node.getSuccessors()) {
res.get(node.getId()).add(arc.getDestination().getId());
if (arc.getRoadInformation().isOneWay()) {
res.get(arc.getDestination().getId()).add(node.getId());
@ -90,15 +89,15 @@ public class WeaklyConnectedComponentsAlgorithm
}
/**
* Apply a breadth first search algorithm on the given undirected graph
* (adjacency list), starting at node cur, and marking nodes in marked.
* Apply a breadth first search algorithm on the given undirected graph (adjacency
* list), starting at node cur, and marking nodes in marked.
*
* @param marked
* @param cur
*
* @return
*/
protected ArrayList<Node> bfs(ArrayList<HashSet<Integer>> ugraph, boolean[] marked, int cur) {
protected ArrayList<Node> bfs(ArrayList<HashSet<Integer>> ugraph, boolean[] marked,
int cur) {
Graph graph = getInputData().getGraph();
ArrayList<Node> component = new ArrayList<Node>();
@ -118,7 +117,7 @@ public class WeaklyConnectedComponentsAlgorithm
// Notify observers
notifyNewNodeInComponent(node);
for (Integer destId: ugraph.get(node.getId())) {
for (Integer destId : ugraph.get(node.getId())) {
Node dest = graph.get(destId);
if (!marked[dest.getId()]) {
queue.add(destId);
@ -149,11 +148,11 @@ public class WeaklyConnectedComponentsAlgorithm
components.add(this.bfs(ugraph, marked, cur));
// Find next non-marked
for (; cur < marked.length && marked[cur]; ++cur)
;
for (; cur < marked.length && marked[cur]; ++cur);
}
return new WeaklyConnectedComponentsSolution(getInputData(), Status.OPTIMAL, components);
return new WeaklyConnectedComponentsSolution(getInputData(), Status.OPTIMAL,
components);
}
}

View File

@ -14,8 +14,8 @@ public class WeaklyConnectedComponentsSolution extends AbstractSolution {
super(data);
}
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data, Status status,
ArrayList<ArrayList<Node>> components) {
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data,
Status status, ArrayList<ArrayList<Node>> components) {
super(data, status);
this.components = components;
}
@ -41,7 +41,7 @@ public class WeaklyConnectedComponentsSolution extends AbstractSolution {
public String toString() {
int nIsolated = 0;
int nGt10 = 0;
for (ArrayList<Node> component: components) {
for (ArrayList<Node> component : components) {
if (component.size() == 1) {
nIsolated += 1;
}
@ -49,8 +49,9 @@ public class WeaklyConnectedComponentsSolution extends AbstractSolution {
nGt10 += 1;
}
}
return "Found " + components.size() + " components (" + nGt10 + " with more than 10 nodes, "
+ nIsolated + " isolated nodes) in " + getSolvingTime().getSeconds() + " seconds.";
return "Found " + components.size() + " components (" + nGt10
+ " with more than 10 nodes, " + nIsolated + " isolated nodes) in "
+ getSolvingTime().getSeconds() + " seconds.";
}

View File

@ -8,7 +8,8 @@ public class BinaryHeapTest extends PriorityQueueTest {
}
@Override
public PriorityQueue<MutableInteger> createQueue(PriorityQueue<MutableInteger> queue) {
public PriorityQueue<MutableInteger> createQueue(
PriorityQueue<MutableInteger> queue) {
return new BinaryHeap<>((BinaryHeap<MutableInteger>) queue);
}

View File

@ -8,7 +8,8 @@ public class BinarySearchTreeTest extends PriorityQueueTest {
}
@Override
public PriorityQueue<MutableInteger> createQueue(PriorityQueue<MutableInteger> queue) {
public PriorityQueue<MutableInteger> createQueue(
PriorityQueue<MutableInteger> queue) {
return new BinarySearchTree<>((BinarySearchTree<MutableInteger>) queue);
}

View File

@ -35,10 +35,10 @@ public abstract class PriorityQueueTest {
* implementation.
*
* @param queue Queue to copy.
*
* @return Copy of the given queue.
*/
public abstract PriorityQueue<MutableInteger> createQueue(PriorityQueue<MutableInteger> queue);
public abstract PriorityQueue<MutableInteger> createQueue(
PriorityQueue<MutableInteger> queue);
protected static class MutableInteger implements Comparable<MutableInteger> {
@ -92,7 +92,6 @@ public abstract class PriorityQueueTest {
/**
* Set of parameters.
*
*/
@Parameters
public static Collection<Object> data() {
@ -102,30 +101,31 @@ public abstract class PriorityQueueTest {
objects.add(new TestParameters<>(new MutableInteger[0], new int[0]));
// Queue with 50 elements from 0 to 49, inserted in order and deleted in order.
objects.add(new TestParameters<>(
IntStream.range(0, 50).mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
IntStream.range(0, 50).toArray()));
objects.add(
new TestParameters<>(
IntStream.range(0, 50).mapToObj(MutableInteger::new)
.toArray(MutableInteger[]::new),
IntStream.range(0, 50).toArray()));
// Queue with 20 elements from 0 to 19, inserted in order, deleted in the given
// order.
objects.add(new TestParameters<>(
IntStream.range(0, 20).mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[] { 12, 17, 18, 19, 4, 5, 3, 2, 0, 9, 10, 16, 8, 14, 13, 15, 7, 6, 1,
11 }));
IntStream.range(0, 20).mapToObj(MutableInteger::new)
.toArray(MutableInteger[]::new),
new int[] { 12, 17, 18, 19, 4, 5, 3, 2, 0, 9, 10, 16, 8, 14, 13, 15, 7,
6, 1, 11 }));
// Queue with 7 elements.
objects.add(
new TestParameters<>(
Arrays.stream(new int[] { 8, 1, 6, 3, 4, 5, 9 })
.mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[] { 6, 5, 0, 1, 4, 2, 3 }));
objects.add(new TestParameters<>(
Arrays.stream(new int[] { 8, 1, 6, 3, 4, 5, 9 })
.mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[] { 6, 5, 0, 1, 4, 2, 3 }));
// Queue with 7 elements.
objects.add(
new TestParameters<>(
Arrays.stream(new int[] { 1, 7, 4, 8, 9, 6, 5 })
.mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[] { 2, 0, 1, 3, 4, 5, 6 }));
objects.add(new TestParameters<>(
Arrays.stream(new int[] { 1, 7, 4, 8, 9, 6, 5 })
.mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[] { 2, 0, 1, 3, 4, 5, 6 }));
// Queue with 13 elements.
objects.add(new TestParameters<>(
@ -147,7 +147,7 @@ public abstract class PriorityQueueTest {
// Create the range queue
this.queue = createQueue();
for (MutableInteger v: parameters.data) {
for (MutableInteger v : parameters.data) {
this.queue.insert(v);
}
}
@ -166,7 +166,7 @@ public abstract class PriorityQueueTest {
public void testInsert() {
PriorityQueue<MutableInteger> queue = createQueue();
int size = 0;
for (MutableInteger x: parameters.data) {
for (MutableInteger x : parameters.data) {
queue.insert(x);
assertEquals(++size, queue.size());
}
@ -174,7 +174,7 @@ public abstract class PriorityQueueTest {
MutableInteger[] range = Arrays.copyOf(parameters.data, parameters.data.length);
Arrays.sort(range);
for (MutableInteger mi: range) {
for (MutableInteger mi : range) {
assertEquals(mi.get(), queue.deleteMin().value);
assertEquals(--size, queue.size());
}
@ -189,7 +189,8 @@ public abstract class PriorityQueueTest {
@Test
public void testFindMin() {
Assume.assumeFalse(queue.isEmpty());
assertEquals(Collections.min(Arrays.asList(parameters.data)).get(), queue.findMin().get());
assertEquals(Collections.min(Arrays.asList(parameters.data)).get(),
queue.findMin().get());
}
@Test(expected = EmptyPriorityQueueException.class)
@ -204,7 +205,7 @@ public abstract class PriorityQueueTest {
assertEquals(size, queue.size());
MutableInteger[] range = Arrays.copyOf(parameters.data, parameters.data.length);
Arrays.sort(range);
for (MutableInteger x: range) {
for (MutableInteger x : range) {
assertEquals(x, queue.deleteMin());
size -= 1;
assertEquals(size, queue.size());
@ -259,7 +260,7 @@ public abstract class PriorityQueueTest {
@Test
public void testRemoveTwice() {
Assume.assumeFalse(queue.isEmpty());
for (MutableInteger data: parameters.data) {
for (MutableInteger data : parameters.data) {
PriorityQueue<MutableInteger> copyQueue = this.createQueue(this.queue);
copyQueue.remove(data);
try {
@ -307,7 +308,7 @@ public abstract class PriorityQueueTest {
public void testRemoveThenAdd() {
Assume.assumeFalse(queue.isEmpty());
int min = Collections.min(Arrays.asList(parameters.data)).get();
for (MutableInteger mi: parameters.data) {
for (MutableInteger mi : parameters.data) {
queue.remove(mi);
assertEquals(parameters.data.length - 1, queue.size());
mi.set(--min);

View File

@ -1,8 +1,5 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.insa.graphs</groupId>

View File

@ -57,8 +57,8 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
private final boolean graphicVisualization;
private final boolean textualVisualization;
public StartActionEvent(Class<? extends AbstractAlgorithm<?>> algoClass, List<Node> nodes,
ArcInspector arcFilter, boolean graphicVisualization,
public StartActionEvent(Class<? extends AbstractAlgorithm<?>> algoClass,
List<Node> nodes, ArcInspector arcFilter, boolean graphicVisualization,
boolean textualVisualization) {
super(AlgorithmPanel.this, START_EVENT_ID, START_EVENT_COMMAND);
this.nodes = nodes;
@ -125,18 +125,17 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
/**
* Create a new AlgorithmPanel with the given parameters.
*
* @param parent Parent component for this panel. Only use for centering
* dialogs.
* @param parent Parent component for this panel. Only use for centering dialogs.
* @param baseAlgorithm Base algorithm for this algorithm panel.
* @param title Title of the panel.
* @param nodeNames Names of the input nodes.
* @param enableArcFilterSelection <code>true</code> to enable
* {@link ArcInspector} selection.
*
* @param enableArcFilterSelection <code>true</code> to enable {@link ArcInspector}
* selection.
* @see ArcInspectorFactory
*/
public AlgorithmPanel(Component parent, Class<? extends AbstractAlgorithm<?>> baseAlgorithm,
String title, String[] nodeNames, boolean enableArcFilterSelection) {
public AlgorithmPanel(Component parent,
Class<? extends AbstractAlgorithm<?>> baseAlgorithm, String title,
String[] nodeNames, boolean enableArcFilterSelection) {
super();
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
@ -217,7 +216,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
startAlgoButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (ActionListener lis: startActionListeners) {
for (ActionListener lis : startActionListeners) {
lis.actionPerformed(new StartActionEvent(
AlgorithmFactory.getAlgorithmClass(baseAlgorithm,
(String) algoSelect.getSelectedItem()),
@ -280,7 +279,6 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
* Create the title JLabel for this panel.
*
* @param title Title for the label.
*
* @return A new JLabel containing the given title with proper font.
*/
protected JLabel createTitleLabel(String title) {
@ -297,17 +295,14 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
/**
* Create the combo box for the algorithm selection.
*
* @param baseAlgorithm Base algorithm for which the select box should be
* created.
*
* @param baseAlgorithm Base algorithm for which the select box should be created.
* @return A new JComboBox containing algorithms for the given base algorithm.
*
* @see AlgorithmFactory
*/
protected JComboBox<String> createAlgoritmSelectComboBox(
Class<? extends AbstractAlgorithm<?>> baseAlgorithm) {
JComboBox<String> algoSelect = new JComboBox<>(
AlgorithmFactory.getAlgorithmNames(baseAlgorithm).toArray(new String[0]));
JComboBox<String> algoSelect = new JComboBox<>(AlgorithmFactory
.getAlgorithmNames(baseAlgorithm).toArray(new String[0]));
algoSelect.setBackground(Color.WHITE);
algoSelect.setAlignmentX(Component.LEFT_ALIGNMENT);
return algoSelect;
@ -318,7 +313,6 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
* Create a node input panel with the given node input names.
*
* @param nodeNames Field names for the inputs to create.
*
* @return A new NodesInputPanel containing inputs for the given names.
*/
protected NodesInputPanel createNodesInputPanel(String[] nodeNames) {
@ -332,17 +326,15 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
}
/**
* Check if the given list of nodes does not contain any <code>null</code>
* value.
* Check if the given list of nodes does not contain any <code>null</code> value.
*
* @param nodes List of {@link Node} to check.
*
* @return <code>true</code> if the list does not contain any <code>null</code>
* value, <code>false</code> otherwise.
*/
protected boolean allNotNull(List<Node> nodes) {
boolean allNotNull = true;
for (Node node: nodes) {
for (Node node : nodes) {
allNotNull = allNotNull && node != null;
}
return allNotNull;
@ -353,7 +345,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
super.setEnabled(enabled);
nodesInputPanel.setEnabled(enabled);
solutionPanel.setEnabled(enabled);
for (JComponent component: components) {
for (JComponent component : components) {
component.setEnabled(enabled);
}
graphicObserverCheckbox.setEnabled(enabled);
@ -371,11 +363,9 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
}
@Override
public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
}
public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {}
@Override
public void onRedrawRequest() {
}
public void onRedrawRequest() {}
}

View File

@ -7,17 +7,15 @@ public interface DrawingChangeListener {
/**
* Event fired when a new drawing is loaded.
*
* @param oldDrawing Old drawing, may be null if no drawing exits prior to this
* one.
* @param oldDrawing Old drawing, may be null if no drawing exits prior to this one.
* @param newDrawing New drawing.
*/
public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing);
/**
* Event fired when a redraw request is emitted - This is typically emitted
* after a onDrawingLoaded event, but not always, and request that elements are
* drawn again on the new drawing.
*
* Event fired when a redraw request is emitted - This is typically emitted after a
* onDrawingLoaded event, but not always, and request that elements are drawn again
* on the new drawing.
*/
public void onRedrawRequest();

View File

@ -21,7 +21,6 @@ import org.insa.graphs.model.io.GraphReaderObserver;
* JProgressBar.
*
* @author Mikael
*
*/
public class GraphReaderProgressBar extends JDialog implements GraphReaderObserver {
@ -37,7 +36,7 @@ public class GraphReaderProgressBar extends JDialog implements GraphReaderObserv
private final JProgressBar[] progressBars = new JProgressBar[3];
// Current element read, and modulo.
private int[] counters = new int[]{ 0, 0, 0 };
private int[] counters = new int[] { 0, 0, 0 };
private int[] modulos = new int[3];
public GraphReaderProgressBar(JFrame owner) {

View File

@ -162,7 +162,8 @@ public class MainWindow extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
StartActionEvent evt = (StartActionEvent) e;
WeaklyConnectedComponentsData data = new WeaklyConnectedComponentsData(graph);
WeaklyConnectedComponentsData data =
new WeaklyConnectedComponentsData(graph);
WeaklyConnectedComponentsAlgorithm wccAlgorithm = null;
try {
@ -181,10 +182,12 @@ public class MainWindow extends JFrame {
wccPanel.setEnabled(false);
if (evt.isGraphicVisualizationEnabled()) {
wccAlgorithm.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
wccAlgorithm.addObserver(
new WeaklyConnectedComponentGraphicObserver(drawing));
}
if (evt.isTextualVisualizationEnabled()) {
wccAlgorithm.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
wccAlgorithm.addObserver(
new WeaklyConnectedComponentTextObserver(printStream));
}
// We love Java...
@ -207,8 +210,9 @@ public class MainWindow extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
StartActionEvent evt = (StartActionEvent) e;
ShortestPathData data = new ShortestPathData(graph, evt.getNodes().get(0),
evt.getNodes().get(1), evt.getArcFilter());
ShortestPathData data =
new ShortestPathData(graph, evt.getNodes().get(0),
evt.getNodes().get(1), evt.getArcFilter());
ShortestPathAlgorithm spAlgorithm = null;
try {
@ -254,12 +258,15 @@ public class MainWindow extends JFrame {
}
});
cpPanel = new AlgorithmPanel(this, CarPoolingAlgorithm.class, "Car-Pooling", new String[] {
"Origin Car", "Origin Pedestrian", "Destination Car", "Destination Pedestrian" },
cpPanel = new AlgorithmPanel(this, CarPoolingAlgorithm.class, "Car-Pooling",
new String[] { "Origin Car", "Origin Pedestrian", "Destination Car",
"Destination Pedestrian" },
true);
psPanel = new AlgorithmPanel(this, PackageSwitchAlgorithm.class, "Car-Pooling",
new String[] { "Oribin A", "Origin B", "Destination A", "Destination B" }, true);
psPanel = new AlgorithmPanel(
this, PackageSwitchAlgorithm.class, "Car-Pooling", new String[] {
"Oribin A", "Origin B", "Destination A", "Destination B" },
true);
// add algorithm panels
algoPanels.add(wccPanel);
@ -271,7 +278,7 @@ public class MainWindow extends JFrame {
// Add click listeners to both drawing.
for (AlgorithmPanel panel: algoPanels) {
for (AlgorithmPanel panel : algoPanels) {
this.basicDrawing.addDrawingClickListener(panel.nodesInputPanel);
this.mapViewDrawing.addDrawingClickListener(panel.nodesInputPanel);
this.graphChangeListeneres.add(panel.nodesInputPanel);
@ -294,10 +301,12 @@ public class MainWindow extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = FileUtils.createFileChooser(FolderType.Map);
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
if (chooser.showOpenDialog(
MainWindow.this) == JFileChooser.APPROVE_OPTION) {
graphFilePath = chooser.getSelectedFile().getAbsolutePath();
// Note: Don't use a try-resources block since loadGraph is asynchronous.
// Note: Don't use a try-resources block since loadGraph is
// asynchronous.
final DataInputStream stream;
try {
stream = new DataInputStream(new BufferedInputStream(
@ -329,8 +338,8 @@ public class MainWindow extends JFrame {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int confirmed = JOptionPane.showConfirmDialog(MainWindow.this,
"Are you sure you want to close the application?", "Exit Confirmation",
JOptionPane.YES_NO_OPTION);
"Are you sure you want to close the application?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION);
if (confirmed == JOptionPane.YES_OPTION) {
dispose();
@ -360,7 +369,7 @@ public class MainWindow extends JFrame {
rightComponent.add(pathPanel, c);
c.gridy = 1;
for (AlgorithmPanel panel: algoPanels) {
for (AlgorithmPanel panel : algoPanels) {
panel.setVisible(false);
rightComponent.add(panel, c);
}
@ -428,7 +437,7 @@ public class MainWindow extends JFrame {
* Notify all listeners that a new graph has been loaded.
*/
private void notifyNewGraphLoaded() {
for (GraphChangeListener listener: graphChangeListeneres) {
for (GraphChangeListener listener : graphChangeListeneres) {
listener.newGraphLoaded(graph);
}
}
@ -440,7 +449,7 @@ public class MainWindow extends JFrame {
* @param newDrawing
*/
private void notifyDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
for (DrawingChangeListener listener: drawingChangeListeners) {
for (DrawingChangeListener listener : drawingChangeListeners) {
listener.onDrawingLoaded(oldDrawing, newDrawing);
}
}
@ -449,7 +458,7 @@ public class MainWindow extends JFrame {
* Notify all listeners that a redraw request is emitted.
*/
private void notifyRedrawRequest() {
for (DrawingChangeListener listener: drawingChangeListeners) {
for (DrawingChangeListener listener : drawingChangeListeners) {
listener.onRedrawRequest();
}
}
@ -478,8 +487,9 @@ public class MainWindow extends JFrame {
// We need to draw MapView, we have to check if the file exists.
File mfile = null;
if (isMapView) {
String mfpath = graphFilePath.substring(0, graphFilePath.lastIndexOf(".map"))
+ ".mapfg";
String mfpath =
graphFilePath.substring(0, graphFilePath.lastIndexOf(".map"))
+ ".mapfg";
mfile = new File(mfpath);
if (!mfile.exists()) {
if (JOptionPane.showConfirmDialog(this,
@ -576,7 +586,8 @@ public class MainWindow extends JFrame {
launchThread(new Runnable() {
@Override
public void run() {
GraphReaderProgressBar progressBar = new GraphReaderProgressBar(MainWindow.this);
GraphReaderProgressBar progressBar =
new GraphReaderProgressBar(MainWindow.this);
progressBar.setLocationRelativeTo(mainPanel.getLeftComponent());
reader.addObserver(progressBar);
try {
@ -601,19 +612,20 @@ public class MainWindow extends JFrame {
String info = graph.getMapId();
if (graph.getMapName() != null && !graph.getMapName().isEmpty()) {
// The \u200e character is the left-to-right mark, we need to avoid issue with
// The \u200e character is the left-to-right mark, we need to avoid
// issue with
// name that are right-to-left (e.g. arabic names).
info += " - " + graph.getMapName() + "\u200e";
}
info += ", " + graph.size() + " nodes, " + graph.getGraphInformation().getArcCount()
+ " arcs.";
info += ", " + graph.size() + " nodes, "
+ graph.getGraphInformation().getArcCount() + " arcs.";
graphInfoPanel.setText(info);
drawGraph();
notifyNewGraphLoaded();
for (JMenuItem item: graphLockItems) {
for (JMenuItem item : graphLockItems) {
item.setEnabled(true);
}
}
@ -627,7 +639,7 @@ public class MainWindow extends JFrame {
*/
private void enableAlgorithmPanel(AlgorithmPanel algorithmPanel) {
int dividerLocation = mainPanel.getDividerLocation();
for (AlgorithmPanel panel: algoPanels) {
for (AlgorithmPanel panel : algoPanels) {
panel.setVisible(panel == algorithmPanel);
}
mainPanel.setDividerLocation(dividerLocation);
@ -637,20 +649,25 @@ public class MainWindow extends JFrame {
// Open Map item...
JMenuItem openMapItem = new JMenuItem("Open Map... ", KeyEvent.VK_O);
openMapItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
openMapItem.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
openMapItem.addActionListener(baf.createBlockingAction(openMapActionListener));
// Open Path item...
JMenuItem openPathItem = new JMenuItem("Open Path... ", KeyEvent.VK_P);
openPathItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK));
openPathItem.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK));
openPathItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = FileUtils.createFileChooser(FolderType.PathInput);
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
try (BinaryPathReader reader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(
new FileInputStream(chooser.getSelectedFile()))))){
JFileChooser chooser =
FileUtils.createFileChooser(FolderType.PathInput);
if (chooser.showOpenDialog(
MainWindow.this) == JFileChooser.APPROVE_OPTION) {
try (BinaryPathReader reader = new BinaryPathReader(
new DataInputStream(new BufferedInputStream(
new FileInputStream(chooser.getSelectedFile()))))) {
Path path = reader.readPath(graph);
pathPanel.addPath(path);
}
@ -673,7 +690,8 @@ public class MainWindow extends JFrame {
// Close item
JMenuItem closeItem = new JMenuItem("Quit", KeyEvent.VK_Q);
closeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
closeItem.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
closeItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -691,7 +709,8 @@ public class MainWindow extends JFrame {
// Second menu
JMenuItem drawGraphItem = new JMenuItem("Redraw", KeyEvent.VK_R);
drawGraphItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
drawGraphItem.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
drawGraphItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -700,23 +719,26 @@ public class MainWindow extends JFrame {
}));
graphLockItems.add(drawGraphItem);
JMenuItem drawGraphBWItem = new JMenuItem("Redraw (B&W)", KeyEvent.VK_B);
drawGraphBWItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.ALT_MASK));
drawGraphBWItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
drawGraph(BasicDrawing.class, blackAndWhitePalette);
}
}));
drawGraphBWItem.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.ALT_MASK));
drawGraphBWItem
.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
drawGraph(BasicDrawing.class, blackAndWhitePalette);
}
}));
graphLockItems.add(drawGraphBWItem);
JMenuItem drawGraphMapsforgeItem = new JMenuItem("Redraw (Map)", KeyEvent.VK_M);
drawGraphMapsforgeItem.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.ALT_MASK));
drawGraphMapsforgeItem
.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.ALT_MASK));
drawGraphMapsforgeItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
drawGraph(MapViewDrawing.class);
}
}));
.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
drawGraph(MapViewDrawing.class);
}
}));
graphLockItems.add(drawGraphMapsforgeItem);
JMenu graphMenu = new JMenu("Graph");
@ -782,7 +804,7 @@ public class MainWindow extends JFrame {
menuBar.add(graphMenu);
menuBar.add(algoMenu);
for (JMenuItem item: graphLockItems) {
for (JMenuItem item : graphLockItems) {
item.setEnabled(false);
}
@ -792,9 +814,9 @@ public class MainWindow extends JFrame {
private JPanel createStatusBar() {
// create the status bar panel and shove it down the bottom of the frame
JPanel statusPanel = new JPanel();
statusPanel.setBorder(
new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
new EmptyBorder(0, 15, 0, 15)));
statusPanel.setBorder(new CompoundBorder(
BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
new EmptyBorder(0, 15, 0, 15)));
statusPanel.setPreferredSize(new Dimension(getWidth(), 38));
statusPanel.setLayout(new BorderLayout());

View File

@ -40,9 +40,7 @@ public class NodesInputPanel extends JPanel
private static final Color DEFAULT_MARKER_COLOR = Color.BLUE;
/**
* Utility class that can be used to find a node from coordinates in a "fast"
* way.
*
* Utility class that can be used to find a node from coordinates in a "fast" way.
*/
private static class NodeFinder {
@ -58,14 +56,13 @@ public class NodesInputPanel extends JPanel
/**
* @param point
*
* @return the closest node to the given point, or null if no node is "close
* enough".
*/
public Node findClosestNode(Point point) {
Node minNode = null;
double minDis = Double.POSITIVE_INFINITY;
for (Node node: graph.getNodes()) {
for (Node node : graph.getNodes()) {
double dlon = point.getLongitude() - node.getPoint().getLongitude();
double dlat = point.getLatitude() - node.getPoint().getLatitude();
double dis = dlon * dlon + dlat * dlat; // No need to square
@ -81,7 +78,6 @@ public class NodesInputPanel extends JPanel
/**
* Event data send when a node input has changed.
*
*/
public class InputChangedEvent extends ActionEvent {
@ -98,7 +94,8 @@ public class NodesInputPanel extends JPanel
List<Node> nodes;
public InputChangedEvent(List<Node> nodes2) {
super(NodesInputPanel.this, ALL_INPUT_FILLED_EVENT_ID, ALL_INPUT_FILLED_EVENT_COMMAND);
super(NodesInputPanel.this, ALL_INPUT_FILLED_EVENT_ID,
ALL_INPUT_FILLED_EVENT_COMMAND);
this.nodes = nodes2;
}
@ -110,7 +107,8 @@ public class NodesInputPanel extends JPanel
// Node inputs and markers.
private final ArrayList<JTextField> nodeInputs = new ArrayList<>();
private final Map<JTextField, MarkerOverlay> markerTrackers = new IdentityHashMap<JTextField, MarkerOverlay>();
private final Map<JTextField, MarkerOverlay> markerTrackers =
new IdentityHashMap<JTextField, MarkerOverlay>();
// Component that can be enabled/disabled.
private ArrayList<JComponent> components = new ArrayList<>();
@ -126,7 +124,6 @@ public class NodesInputPanel extends JPanel
/**
* Create a new NodesInputPanel.
*
*/
public NodesInputPanel() {
super(new GridBagLayout());
@ -134,12 +131,11 @@ public class NodesInputPanel extends JPanel
}
/**
* Add an InputChanged listener to this panel. This listener will be notified by
* a {@link InputChangedEvent} each time an input in this panel change (click,
* clear, manual input).
* Add an InputChanged listener to this panel. This listener will be notified by a
* {@link InputChangedEvent} each time an input in this panel change (click, clear,
* manual input).
*
* @param listener Listener to add.
*
* @see InputChangedEvent
*/
public void addInputChangedListener(ActionListener listener) {
@ -149,7 +145,7 @@ public class NodesInputPanel extends JPanel
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
for (JTextField input: nodeInputs) {
for (JTextField input : nodeInputs) {
MarkerOverlay marker = markerTrackers.getOrDefault(input, null);
if (marker != null) {
marker.setVisible(visible && !input.getText().trim().isEmpty());
@ -159,7 +155,7 @@ public class NodesInputPanel extends JPanel
@Override
public void setEnabled(boolean enabled) {
for (JComponent component: components) {
for (JComponent component : components) {
component.setEnabled(enabled);
}
super.setEnabled(enabled);
@ -176,7 +172,7 @@ public class NodesInputPanel extends JPanel
}
public void clear() {
for (JTextField field: nodeInputs) {
for (JTextField field : nodeInputs) {
field.setText("");
markerTrackers.put(field, null);
}
@ -248,8 +244,8 @@ public class NodesInputPanel extends JPanel
MarkerOverlay tracker = markerTrackers.getOrDefault(textField, null);
if (curnode != null) {
if (tracker == null) {
tracker = drawing.drawMarker(curnode.getPoint(), markerColor, Color.BLACK,
AlphaMode.TRANSPARENT);
tracker = drawing.drawMarker(curnode.getPoint(), markerColor,
Color.BLACK, AlphaMode.TRANSPARENT);
markerTrackers.put(textField, tracker);
}
else {
@ -268,7 +264,7 @@ public class NodesInputPanel extends JPanel
List<Node> nodes = getNodeForInputs();
// Trigger change event.
for (ActionListener lis: inputChangeListeners) {
for (ActionListener lis : inputChangeListeners) {
lis.actionPerformed(new InputChangedEvent(nodes));
}
}
@ -317,20 +313,20 @@ public class NodesInputPanel extends JPanel
}
/**
* @return List of nodes associated with the input. Some nodes may be null if
* their associated input is invalid.
* @return List of nodes associated with the input. Some nodes may be null if their
* associated input is invalid.
*/
public List<Node> getNodeForInputs() {
List<Node> nodes = new ArrayList<>(nodeInputs.size());
for (JTextField input: nodeInputs) {
for (JTextField input : nodeInputs) {
nodes.add(getNodeForInput(input));
}
return nodes;
}
/**
* Get the next input that should be filled by a click, or null if none should
* be filled.
* Get the next input that should be filled by a click, or null if none should be
* filled.
*
* @return
*/
@ -410,7 +406,7 @@ public class NodesInputPanel extends JPanel
@Override
public void onRedrawRequest() {
for (JTextField input: nodeInputs) {
for (JTextField input : nodeInputs) {
MarkerOverlay tracker = markerTrackers.getOrDefault(input, null);
if (tracker != null) {
MarkerOverlay newMarker = this.drawing.drawMarker(tracker.getPoint(),

View File

@ -41,7 +41,8 @@ import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Path;
import org.insa.graphs.model.io.BinaryPathWriter;
public class PathsPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
public class PathsPanel extends JPanel
implements DrawingChangeListener, GraphChangeListener {
/**
*
@ -57,7 +58,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
/**
* Simple icon that represents a unicolor rectangle.
*
*/
protected class ColorIcon implements Icon {
@ -105,9 +105,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
* corresponding to the path.
*
* @param path Path for this bundle, must not be null.
*
* @throws IOException If a resource was not found.
*
*/
public PathPanel(Path path, Color color) throws IOException {
super();
@ -181,21 +179,24 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
chooser.getSelectionModel().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
icon.setColor(chooser.getSelectionModel().getSelectedColor());
icon.setColor(
chooser.getSelectionModel().getSelectedColor());
colorButton.repaint();
overlay.setColor(chooser.getSelectionModel().getSelectedColor());
overlay.setColor(
chooser.getSelectionModel().getSelectedColor());
overlay.redraw();
}
});
JColorChooser.createDialog(getTopLevelAncestor(), "Pick a new color", true,
chooser, new ActionListener() {
JColorChooser.createDialog(getTopLevelAncestor(),
"Pick a new color", true, chooser, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
icon.setColor(chooser.getSelectionModel().getSelectedColor());
icon.setColor(chooser.getSelectionModel()
.getSelectedColor());
colorButton.repaint();
overlay.setColor(
chooser.getSelectionModel().getSelectedColor());
overlay.setColor(chooser.getSelectionModel()
.getSelectedColor());
overlay.redraw();
}
}, new ActionListener() {
@ -206,14 +207,14 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
overlay.setColor(originalColor);
overlay.redraw();
}
}).setVisible(true);
;
}).setVisible(true);;
}
});
Image saveImg = ImageIO.read(getClass().getResourceAsStream("/save-icon.png"))
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
Image saveImg =
ImageIO.read(getClass().getResourceAsStream("/save-icon.png"))
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
JButton saveButton = new JButton(new ImageIcon(saveImg));
saveButton.setFocusPainted(false);
saveButton.setFocusable(false);
@ -224,16 +225,18 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
@Override
public void actionPerformed(ActionEvent e) {
String filepath = String.format("path_%s_%d_%d.path",
path.getGraph().getMapId().toLowerCase().replaceAll("[^a-z0-9_]", ""),
path.getGraph().getMapId().toLowerCase()
.replaceAll("[^a-z0-9_]", ""),
path.getOrigin().getId(), path.getDestination().getId());
JFileChooser chooser = FileUtils.createFileChooser(FolderType.PathOutput,
filepath);
JFileChooser chooser = FileUtils
.createFileChooser(FolderType.PathOutput, filepath);
if (chooser
.showSaveDialog(getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
if (chooser.showSaveDialog(
getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try (BinaryPathWriter writer = new BinaryPathWriter(new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(file))))) {
try (BinaryPathWriter writer = new BinaryPathWriter(
new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(file))))) {
writer.writePath(path);
}
catch (IOException e1) {
@ -245,8 +248,9 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
}
});
Image newimg = ImageIO.read(getClass().getResourceAsStream("/delete-icon.png"))
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
Image newimg =
ImageIO.read(getClass().getResourceAsStream("/delete-icon.png"))
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
JButton deleteButton = new JButton(new ImageIcon(newimg));
deleteButton.setFocusPainted(false);
deleteButton.setFocusable(false);
@ -273,7 +277,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
/**
* Re-draw the current overlay (if any) on the new drawing.
*
*/
public void updateOverlay() {
PathOverlay oldOverlay = this.overlay;
@ -312,7 +315,8 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
public void addPath(Path path) {
try {
this.add(new PathPanel(path, ColorUtils.getColor(this.getComponentCount())));
this.add(
new PathPanel(path, ColorUtils.getColor(this.getComponentCount())));
this.setVisible(true);
this.revalidate();
this.repaint();
@ -333,7 +337,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
@Override
public void newGraphLoaded(Graph graph) {
for (Component c: this.getComponents()) {
for (Component c : this.getComponents()) {
if (c instanceof PathPanel) {
((PathPanel) c).overlay.delete();
}
@ -351,7 +355,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
@Override
public void onRedrawRequest() {
for (Component c: this.getComponents()) {
for (Component c : this.getComponents()) {
if (c instanceof PathPanel) {
((PathPanel) c).updateOverlay();
}

View File

@ -26,7 +26,8 @@ import org.insa.graphs.gui.drawing.overlays.PathOverlay;
import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Path;
public class SolutionPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
public class SolutionPanel extends JPanel
implements DrawingChangeListener, GraphChangeListener {
/**
*
@ -46,7 +47,6 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
* corresponding to the solution (if the solution is feasible).
*
* @param solution Solution for this bundle, must not be null.
*
*/
public SolutionBundle(AbstractSolution solution, boolean createOverlays) {
this.solution = solution;
@ -85,7 +85,6 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
/**
* Re-draw the current overlay (if any) on the new drawing.
*
*/
public void updateOverlays() {
if (this.overlays.isEmpty()) {
@ -102,7 +101,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
List<PathOverlay> overlays = new ArrayList<>();
if (solution.isFeasible()) {
Method[] methods = this.solution.getClass().getDeclaredMethods();
for (Method method: methods) {
for (Method method : methods) {
if (method.getReturnType().equals(Path.class)
&& method.getParameterCount() == 0) {
try {
@ -145,7 +144,8 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
public SolutionPanel(Component parent) {
super();
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
setBorder(new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.LIGHT_GRAY),
setBorder(new CompoundBorder(
BorderFactory.createMatteBorder(1, 0, 1, 0, Color.LIGHT_GRAY),
new EmptyBorder(10, 0, 10, 0)));
solutionSelect = new JComboBox<>();
@ -167,7 +167,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
@Override
public void actionPerformed(ActionEvent e) {
for (PathOverlay overlay: currentBundle.getOverlays()) {
for (PathOverlay overlay : currentBundle.getOverlays()) {
if (overlay.isVisible()) {
overlay.setVisible(false);
clearButton.setText("Show");
@ -193,21 +193,23 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
public void actionPerformed(ActionEvent e) {
if (currentBundle != null) {
for (PathOverlay overlay: currentBundle.getOverlays()) {
for (PathOverlay overlay : currentBundle.getOverlays()) {
overlay.setVisible(false);
}
}
SolutionBundle bundle = (SolutionBundle) solutionSelect.getSelectedItem();
SolutionBundle bundle =
(SolutionBundle) solutionSelect.getSelectedItem();
if (bundle != null) {
updateInformationLabel(bundle);
buttonPanel
.setVisible(bundle.getSolution().isFeasible() && bundle.hasOverlays());
clearButton.setText(bundle.getSolution().isFeasible() ? "Hide" : "Show");
buttonPanel.setVisible(
bundle.getSolution().isFeasible() && bundle.hasOverlays());
clearButton.setText(
bundle.getSolution().isFeasible() ? "Hide" : "Show");
for (PathOverlay overlay: bundle.getOverlays()) {
for (PathOverlay overlay : bundle.getOverlays()) {
overlay.setVisible(true);
}
}
@ -226,8 +228,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
* Add the given solution to the panel.
*
* @param solution the solution to add to the panel
* @param createOverlays Whether or not overlay should be created for this
* solution.
* @param createOverlays Whether or not overlay should be created for this solution.
*/
public void addSolution(AbstractSolution solution, boolean createOverlays) {
SolutionBundle bundle = new SolutionBundle(solution, createOverlays);
@ -251,9 +252,10 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
solutionSelect.setSelectedItem(currentBundle);
}
else {
SolutionBundle bundle = (SolutionBundle) this.solutionSelect.getSelectedItem();
SolutionBundle bundle =
(SolutionBundle) this.solutionSelect.getSelectedItem();
if (bundle != null) {
for (PathOverlay overlay: bundle.getOverlays()) {
for (PathOverlay overlay : bundle.getOverlays()) {
overlay.setVisible(false);
}
}
@ -263,7 +265,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
@Override
public void newGraphLoaded(Graph graph) {
for (int i = 0; i < this.solutionSelect.getItemCount(); ++i) {
for (PathOverlay overlay: this.solutionSelect.getItemAt(i).getOverlays()) {
for (PathOverlay overlay : this.solutionSelect.getItemAt(i).getOverlays()) {
overlay.delete();
}
}

View File

@ -17,28 +17,28 @@ public class BasicGraphPalette implements GraphPalette {
public Color getColorForArc(Arc arc) {
RoadType type = arc.getRoadInformation().getType();
switch (type) {
case MOTORWAY:
return MOTORWAY_COLOR;
case TRUNK:
case PRIMARY:
case SECONDARY:
case MOTORWAY_LINK:
case TRUNK_LINK:
case PRIMARY_LINK:
return BIG_ROAD_COLOR;
case SECONDARY_LINK:
case TERTIARY:
case RESIDENTIAL:
case UNCLASSIFIED:
case LIVING_STREET:
case SERVICE:
case ROUNDABOUT:
case PEDESTRIAN:
case CYCLEWAY:
case TRACK:
return SMALL_ROAD_COLOR;
case COASTLINE:
return COASTLINE_COLOR;
case MOTORWAY:
return MOTORWAY_COLOR;
case TRUNK:
case PRIMARY:
case SECONDARY:
case MOTORWAY_LINK:
case TRUNK_LINK:
case PRIMARY_LINK:
return BIG_ROAD_COLOR;
case SECONDARY_LINK:
case TERTIARY:
case RESIDENTIAL:
case UNCLASSIFIED:
case LIVING_STREET:
case SERVICE:
case ROUNDABOUT:
case PEDESTRIAN:
case CYCLEWAY:
case TRACK:
return SMALL_ROAD_COLOR;
case COASTLINE:
return COASTLINE_COLOR;
}
return Color.BLACK;
@ -49,32 +49,32 @@ public class BasicGraphPalette implements GraphPalette {
RoadType type = arc.getRoadInformation().getType();
int width = 1;
switch (type) {
case MOTORWAY:
width = 2;
break;
case TRUNK:
case PRIMARY:
case SECONDARY:
case MOTORWAY_LINK:
case TRUNK_LINK:
case PRIMARY_LINK:
width = 1;
break;
case SECONDARY_LINK:
case TERTIARY:
case RESIDENTIAL:
case UNCLASSIFIED:
case LIVING_STREET:
case SERVICE:
case ROUNDABOUT:
case PEDESTRIAN:
case CYCLEWAY:
case TRACK:
width = 1;
break;
case COASTLINE:
width = 4;
break;
case MOTORWAY:
width = 2;
break;
case TRUNK:
case PRIMARY:
case SECONDARY:
case MOTORWAY_LINK:
case TRUNK_LINK:
case PRIMARY_LINK:
width = 1;
break;
case SECONDARY_LINK:
case TERTIARY:
case RESIDENTIAL:
case UNCLASSIFIED:
case LIVING_STREET:
case SERVICE:
case ROUNDABOUT:
case PEDESTRIAN:
case CYCLEWAY:
case TRACK:
width = 1;
break;
case COASTLINE:
width = 4;
break;
}
return width;
}

View File

@ -7,8 +7,9 @@ import org.insa.graphs.model.Arc;
public class BlackAndWhiteGraphPalette extends BasicGraphPalette {
// Road colors (index
private final static Color[] ROAD_COLOR_FROM_WIDTH = { null, new Color(140, 140, 140),
new Color(80, 80, 80), new Color(40, 40, 40), new Color(30, 30, 30) };
private final static Color[] ROAD_COLOR_FROM_WIDTH =
{ null, new Color(140, 140, 140), new Color(80, 80, 80),
new Color(40, 40, 40), new Color(30, 30, 30) };
@Override
public Color getColorForArc(Arc arc) {

View File

@ -12,8 +12,8 @@ import org.insa.graphs.model.Point;
public interface Drawing {
/**
* Available fill mode for the creation of markers, see the documentation of
* each value for more details.
* Available fill mode for the creation of markers, see the documentation of each
* value for more details.
*/
enum AlphaMode {
@ -53,37 +53,34 @@ public interface Drawing {
public void clearOverlays();
/**
* Draw a marker at the given position using the given colors and according to
* the given mode.
* Draw a marker at the given position using the given colors and according to the
* given mode.
*
* @param point Position of the marker to draw.
* @param outer Color for the outer part of the marker to draw.
* @param inner Color for the inner part of the marker to draw.
* @param mode Mode for filling the inner par of the marker.
*
* @return A MarkerOverlay instance representing the newly drawn marker.
*/
public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode);
public MarkerOverlay drawMarker(Point point, Color outer, Color inner,
AlphaMode mode);
/**
* Create a new PointSetOverlay that can be used to add overlay points to this
* drawing.
*
* PointSetOverlay are heavy memory resources, do not use one for each point!
* drawing. PointSetOverlay are heavy memory resources, do not use one for each
* point!
*
* @return A new PointSetOverlay for this drawing.
*/
public PointSetOverlay createPointSetOverlay();
/**
* Create a new PointSetOverlay with the given initial width and color that can
* be used to add overlay points to this drawing.
*
* PointSetOverlay are heavy memory resources, do not use one for each point!
* Create a new PointSetOverlay with the given initial width and color that can be
* used to add overlay points to this drawing. PointSetOverlay are heavy memory
* resources, do not use one for each point!
*
* @param width Initial width of points in the overlay.
* @param color Initial width of points in the overlay.
*
* @return A new PointSetOverlay for this drawing.
*/
public PointSetOverlay createPointSetOverlay(int width, Color color);
@ -93,7 +90,6 @@ public interface Drawing {
*
* @param graph Graph to draw.
* @param palette Palette to use to draw the graph.
*
* @see BasicGraphPalette
* @see BlackAndWhiteGraphPalette
*/
@ -112,7 +108,6 @@ public interface Drawing {
* @param path Path to draw.
* @param color Color of the path to draw.
* @param markers true to show origin and destination markers.
*
* @return A PathOverlay instance representing the newly drawn path.
*/
public PathOverlay drawPath(Path path, Color color, boolean markers);
@ -122,9 +117,7 @@ public interface Drawing {
*
* @param path Path to draw.
* @param color Color of the path to draw.
*
* @return A PathOverlay instance representing the newly drawn path.
*
* @see Drawing#drawPath(Path, Color, boolean)
*/
public PathOverlay drawPath(Path path, Color color);
@ -134,9 +127,7 @@ public interface Drawing {
*
* @param path Path to draw.
* @param markers true to show origin and destination markers.
*
* @return A PathOverlay instance representing the newly drawn path.
*
* @see Drawing#drawPath(Path, Color, boolean)
*/
public PathOverlay drawPath(Path path, boolean markers);
@ -145,11 +136,8 @@ public interface Drawing {
* Draw a path with both origin and destination markers using a default color
* specific to the implementation
*
*
* @param path Path to draw.
*
* @return A PathOverlay instance representing the newly drawn path.
*
* @see Drawing#drawPath(Path, Color, boolean)
*/
public PathOverlay drawPath(Path path);

View File

@ -8,14 +8,12 @@ public interface GraphPalette {
/**
* @param arc Arc for which color should be retrieved.
*
* @return Color associated with the given arc.
*/
public Color getColorForArc(Arc arc);
/**
* @param arc Arc for which width should be retrieved.
*
* @return Width associated with the given arc.
*/
public int getWidthForArc(Arc arc);

View File

@ -30,8 +30,8 @@ public class MercatorProjection implements Projection {
* maxSize.
*
* @param boundingBox Box for this projection.
* @param maxSize Maximum size of any side (width / height) of the image to
* which this projection should draw.
* @param maxSize Maximum size of any side (width / height) of the image to which
* this projection should draw.
*/
public MercatorProjection(BoundingBox boundingBox, int maxSize) {
// Find minimum/maximum longitude and latitude.
@ -53,7 +53,6 @@ public class MercatorProjection implements Projection {
* Compute the projection (without scaling) of the given latitude.
*
* @param latitude Latitude to project.
*
* @return Projection of the given latitude (without scaling).
*/
private static double projectY(double latitude) {
@ -62,11 +61,10 @@ public class MercatorProjection implements Projection {
}
/**
* Compute the dimension required for drawing a projection of the given box on
* an image, ensuring that none of the side of image is greater than maxSize.
* Compute the dimension required for drawing a projection of the given box on an
* image, ensuring that none of the side of image is greater than maxSize.
*
* @param maxSize Maximum side of any side of the image.
*
* @return Dimension corresponding to the preferred size for the image.
*/
protected Dimension computeImageSize(int maxSize) {
@ -97,7 +95,8 @@ public class MercatorProjection implements Projection {
@Override
public int longitudeToPixelX(float longitude) {
return (int) (width * (longitude - minLongitude) / (maxLongitude - minLongitude));
return (int) (width * (longitude - minLongitude)
/ (maxLongitude - minLongitude));
}
@Override

View File

@ -15,8 +15,8 @@ public class PlateCarreProjection implements Projection {
* maxSize.
*
* @param boundingBox Box for this projection.
* @param maxSize Maximum size of any side (width / height) of the image to
* which this projection should draw.
* @param maxSize Maximum size of any side (width / height) of the image to which
* this projection should draw.
*/
public PlateCarreProjection(BoundingBox boundingBox, int maxSize) {
// Find minimum/maximum longitude and latitude.
@ -25,7 +25,8 @@ public class PlateCarreProjection implements Projection {
this.minLatitude = boundingBox.getBottomRightPoint().getLatitude();
this.maxLatitude = boundingBox.getTopLeftPoint().getLatitude();
float diffLon = maxLongitude - minLongitude, diffLat = maxLatitude - minLatitude;
float diffLon = maxLongitude - minLongitude,
diffLat = maxLatitude - minLatitude;
this.width = diffLon < diffLat ? (int) (maxSize * diffLon / diffLat) : maxSize;
this.height = diffLon < diffLat ? maxSize : (int) (maxSize * diffLat / diffLon);

View File

@ -16,7 +16,6 @@ public interface Projection {
* Project the given latitude on the image.
*
* @param latitude Latitude to project.
*
* @return Projected position of the latitude on the image.
*/
public int latitudeToPixelY(float latitude);
@ -25,7 +24,6 @@ public interface Projection {
* Project the given longitude on the image.
*
* @param longitude Longitude to project.
*
* @return Projected position of the longitude on the image.
*/
public int longitudeToPixelX(float longitude);
@ -34,7 +32,6 @@ public interface Projection {
* Retrieve the latitude associated to the given projected point.
*
* @param py Projected y-position for which latitude should be retrieved.
*
* @return The original latitude of the point.
*/
public float pixelYToLatitude(double py);
@ -43,7 +40,6 @@ public interface Projection {
* Retrieve the longitude associated to the given projected point.
*
* @param px Projected x-position for which longitude should be retrieved.
*
* @return The original longitude of the point.
*/
public float pixelXToLongitude(double px);

View File

@ -125,7 +125,8 @@ public class BasicDrawing extends JPanel implements Drawing {
private Color innerColor;
private final AlphaMode alphaMode;
public BasicMarkerOverlay(Point point, Color color, Color inner, AlphaMode alphaMode) {
public BasicMarkerOverlay(Point point, Color color, Color inner,
AlphaMode alphaMode) {
super(color);
this.point = point;
this.image = MarkerUtils.getMarkerForColor(color, inner, alphaMode);
@ -146,7 +147,8 @@ public class BasicDrawing extends JPanel implements Drawing {
public void setColor(Color color) {
this.innerColor = this.innerColor.equals(this.color) ? color : innerColor;
super.setColor(color);
this.image = MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
this.image =
MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
}
@Override
@ -161,8 +163,8 @@ public class BasicDrawing extends JPanel implements Drawing {
int px = projection.longitudeToPixelX(getPoint().getLongitude());
int py = projection.latitudeToPixelY(getPoint().getLatitude());
graphics.drawImage(this.image, px - MARKER_WIDTH / 2, py - MARKER_HEIGHT, MARKER_WIDTH,
MARKER_HEIGHT, BasicDrawing.this);
graphics.drawImage(this.image, px - MARKER_WIDTH / 2, py - MARKER_HEIGHT,
MARKER_WIDTH, MARKER_HEIGHT, BasicDrawing.this);
}
};
@ -175,8 +177,8 @@ public class BasicDrawing extends JPanel implements Drawing {
// Origin / Destination markers.
private BasicMarkerOverlay origin, destination;
public BasicPathOverlay(List<Point> points, Color color, BasicMarkerOverlay origin,
BasicMarkerOverlay destination) {
public BasicPathOverlay(List<Point> points, Color color,
BasicMarkerOverlay origin, BasicMarkerOverlay destination) {
super(color);
this.points = points;
this.origin = origin;
@ -244,8 +246,8 @@ public class BasicDrawing extends JPanel implements Drawing {
public BasicPointSetOverlay() {
super(Color.BLACK);
this.image = new BufferedImage(BasicDrawing.this.width, BasicDrawing.this.height,
BufferedImage.TYPE_4BYTE_ABGR);
this.image = new BufferedImage(BasicDrawing.this.width,
BasicDrawing.this.height, BufferedImage.TYPE_4BYTE_ABGR);
this.graphics = image.createGraphics();
this.graphics.setBackground(new Color(0, 0, 0, 0));
}
@ -307,7 +309,6 @@ public class BasicDrawing extends JPanel implements Drawing {
/**
* Class encapsulating a set of overlays.
*
*/
private class BasicOverlays {
@ -316,8 +317,8 @@ public class BasicDrawing extends JPanel implements Drawing {
public synchronized void draw(Graphics2D g) {
// Clear overlays.
for (ArrayList<BasicOverlay> arr: this.overlays) {
for (BasicOverlay overlay: arr) {
for (ArrayList<BasicOverlay> arr : this.overlays) {
for (BasicOverlay overlay : arr) {
overlay.draw(g);
}
}
@ -334,7 +335,7 @@ public class BasicDrawing extends JPanel implements Drawing {
public void clear(boolean repaint) {
// Clear overlays.
for (ArrayList<BasicOverlay> arr: this.overlays) {
for (ArrayList<BasicOverlay> arr : this.overlays) {
arr.clear();
}
// Repaint if requested.
@ -397,7 +398,6 @@ public class BasicDrawing extends JPanel implements Drawing {
/**
* Create a new BasicDrawing.
*
*/
public BasicDrawing() {
setLayout(null);
@ -440,7 +440,7 @@ public class BasicDrawing extends JPanel implements Drawing {
catch (NoninvertibleTransformException e) {
return;
}
for (DrawingClickListener listener: drawingClickListeners) {
for (DrawingClickListener listener : drawingClickListeners) {
listener.mouseClicked(lonlat);
}
}
@ -510,14 +510,12 @@ public class BasicDrawing extends JPanel implements Drawing {
* MouseEvent.
*
* @param event MouseEvent from which longitude/latitude should be retrieved.
*
* @return Point representing the projection of the MouseEvent position in the
* graph/map.
*
* @throws NoninvertibleTransformException if the actual transformation is
* invalid.
* @throws NoninvertibleTransformException if the actual transformation is invalid.
*/
protected Point getLongitudeLatitude(MouseEvent event) throws NoninvertibleTransformException {
protected Point getLongitudeLatitude(MouseEvent event)
throws NoninvertibleTransformException {
// Get the point using the inverse transform of the Zoom/Pan object, this gives
// us
// a point within the drawing box (between [0, 0] and [width, height]).
@ -532,8 +530,7 @@ public class BasicDrawing extends JPanel implements Drawing {
/*
* (non-Javadoc)
*
* @see
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
* @see org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
* drawing.DrawingClickListener)
*/
@Override
@ -552,13 +549,16 @@ public class BasicDrawing extends JPanel implements Drawing {
this.drawingClickListeners.remove(listener);
}
public BasicMarkerOverlay createMarker(Point point, Color outer, Color inner, AlphaMode mode) {
public BasicMarkerOverlay createMarker(Point point, Color outer, Color inner,
AlphaMode mode) {
return new BasicMarkerOverlay(point, outer, inner, mode);
}
@Override
public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
return (MarkerOverlay) this.overlays.add(createMarker(point, outer, inner, mode));
public MarkerOverlay drawMarker(Point point, Color outer, Color inner,
AlphaMode mode) {
return (MarkerOverlay) this.overlays
.add(createMarker(point, outer, inner, mode));
}
@Override
@ -577,15 +577,16 @@ public class BasicDrawing extends JPanel implements Drawing {
* Draw the given arc.
*
* @param arc Arc to draw.
* @param palette Palette to use to retrieve color and width for arc, or null to
* use current settings.
* @param palette Palette to use to retrieve color and width for arc, or null to use
* current settings.
*/
protected void drawArc(Arc arc, GraphPalette palette, boolean repaint) {
List<Point> pts = arc.getPoints();
if (!pts.isEmpty()) {
if (palette != null) {
this.graphGraphics.setColor(palette.getColorForArc(arc));
this.graphGraphics.setStroke(new BasicStroke(palette.getWidthForArc(arc)));
this.graphGraphics
.setStroke(new BasicStroke(palette.getWidthForArc(arc)));
}
Iterator<Point> it1 = pts.iterator();
Point prev = it1.next();
@ -633,7 +634,8 @@ public class BasicDrawing extends JPanel implements Drawing {
// Special projection for non-realistic maps...
if (graph.getMapId().startsWith("0x")) {
projection = new PlateCarreProjection(extendedBox, MAXIMUM_DRAWING_WIDTH / 4);
projection =
new PlateCarreProjection(extendedBox, MAXIMUM_DRAWING_WIDTH / 4);
}
else {
projection = new MercatorProjection(extendedBox, MAXIMUM_DRAWING_WIDTH);
@ -679,8 +681,8 @@ public class BasicDrawing extends JPanel implements Drawing {
this.removeMouseMotionListener(zoomAndPanListener);
this.removeMouseWheelListener(zoomAndPanListener);
for (Node node: graph.getNodes()) {
for (Arc arc: node.getSuccessors()) {
for (Node node : graph.getNodes()) {
for (Arc arc : node.getSuccessors()) {
// Draw arcs only if there are one-way arcs or if origin is lower than
// destination, avoid drawing two-ways arc twice.
if (arc.getRoadInformation().isOneWay()
@ -710,7 +712,7 @@ public class BasicDrawing extends JPanel implements Drawing {
List<Point> points = new ArrayList<Point>();
if (!path.isEmpty()) {
points.add(path.getOrigin().getPoint());
for (Arc arc: path.getArcs()) {
for (Arc arc : path.getArcs()) {
Iterator<Point> itPoint = arc.getPoints().iterator();
// Discard origin each time
itPoint.next();
@ -721,7 +723,8 @@ public class BasicDrawing extends JPanel implements Drawing {
}
BasicMarkerOverlay origin = null, destination = null;
if (markers && !path.isEmpty()) {
origin = createMarker(path.getOrigin().getPoint(), color, color, AlphaMode.TRANSPARENT);
origin = createMarker(path.getOrigin().getPoint(), color, color,
AlphaMode.TRANSPARENT);
destination = createMarker(path.getDestination().getPoint(), color, color,
AlphaMode.TRANSPARENT);
}

View File

@ -62,7 +62,6 @@ public class MapViewDrawing extends MapView implements Drawing {
/**
* Base Overlay for MapViewDrawing overlays.
*
*/
private abstract class MapViewOverlay implements Overlay {
@ -74,7 +73,7 @@ public class MapViewDrawing extends MapView implements Drawing {
public MapViewOverlay(Layer[] layers, Color color) {
this.layers = layers;
for (Layer layer: this.layers) {
for (Layer layer : this.layers) {
MapViewDrawing.this.getLayerManager().getLayers().add(layer);
}
this.color = color;
@ -92,7 +91,7 @@ public class MapViewDrawing extends MapView implements Drawing {
@Override
public void setVisible(boolean visible) {
for (Layer layer: layers) {
for (Layer layer : layers) {
layer.setVisible(visible);
}
}
@ -108,7 +107,7 @@ public class MapViewDrawing extends MapView implements Drawing {
@Override
public void delete() {
Layers mlayers = MapViewDrawing.this.getLayerManager().getLayers();
for (Layer layer: layers) {
for (Layer layer : layers) {
mlayers.remove(layer);
}
}
@ -121,7 +120,6 @@ public class MapViewDrawing extends MapView implements Drawing {
/**
* MarkerOverlay for MapViewDrawing.
*
*/
private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay {
@ -144,10 +142,12 @@ public class MapViewDrawing extends MapView implements Drawing {
@Override
public void setColor(Color outer) {
this.innerColor = this.innerColor.equals(this.color) ? outer : this.innerColor;
this.innerColor =
this.innerColor.equals(this.color) ? outer : this.innerColor;
super.setColor(color);
MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0];
marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor, this.alphaMode));
marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor,
this.alphaMode));
}
@Override
@ -163,7 +163,6 @@ public class MapViewDrawing extends MapView implements Drawing {
/**
* PathOverlay for MapViewDrawing.
*
*/
private class MapViewPathOverlay extends MapViewOverlay implements PathOverlay {
@ -180,19 +179,19 @@ public class MapViewDrawing extends MapView implements Drawing {
public void setColor(Color color) {
super.setColor(color);
((PolylineAutoScaling) this.layers[0]).setColor(color);
((MarkerAutoScaling) this.layers[1])
.setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
((MarkerAutoScaling) this.layers[2])
.setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
((MarkerAutoScaling) this.layers[1]).setImage(
MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
((MarkerAutoScaling) this.layers[2]).setImage(
MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
}
}
/**
* PointSetOverlay for MapViewDrawing - Not currently implemented.
*
*/
private class MapViewPointSetOverlay extends MapViewOverlay implements PointSetOverlay {
private class MapViewPointSetOverlay extends MapViewOverlay
implements PointSetOverlay {
private List<Point> points = new ArrayList<>();
private final Polygon polygon;
@ -205,8 +204,9 @@ public class MapViewDrawing extends MapView implements Drawing {
List<Point> h = new ArrayList<>();
// lower hull
for (Point pt: p) {
while (h.size() >= 2 && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
for (Point pt : p) {
while (h.size() >= 2
&& !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
h.remove(h.size() - 1);
}
h.add(pt);
@ -216,7 +216,8 @@ public class MapViewDrawing extends MapView implements Drawing {
int t = h.size() + 1;
for (int i = p.size() - 1; i >= 0; i--) {
Point pt = p.get(i);
while (h.size() >= t && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
while (h.size() >= t
&& !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
h.remove(h.size() - 1);
}
h.add(pt);
@ -228,13 +229,14 @@ public class MapViewDrawing extends MapView implements Drawing {
// ccw returns true if the three points make a counter-clockwise turn
private boolean ccw(Point a, Point b, Point c) {
return ((b.getLongitude() - a.getLongitude())
* (c.getLatitude() - a.getLatitude())) > ((b.getLatitude() - a.getLatitude())
return ((b.getLongitude() - a.getLongitude()) * (c.getLatitude()
- a.getLatitude())) > ((b.getLatitude() - a.getLatitude())
* (c.getLongitude() - a.getLongitude()));
}
public MapViewPointSetOverlay() {
super(new Layer[] { new Polygon(GRAPHIC_FACTORY.createPaint(), null, GRAPHIC_FACTORY) },
super(new Layer[] {
new Polygon(GRAPHIC_FACTORY.createPaint(), null, GRAPHIC_FACTORY) },
Color.BLACK);
polygon = (Polygon) this.layers[0];
}
@ -242,13 +244,12 @@ public class MapViewDrawing extends MapView implements Drawing {
@Override
public void setColor(Color color) {
super.setColor(color);
polygon.getPaintFill().setColor(GRAPHIC_FACTORY.createColor(100, color.getRed(),
color.getGreen(), color.getBlue()));
polygon.getPaintFill().setColor(GRAPHIC_FACTORY.createColor(100,
color.getRed(), color.getGreen(), color.getBlue()));
}
@Override
public void setWidth(int width) {
}
public void setWidth(int width) {}
@Override
public void setWidthAndColor(int width, Color color) {
@ -260,8 +261,9 @@ public class MapViewDrawing extends MapView implements Drawing {
public void addPoint(Point point) {
points.add(point);
this.points = convexHull(points);
polygon.setPoints(this.points.stream().map(MapViewDrawing.this::convertPoint)
.collect(Collectors.toList()));
polygon.setPoints(
this.points.stream().map(MapViewDrawing.this::convertPoint)
.collect(Collectors.toList()));
polygon.requestRedraw();
}
@ -347,7 +349,8 @@ public class MapViewDrawing extends MapView implements Drawing {
public void paint(Graphics graphics) {
super.paint(graphics);
if (this.zoomControls != null) {
this.zoomControls.setZoomLevel(this.getModel().mapViewPosition.getZoomLevel());
this.zoomControls
.setZoomLevel(this.getModel().mapViewPosition.getZoomLevel());
this.zoomControls.draw((Graphics2D) graphics,
getWidth() - this.zoomControls.getWidth() - 20,
this.getHeight() - this.zoomControls.getHeight() - 10, this);
@ -374,8 +377,9 @@ public class MapViewDrawing extends MapView implements Drawing {
@Override
public void clearOverlays() {
Layers layers = getLayerManager().getLayers();
for (Layer layer: layers) {
if (layer instanceof PolylineAutoScaling || layer instanceof MarkerAutoScaling) {
for (Layer layer : layers) {
if (layer instanceof PolylineAutoScaling
|| layer instanceof MarkerAutoScaling) {
getLayerManager().getLayers().remove(layer, false);
}
}
@ -389,22 +393,25 @@ public class MapViewDrawing extends MapView implements Drawing {
private TileRendererLayer createTileRendererLayer(TileCache tileCache,
MapDataStore mapDataStore, IMapViewPosition mapViewPosition,
HillsRenderConfig hillsRenderConfig) {
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
@Override
public boolean onTap(LatLong tapLatLong, org.mapsforge.core.model.Point layerXY,
org.mapsforge.core.model.Point tapXY) {
if (zoomControls.contains(new java.awt.Point((int) tapXY.x, (int) tapXY.y))) {
return false;
}
Point pt = new Point((float) tapLatLong.getLongitude(),
(float) tapLatLong.getLatitude());
for (DrawingClickListener listener: MapViewDrawing.this.drawingClickListeners) {
listener.mouseClicked(pt);
}
return true;
}
};
TileRendererLayer tileRendererLayer =
new TileRendererLayer(tileCache, mapDataStore, mapViewPosition, false,
true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
@Override
public boolean onTap(LatLong tapLatLong,
org.mapsforge.core.model.Point layerXY,
org.mapsforge.core.model.Point tapXY) {
if (zoomControls.contains(
new java.awt.Point((int) tapXY.x, (int) tapXY.y))) {
return false;
}
Point pt = new Point((float) tapLatLong.getLongitude(),
(float) tapLatLong.getLatitude());
for (DrawingClickListener listener : MapViewDrawing.this.drawingClickListeners) {
listener.mouseClicked(pt);
}
return true;
}
};
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.DEFAULT);
return tileRendererLayer;
}
@ -426,9 +433,10 @@ public class MapViewDrawing extends MapView implements Drawing {
}
@Override
public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer, inner,
mode);
public MarkerOverlay drawMarker(Point point, Color outer, Color inner,
AlphaMode mode) {
return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer,
inner, mode);
}
@Override
@ -448,24 +456,26 @@ public class MapViewDrawing extends MapView implements Drawing {
// Tile cache
TileCache tileCache = AwtUtil.createTileCache(tileSize,
getModel().frameBufferModel.getOverdrawFactor(), 1024,
new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
new File(System.getProperty("java.io.tmpdir"),
UUID.randomUUID().toString()));
// Layers
Layers layers = getLayerManager().getLayers();
MapDataStore mapDataStore = new MapFile(file);
TileRendererLayer tileRendererLayer = createTileRendererLayer(tileCache, mapDataStore,
getModel().mapViewPosition, null);
TileRendererLayer tileRendererLayer = createTileRendererLayer(tileCache,
mapDataStore, getModel().mapViewPosition, null);
layers.add(tileRendererLayer);
BoundingBox boundingBox = mapDataStore.boundingBox();
final Model model = getModel();
if (model.mapViewPosition.getZoomLevel() == 0
|| !boundingBox.contains(model.mapViewPosition.getCenter())) {
byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(),
boundingBox, model.displayModel.getTileSize());
model.mapViewPosition
.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
byte zoomLevel =
LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(),
boundingBox, model.displayModel.getTileSize());
model.mapViewPosition.setMapPosition(
new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
zoomControls.setZoomLevel(zoomLevel);
}
@ -485,16 +495,17 @@ public class MapViewDrawing extends MapView implements Drawing {
public PathOverlay drawPath(Path path, Color color, boolean markers) {
PolylineAutoScaling line = new PolylineAutoScaling(1, color);
ArrayList<Point> points = new ArrayList<>(path.getArcs().size() * 4);
for (Arc arc: path.getArcs()) {
for (Arc arc : path.getArcs()) {
points.addAll(arc.getPoints());
}
line.addAll(points);
PathOverlay overlay = null;
if (markers) {
MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), color, color,
AlphaMode.TRANSPARENT),
destination = createMarker(path.getDestination().getPoint(), color, color,
AlphaMode.TRANSPARENT);
MarkerAutoScaling origin =
createMarker(path.getOrigin().getPoint(), color, color,
AlphaMode.TRANSPARENT),
destination = createMarker(path.getDestination().getPoint(), color,
color, AlphaMode.TRANSPARENT);
overlay = new MapViewPathOverlay(line, origin, destination);
}
else {

View File

@ -61,8 +61,8 @@ public class MapZoomControls {
private final List<ActionListener> zoomInListeners = new ArrayList<>();
private final List<ActionListener> zoomOutListeners = new ArrayList<>();
public MapZoomControls(Component component, final int defaultZoom, final int minZoom,
final int maxZoom) throws IOException {
public MapZoomControls(Component component, final int defaultZoom,
final int minZoom, final int maxZoom) throws IOException {
zoomIn = ImageIO.read(getClass().getResourceAsStream("/zoomIn.png"))
.getScaledInstance(DEFAULT_HEIGHT, DEFAULT_HEIGHT, Image.SCALE_SMOOTH);
@ -76,7 +76,8 @@ public class MapZoomControls {
component.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
if (zoomInRect.contains(e.getPoint()) || zoomOutRect.contains(e.getPoint())) {
if (zoomInRect.contains(e.getPoint())
|| zoomOutRect.contains(e.getPoint())) {
component.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
else {
@ -90,16 +91,17 @@ public class MapZoomControls {
public void mouseClicked(MouseEvent e) {
if (zoomInRect.contains(e.getPoint()) && currentLevel < maxLevel) {
currentLevel += 1;
for (ActionListener al: zoomInListeners) {
al.actionPerformed(
new ActionEvent(this, ZOOM_IN_ACTION_ID, ZOOM_IN_ACTION_NAME));
for (ActionListener al : zoomInListeners) {
al.actionPerformed(new ActionEvent(this, ZOOM_IN_ACTION_ID,
ZOOM_IN_ACTION_NAME));
}
}
else if (zoomOutRect.contains(e.getPoint()) && currentLevel > minLevel) {
else if (zoomOutRect.contains(e.getPoint())
&& currentLevel > minLevel) {
currentLevel -= 1;
for (ActionListener al: zoomOutListeners) {
al.actionPerformed(
new ActionEvent(this, ZOOM_OUT_ACTION_ID, ZOOM_OUT_ACTION_NAME));
for (ActionListener al : zoomOutListeners) {
al.actionPerformed(new ActionEvent(this, ZOOM_OUT_ACTION_ID,
ZOOM_OUT_ACTION_NAME));
}
}
component.repaint();
@ -152,24 +154,23 @@ public class MapZoomControls {
* @return Width of this "component" when drawn.
*/
public int getWidth() {
return DEFAULT_HEIGHT + 2 + (this.maxLevel - this.minLevel) * DEFAULT_SPACING + 1 + 2
+ DEFAULT_HEIGHT;
return DEFAULT_HEIGHT + 2 + (this.maxLevel - this.minLevel) * DEFAULT_SPACING
+ 1 + 2 + DEFAULT_HEIGHT;
}
/**
* Check if a point is contained inside an element of this zoom controls, useful
* to avoid spurious click listeners.
* Check if a point is contained inside an element of this zoom controls, useful to
* avoid spurious click listeners.
*
* @param point Point to check.
*
* @return true if the given point correspond to an element of this zoom
* controls.
* @return true if the given point correspond to an element of this zoom controls.
*/
public boolean contains(Point point) {
return zoomInRect.contains(point) || zoomOutRect.contains(point);
}
protected void draw(Graphics2D g, int xoffset, int yoffset, ImageObserver observer) {
protected void draw(Graphics2D g, int xoffset, int yoffset,
ImageObserver observer) {
int height = getHeight();

View File

@ -11,7 +11,8 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
public class ZoomAndPanListener implements MouseListener, MouseMotionListener, MouseWheelListener {
public class ZoomAndPanListener
implements MouseListener, MouseMotionListener, MouseWheelListener {
public static final int DEFAULT_MIN_ZOOM_LEVEL = -20;
public static final int DEFAULT_MAX_ZOOM_LEVEL = 10;
public static final double DEFAULT_ZOOM_MULTIPLICATION_FACTOR = 1.2;
@ -31,8 +32,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
this.targetComponent = targetComponent;
}
public ZoomAndPanListener(Component targetComponent, int minZoomLevel, int maxZoomLevel,
double zoomMultiplicationFactor) {
public ZoomAndPanListener(Component targetComponent, int minZoomLevel,
int maxZoomLevel, double zoomMultiplicationFactor) {
this.targetComponent = targetComponent;
this.minZoomLevel = minZoomLevel;
this.maxZoomLevel = maxZoomLevel;
@ -44,25 +45,20 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
targetComponent.repaint();
}
public void mouseClicked(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
dragStartScreen = e.getPoint();
dragEndScreen = null;
}
public void mouseReleased(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {
moveCamera(e);
@ -97,9 +93,11 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
if (zoomLevel < maxZoomLevel) {
zoomLevel++;
Point2D p1 = transformPoint(p);
coordTransform.scale(zoomMultiplicationFactor, zoomMultiplicationFactor);
coordTransform.scale(zoomMultiplicationFactor,
zoomMultiplicationFactor);
Point2D p2 = transformPoint(p);
coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
coordTransform.translate(p2.getX() - p1.getX(),
p2.getY() - p1.getY());
targetComponent.repaint();
}
}
@ -110,7 +108,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
coordTransform.scale(1 / zoomMultiplicationFactor,
1 / zoomMultiplicationFactor);
Point2D p2 = transformPoint(p);
coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
coordTransform.translate(p2.getX() - p1.getX(),
p2.getY() - p1.getY());
targetComponent.repaint();
}
}
@ -120,7 +119,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
}
}
private Point2D.Float transformPoint(Point p1) throws NoninvertibleTransformException {
private Point2D.Float transformPoint(Point p1)
throws NoninvertibleTransformException {
AffineTransform inverse = coordTransform.createInverse();
@ -139,7 +139,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
public void zoomIn() {
try {
Point p = new Point(targetComponent.getWidth() / 2, targetComponent.getHeight() / 2);
Point p = new Point(targetComponent.getWidth() / 2,
targetComponent.getHeight() / 2);
zoomLevel++;
Point2D p1 = transformPoint(p);
coordTransform.scale(zoomMultiplicationFactor, zoomMultiplicationFactor);
@ -154,10 +155,12 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
public void zoomOut() {
try {
Point p = new Point(targetComponent.getWidth() / 2, targetComponent.getHeight() / 2);
Point p = new Point(targetComponent.getWidth() / 2,
targetComponent.getHeight() / 2);
zoomLevel--;
Point2D p1 = transformPoint(p);
coordTransform.scale(1 / zoomMultiplicationFactor, 1 / zoomMultiplicationFactor);
coordTransform.scale(1 / zoomMultiplicationFactor,
1 / zoomMultiplicationFactor);
Point2D p2 = transformPoint(p);
coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
targetComponent.repaint();

View File

@ -12,11 +12,9 @@ import org.mapsforge.map.awt.graphics.AwtBitmap;
import org.mapsforge.map.layer.overlay.Marker;
/**
* Class extending the default Mapsforge's {@link Marker} with auto-scaling.
*
* Mapsforge's Markers do not scale with zoom level, this class aims at
* correcting this. Internally, this image stores an {@link Image} instance and
* scale it when a redraw is requested.
* Class extending the default Mapsforge's {@link Marker} with auto-scaling. Mapsforge's
* Markers do not scale with zoom level, this class aims at correcting this. Internally,
* this image stores an {@link Image} instance and scale it when a redraw is requested.
*
* @see MarkerUtils#getMarkerForColor(java.awt.Color, java.awt.Color,
* org.insa.graphics.drawing.Drawing.AlphaMode)
@ -55,15 +53,15 @@ public class MarkerAutoScaling extends Marker {
}
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
Point topLeftPoint) {
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel,
Canvas canvas, Point topLeftPoint) {
int width = (int) PaintUtils.getStrokeWidth(8, zoomLevel),
height = (int) PaintUtils.getStrokeWidth(16, zoomLevel);
BufferedImage bfd = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
BufferedImage bfd =
new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = bfd.createGraphics();
g.drawImage(
this.image.getScaledInstance(bfd.getWidth(), bfd.getHeight(), Image.SCALE_SMOOTH),
0, 0, null);
g.drawImage(this.image.getScaledInstance(bfd.getWidth(), bfd.getHeight(),
Image.SCALE_SMOOTH), 0, 0, null);
setBitmap(new AwtBitmap(bfd));
setVerticalOffset(-height / 2);

View File

@ -16,7 +16,6 @@ public class MarkerUtils {
* @param outer Outer color of the marker.
* @param inner Inner color of the marker.
* @param mode Mode to use to fill the inner part of the marker.
*
* @return An image representing a marker.
*/
public static Image getMarkerForColor(Color outer, Color inner, AlphaMode mode) {
@ -31,23 +30,28 @@ public class MarkerUtils {
for (int j = 0; j < image.getWidth(); ++j) {
// If we are in the "inner" part of the marker...
if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER && j < MAX_X_CENTER
&& mask[i][j] != MAXIMUM_INNER_MASK_VALUE) {
if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER
&& j < MAX_X_CENTER && mask[i][j] != MAXIMUM_INNER_MASK_VALUE) {
// Don't ask... https://stackoverflow.com/a/29321264/2666289
// Basically, this compute a "middle" color between outer and inner depending on
// Basically, this compute a "middle" color between outer and inner
// depending on
// the current mask value.
double t = 1 - (mask[i][j] - MINIMUM_INNER_MASK_VALUE)
/ (double) (MAXIMUM_INNER_MASK_VALUE - MINIMUM_INNER_MASK_VALUE);
/ (double) (MAXIMUM_INNER_MASK_VALUE
- MINIMUM_INNER_MASK_VALUE);
int r = (int) Math.sqrt((1 - t) * outer.getRed() * outer.getRed()
+ t * inner.getRed() * inner.getRed());
int g = (int) Math.sqrt((1 - t) * outer.getGreen() * outer.getGreen()
+ t * inner.getGreen() * inner.getGreen());
int g = (int) Math
.sqrt((1 - t) * outer.getGreen() * outer.getGreen()
+ t * inner.getGreen() * inner.getGreen());
int b = (int) Math.sqrt((1 - t) * outer.getBlue() * outer.getBlue()
+ t * inner.getBlue() * inner.getBlue());
int a = mode == AlphaMode.OPAQUE ? MAXIMUM_INNER_MASK_VALUE : mask[i][j];
int a = mode == AlphaMode.OPAQUE ? MAXIMUM_INNER_MASK_VALUE
: mask[i][j];
image.setRGB(j, i, (a << 24) | (r << 16) | (g << 8) | b);
}
// Otherwize, just fill with the outer color and set the alpha value properly.
// Otherwize, just fill with the outer color and set the alpha value
// properly.
else {
image.setRGB(j, i, outerRGB | (mask[i][j] << 24));
}
@ -64,7 +68,8 @@ public class MarkerUtils {
// with a different color.
private static final int MIN_X_CENTER = 40, MAX_X_CENTER = 101, MIN_Y_CENTER = 40,
MAX_Y_CENTER = 100;
private static final int MINIMUM_INNER_MASK_VALUE = 116, MAXIMUM_INNER_MASK_VALUE = 249;
private static final int MINIMUM_INNER_MASK_VALUE = 116,
MAXIMUM_INNER_MASK_VALUE = 249;
/**
* @return Retrieve the mask from the mask file or from the cache.

View File

@ -16,19 +16,17 @@ public class PaintUtils {
* Convert the given AWT color to a mapsforge compatible color.
*
* @param color AWT color to convert.
*
* @return Integer value representing a corresponding mapsforge color.
*/
public static int convertColor(Color color) {
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(), color.getGreen(),
color.getBlue());
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(),
color.getGreen(), color.getBlue());
}
/**
* Convert the given mapsforge color to an AWT Color.
*
* @param color Integer value representing a mapsforge color.
*
* @return AWT color corresponding to the given value.
*/
public static Color convertColor(int color) {
@ -37,12 +35,11 @@ public class PaintUtils {
/**
* Compute an updated value for the given width at the given zoom level. This
* function can be used to automatically scale {@link Polyline} or
* {@link Marker} when zooming (which is not done by default in Mapsforge).
* function can be used to automatically scale {@link Polyline} or {@link Marker}
* when zooming (which is not done by default in Mapsforge).
*
* @param width Original width to convert.
* @param zoomLevel Zoom level for which the width should be computed.
*
* @return Actual width at the given zoom level.
*/
public static float getStrokeWidth(int width, byte zoomLevel) {

View File

@ -25,7 +25,6 @@ public interface PointSetOverlay extends Overlay {
* Add a new point using the current width and color.
*
* @param point Position of the point to add.
*
* @see #setWidth(int)
* @see #setColor(Color)
*/
@ -36,7 +35,6 @@ public interface PointSetOverlay extends Overlay {
*
* @param point Position of the point to add.
* @param width New default width for this overlay.
*
* @see #setWidth(int)
* @see PointSetOverlay#addPoint(Point)
*/
@ -47,20 +45,18 @@ public interface PointSetOverlay extends Overlay {
*
* @param point Position of the point to add.
* @param color New default color for this overlay.
*
* @see #setColor(Color)
* @see PointSetOverlay#addPoint(Point)
*/
public void addPoint(Point point, Color color);
/**
* Add a new point at the given location, with the given color and width, and
* update the current width and color.
* Add a new point at the given location, with the given color and width, and update
* the current width and color.
*
* @param point Position of the point to add.
* @param width New default width for this overlay.
* @param color New default color for this overlay.
*
* @see #setWidth(int)
* @see #setColor(Color)
* @see PointSetOverlay#addPoint(Point)

View File

@ -15,10 +15,9 @@ import org.mapsforge.map.layer.overlay.Polyline;
/**
* Class extending the default Mapsforge's {@link Polyline} with auto-scaling.
*
* Mapsforge's Polylines do not scale with zoom level, this class aims at
* correcting this. When a redraw is requested, the width of the line is
* recomputed for the current zoom level.
* Mapsforge's Polylines do not scale with zoom level, this class aims at correcting
* this. When a redraw is requested, the width of the line is recomputed for the current
* zoom level.
*
* @see PaintUtils#getStrokeWidth(int, byte)
*/
@ -35,7 +34,6 @@ public class PolylineAutoScaling extends Polyline {
*
* @param width Original width of the line (independent of the zoom level).
* @param color Color of the line.
*
* @see PaintUtils#getStrokeWidth(int, byte)
*/
public PolylineAutoScaling(int width, Color color) {
@ -73,18 +71,19 @@ public class PolylineAutoScaling extends Polyline {
*/
public void addAll(Collection<? extends Point> points) {
ArrayList<LatLong> latlongs = new ArrayList<>(points.size());
for (Point point: points) {
for (Point point : points) {
latlongs.add(new LatLong(point.getLatitude(), point.getLongitude()));
}
getLatLongs().addAll(latlongs);
}
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
org.mapsforge.core.model.Point topLeftPoint) {
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel,
Canvas canvas, org.mapsforge.core.model.Point topLeftPoint) {
// Update paint stroke with width for level
this.getPaintStroke().setStrokeWidth(PaintUtils.getStrokeWidth(width, zoomLevel));
this.getPaintStroke()
.setStrokeWidth(PaintUtils.getStrokeWidth(width, zoomLevel));
super.draw(boundingBox, zoomLevel, canvas, topLeftPoint);
}

View File

@ -8,10 +8,11 @@ import org.insa.graphs.gui.drawing.Drawing;
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
import org.insa.graphs.model.Node;
public class WeaklyConnectedComponentGraphicObserver implements WeaklyConnectedComponentObserver {
public class WeaklyConnectedComponentGraphicObserver
implements WeaklyConnectedComponentObserver {
private static final Color[] COLORS = { Color.BLUE, Color.ORANGE, Color.GREEN, Color.YELLOW,
Color.RED };
private static final Color[] COLORS =
{ Color.BLUE, Color.ORANGE, Color.GREEN, Color.YELLOW, Color.RED };
// Drawing + Graph drawing
private PointSetOverlay grPoints;

View File

@ -14,11 +14,11 @@ import javax.swing.filechooser.FileNameExtensionFilter;
public class FileUtils {
// Preferences
private static Preferences preferences = Preferences.userRoot().node(FileUtils.class.getName());
private static Preferences preferences =
Preferences.userRoot().node(FileUtils.class.getName());
/**
* Type of folder with associated preferred folder and path filters.
*
*/
public enum FolderType {
@ -49,34 +49,35 @@ public class FileUtils {
}
// Map folder type -> PreferencesEntry
private static final Map<FolderType, PreferencesEntry> folderToEntry = new EnumMap<>(
FolderType.class);
private static final Map<FolderType, PreferencesEntry> folderToEntry =
new EnumMap<>(FolderType.class);
// Map folder type -> File Filter
private static final Map<FolderType, FileFilter> folderToFilter = new EnumMap<>(
FolderType.class);
private static final Map<FolderType, FileFilter> folderToFilter =
new EnumMap<>(FolderType.class);
static {
// Populate folderToEntry
folderToEntry.put(FolderType.Map, new PreferencesEntry("DefaultMapFolder",
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps"));
folderToEntry.put(FolderType.PathInput, new PreferencesEntry("DefaultPathInputFolder",
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths"));
folderToEntry.put(FolderType.PathInput,
new PreferencesEntry("DefaultPathInputFolder",
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths"));
folderToEntry.put(FolderType.PathOutput,
new PreferencesEntry("DefaultPathOutputsFolder", "paths"));
// Populate folderToFilter
folderToFilter.put(FolderType.Map, new FileNameExtensionFilter("Graph files", "mapgr"));
folderToFilter.put(FolderType.PathInput, new FileNameExtensionFilter("Path files", "path"));
folderToFilter.put(FolderType.Map,
new FileNameExtensionFilter("Graph files", "mapgr"));
folderToFilter.put(FolderType.PathInput,
new FileNameExtensionFilter("Path files", "path"));
folderToFilter.put(FolderType.PathOutput,
new FileNameExtensionFilter("Path files", "path"));
}
/**
* @param folderType Type of folder to retrieve.
*
* @return A File instance pointing to the preferred folder for the given type.
*
* @see FolderType
*/
public static File getPreferredFolder(FolderType folderType) {
@ -92,14 +93,14 @@ public class FileUtils {
* @param folderType Type of folder to update.
* @param newPreferredFolder New preferred folder.
*/
public static void updatePreferredFolder(FolderType folderType, File newPreferredFolder) {
public static void updatePreferredFolder(FolderType folderType,
File newPreferredFolder) {
PreferencesEntry entry = folderToEntry.get(folderType);
preferences.put(entry.key, newPreferredFolder.getAbsolutePath());
}
/**
* @param folderType Type of folder for which the filter should be retrieved.
*
* @return A FileFilter corresponding to input graph files.
*/
public static FileFilter getFileFilter(FolderType folderType) {
@ -108,18 +109,18 @@ public class FileUtils {
/**
* @param folderType Type of folder for which a file chooser should be created.
* @param defaultFileName Default file name to show, or null to not show any
* file.
*
* @param defaultFileName Default file name to show, or null to not show any file.
* @return A new JFileChooser pointing to the preferred folder for the given
* folderType, with the given default file selected (if given).
*/
public static JFileChooser createFileChooser(FolderType folderType, String defaultFileName) {
public static JFileChooser createFileChooser(FolderType folderType,
String defaultFileName) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(getPreferredFolder(folderType));
if (defaultFileName != null) {
chooser.setSelectedFile(new File(chooser.getCurrentDirectory().getAbsolutePath()
+ File.separator + defaultFileName));
chooser.setSelectedFile(
new File(chooser.getCurrentDirectory().getAbsolutePath()
+ File.separator + defaultFileName));
}
chooser.setFileFilter(getFileFilter(folderType));
chooser.addActionListener(new ActionListener() {
@ -138,10 +139,8 @@ public class FileUtils {
/**
* @param folderType Type of folder for which a file chooser should be created.
*
* @return A new JFileChooser pointing to the preferred folder for the given
* folderType.
*
* @see #createFileChooser(FolderType, String)
*/
public static JFileChooser createFileChooser(FolderType folderType) {

View File

@ -1,8 +1,5 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@ -7,18 +7,15 @@ import java.util.EnumSet;
* <p>
* Class containing access restrictions for roads/arcs.
* </p>
*
* <p>
* This class maps transport modes to their restriction and provide interface
* based on EnumSet to query restrictions.
* This class maps transport modes to their restriction and provide interface based on
* EnumSet to query restrictions.
* </p>
*
* <p>
* To each transport is associated at most one restriction per road (no
* restriction corresponds to {@link AccessRestriction#UNKNOWN} but a road can
* have different restrictions for different modes.
* To each transport is associated at most one restriction per road (no restriction
* corresponds to {@link AccessRestriction#UNKNOWN} but a road can have different
* restrictions for different modes.
* </p>
*
*/
public class AccessRestrictions {
@ -73,24 +70,20 @@ public class AccessRestrictions {
/**
* {@code EnumSet} containing all possible transport modes.
*
*
*/
public static final EnumSet<AccessMode> ALL = EnumSet.allOf(AccessMode.class);
/**
* {@code EnumSet} containing all vehicle transport modes.
*
*/
public static final EnumSet<AccessMode> VEHICLE = EnumSet.range(AccessMode.BICYCLE,
AccessMode.PUBLIC_TRANSPORT);
public static final EnumSet<AccessMode> VEHICLE =
EnumSet.range(AccessMode.BICYCLE, AccessMode.PUBLIC_TRANSPORT);
/**
* {@code EnumSet} containing all motorized vehicle transport modes.
*
*/
public static final EnumSet<AccessMode> MOTOR_VEHICLE = EnumSet
.range(AccessMode.SMALL_MOTORCYCLE, AccessMode.PUBLIC_TRANSPORT);
public static final EnumSet<AccessMode> MOTOR_VEHICLE =
EnumSet.range(AccessMode.SMALL_MOTORCYCLE, AccessMode.PUBLIC_TRANSPORT);
}
/**
@ -144,12 +137,11 @@ public class AccessRestrictions {
/**
* {@code EnumSet} corresponding to restrictions that are not totally private.
*
*/
public static final EnumSet<AccessRestriction> ALLOWED_FOR_SOMETHING = EnumSet.of(
AccessRestriction.ALLOWED, AccessRestriction.DESTINATION,
AccessRestriction.DESTINATION, AccessRestriction.DELIVERY,
AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY);
public static final EnumSet<AccessRestriction> ALLOWED_FOR_SOMETHING =
EnumSet.of(AccessRestriction.ALLOWED, AccessRestriction.DESTINATION,
AccessRestriction.DESTINATION, AccessRestriction.DELIVERY,
AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY);
}
@ -161,7 +153,7 @@ public class AccessRestrictions {
*/
public AccessRestrictions() {
this.restrictions = new EnumMap<>(AccessMode.class);
for (AccessMode mode: AccessMode.values()) {
for (AccessMode mode : AccessMode.values()) {
this.restrictions.put(mode, AccessRestriction.UNKNOWN);
}
}
@ -169,8 +161,7 @@ public class AccessRestrictions {
/**
* Create a new AccessRestrictions instances with the given restrictions.
*
* @param restrictions Map of restrictions for this instance of
* AccessRestrictions.
* @param restrictions Map of restrictions for this instance of AccessRestrictions.
*/
public AccessRestrictions(EnumMap<AccessMode, AccessRestriction> restrictions) {
this.restrictions = restrictions;
@ -180,7 +171,6 @@ public class AccessRestrictions {
* Retrieve the restriction corresponding to the given mode.
*
* @param mode Mode for which the restriction should be retrieved.
*
* @return Restriction for the given mode.
*/
public AccessRestriction getRestrictionFor(AccessMode mode) {
@ -191,23 +181,21 @@ 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
* restrictions.
*/
public boolean isAllowedForAny(AccessMode mode, EnumSet<AccessRestriction> restrictions) {
public boolean isAllowedForAny(AccessMode mode,
EnumSet<AccessRestriction> restrictions) {
return restrictions.contains(getRestrictionFor(mode));
}
/**
* Check if the restriction for the given mode corresponds to the given
* restriction.
* 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
* given restriction.
*/
@ -219,9 +207,8 @@ 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
* restrictions.
*/

View File

@ -4,18 +4,16 @@ import java.util.List;
/**
* <p>
* Interface representing an arc in the graph. {@code Arc} is an interface and
* not a class to allow us to represent two-ways roads in a memory efficient
* manner (without having to duplicate attributes).
* Interface representing an arc in the graph. {@code Arc} is an interface and not a
* class to allow us to represent two-ways roads in a memory efficient manner (without
* having to duplicate attributes).
* </p>
*
* <p>
* Arc should never be created manually but always using the
* {@link Node#linkNodes(Node, Node, float, RoadInformation, java.util.ArrayList)}
* method to ensure proper instantiation of the {@link ArcForward} and
* {@link ArcBackward} classes.
* </p>
*
*/
public abstract class Arc {
@ -38,7 +36,6 @@ public abstract class Arc {
* Compute the time required to travel this arc if moving at the given speed.
*
* @param speed Speed to compute the travel time.
*
* @return Time (in seconds) required to travel this arc at the given speed (in
* kilometers-per-hour).
*/
@ -51,7 +48,6 @@ public abstract class Arc {
* required to travel this arc at the maximum speed allowed.
*
* @return Minimum time required to travel this arc, in seconds.
*
* @see Arc#getTravelTime(double)
*/
public double getMinimumTravelTime() {

View File

@ -5,10 +5,8 @@ import java.util.Collections;
import java.util.List;
/**
* Implementation of Arc that represents a "backward" arc in a graph, i.e., an
* arc that is the reverse of another one. This arc only holds a reference to
* the original arc.
*
* Implementation of Arc that represents a "backward" arc in a graph, i.e., an arc that
* is the reverse of another one. This arc only holds a reference to the original arc.
*/
class ArcBackward extends Arc {
@ -16,8 +14,7 @@ class ArcBackward extends Arc {
private final Arc originalArc;
/**
* Create a new backward arc which corresponds to the reverse arc of the given
* arc.
* Create a new backward arc which corresponds to the reverse arc of the given arc.
*
* @param originalArc Original forwarc arc corresponding to this backward arc.
*/

View File

@ -4,9 +4,8 @@ import java.util.Collections;
import java.util.List;
/**
* Implementation of Arc that represents a "forward" arc in a graph, this is the
* arc implementation that stores data relative to the arc.
*
* Implementation of Arc that represents a "forward" arc in a graph, this is the arc
* implementation that stores data relative to the arc.
*/
class ArcForward extends Arc {
@ -31,8 +30,8 @@ class ArcForward extends Arc {
* @param roadInformation Road information for this arc.
* @param points Points representing this arc.
*/
protected ArcForward(Node origin, Node dest, float length, RoadInformation roadInformation,
List<Point> points) {
protected ArcForward(Node origin, Node dest, float length,
RoadInformation roadInformation, List<Point> points) {
this.origin = origin;
this.destination = dest;
this.length = length;

View File

@ -8,12 +8,10 @@ import java.util.List;
* <p>
* Main graph class.
* </p>
*
* <p>
* This class acts as a object-oriented <b>adjacency list</b> for a graph, i.e.,
* it holds a list of nodes and each node holds a list of its successors.
* This class acts as a object-oriented <b>adjacency list</b> for a graph, i.e., it
* holds a list of nodes and each node holds a list of its successors.
* </p>
*
*/
public final class Graph {
@ -32,12 +30,13 @@ 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) {
public Graph(String mapId, String mapName, List<Node> nodes,
GraphStatistics graphStatistics) {
this.mapId = mapId;
this.mapName = mapName;
this.nodes = Collections.unmodifiableList(nodes);
@ -52,12 +51,9 @@ public final class Graph {
}
/**
* Fetch the node with the given ID.
*
* Complexity: O(1).
* Fetch the node with the given ID. Complexity: O(1).
*
* @param id ID of the node to fetch.
*
* @return Node with the given ID.
*/
public Node get(int id) {
@ -73,7 +69,6 @@ public final class Graph {
/**
* @return List of nodes in this graph (unmodifiable).
*
* @see Collections#unmodifiableList(List)
*/
public List<Node> getNodes() {
@ -99,16 +94,17 @@ public final class Graph {
*/
public Graph transpose() {
final ArrayList<Node> trNodes = new ArrayList<>(nodes.size());
for (Node node: nodes) {
for (Node node : nodes) {
trNodes.add(new Node(node.getId(), node.getPoint()));
}
for (Node node: nodes) {
for (Node node : nodes) {
final Node orig = trNodes.get(node.getId());
for (Arc arc: node.getSuccessors()) {
for (Arc arc : node.getSuccessors()) {
if (arc.getRoadInformation().isOneWay()) {
final Node dest = trNodes.get(arc.getDestination().getId());
dest.addSuccessor(new ArcBackward(new ArcForward(orig, dest, arc.getLength(),
arc.getRoadInformation(), arc.getPoints())));
dest.addSuccessor(
new ArcBackward(new ArcForward(orig, dest, arc.getLength(),
arc.getRoadInformation(), arc.getPoints())));
}
else if (arc instanceof ArcForward) {
final Node dest = trNodes.get(arc.getDestination().getId());
@ -124,8 +120,8 @@ public final class Graph {
@Override
public String toString() {
return String.format("%s[id=%s, name=%s, #nodes=%d]", getClass().getCanonicalName(),
getMapId(), getMapName(), size());
return String.format("%s[id=%s, name=%s, #nodes=%d]",
getClass().getCanonicalName(), getMapId(), getMapName(), size());
}
}

View File

@ -2,30 +2,24 @@ package org.insa.graphs.model;
/**
* <p>
* Utility class that stores some statistics of graphs that are not easy to
* access.
* Utility class that stores some statistics of graphs that are not easy to access.
* </p>
*
* <p>
* This class is used to provide constant ({@code O(1)}) access to information
* in graph that do not change, and that usually require linear complexity to
* compute.
* This class is used to provide constant ({@code O(1)}) access to information in graph
* that do not change, and that usually require linear complexity to compute.
* </p>
*
*/
public class GraphStatistics {
/**
* Special value used to indicate that the graph has no maximum speed limit
* (some roads are not limited).
*
* Special value used to indicate that the graph has no maximum speed limit (some
* roads are not limited).
*/
public static final int NO_MAXIMUM_SPEED = -1;
/**
* Class representing a bounding box for a graph (a rectangle that contains all
* nodes in the graph).
*
*/
public static class BoundingBox {
@ -65,12 +59,12 @@ public class GraphStatistics {
* @param top Extra size to add to the top of the box.
* @param right Extra size to add to the right of the box.
* @param bottom Extra size to add to the bottom of the box.
*
* @return New bounding box corresponding to an extension of the current one.
*/
public BoundingBox extend(float left, float top, float right, float bottom) {
return new BoundingBox(
new Point(this.topLeft.getLongitude() - left, this.topLeft.getLatitude() + top),
new Point(this.topLeft.getLongitude() - left,
this.topLeft.getLatitude() + top),
new Point(this.bottomRight.getLongitude() + right,
this.bottomRight.getLatitude() - bottom));
}
@ -80,7 +74,6 @@ public class GraphStatistics {
* value on each side.
*
* @param size Extra size to add to each side of this box.
*
* @return New bounding box corresponding to an extension of the current one.
*/
public BoundingBox extend(float size) {
@ -89,7 +82,6 @@ public class GraphStatistics {
/**
* @param point Point to check
*
* @return true if this box contains the given point.
*/
public boolean contains(Point point) {
@ -101,7 +93,6 @@ public class GraphStatistics {
/**
* @param other Box to intersect.
*
* @return true if this box contains the given box.
*/
public boolean contains(BoundingBox other) {
@ -110,8 +101,8 @@ public class GraphStatistics {
@Override
public String toString() {
return "BoundingBox(topLeft=" + this.topLeft + ", bottomRight=" + this.bottomRight
+ ")";
return "BoundingBox(topLeft=" + this.topLeft + ", bottomRight="
+ this.bottomRight + ")";
}
}
@ -135,8 +126,8 @@ public class GraphStatistics {
* @param nbRoadOneWay Number of one-way roads in the graph.
* @param nbRoadTwoWays Number of two-ways roads in the graph.
* @param maximumSpeed Maximum speed of any road of the graph. You can use
* {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum
* speed limit.
* {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum speed
* limit.
* @param maximumLength Maximum length of any arc of the graph.
*/
public GraphStatistics(BoundingBox boundingBox, int nbRoadOneWay, int nbRoadTwoWays,
@ -171,7 +162,6 @@ public class GraphStatistics {
/**
* @return Number of arcs in this graph.
*
* @see #getOneWayRoadCount()
* @see #getTwoWaysRoadCount()
*/
@ -187,8 +177,8 @@ public class GraphStatistics {
}
/**
* @return Maximum speed of any arc in the graph, or {@link #NO_MAXIMUM_SPEED}
* if some roads have no speed limitation.
* @return Maximum speed of any arc in the graph, or {@link #NO_MAXIMUM_SPEED} if
* some roads have no speed limitation.
*/
public int getMaximumSpeed() {
return this.maximumSpeed;

View File

@ -8,16 +8,13 @@ import java.util.List;
* <p>
* Class representing a Node in a {@link Graph}.
* </p>
*
* <p>
* This class holds information regarding nodes in the graph together with the
* successors associated to the nodes.
* </p>
*
* <p>
* Nodes are comparable based on their ID.
* </p>
*
*/
public final class Node implements Comparable<Node> {
@ -26,19 +23,17 @@ public final class Node implements Comparable<Node> {
* Link the two given nodes with one or two arcs (depending on roadInformation),
* with the given attributes.
* </p>
*
* <p>
* If {@code roadInformation.isOneWay()} is {@code true}, only a forward arc is
* created (origin to destination) and added to origin. Otherwise, a
* corresponding backward arc is created and add to destination.
* created (origin to destination) and added to origin. Otherwise, a 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,
@ -51,12 +46,14 @@ public final class Node implements Comparable<Node> {
else {
final Arc d2o;
if (origin.getId() < destination.getId()) {
arc = new ArcForward(origin, destination, length, roadInformation, points);
arc = new ArcForward(origin, destination, length, roadInformation,
points);
d2o = new ArcBackward(arc);
}
else {
Collections.reverse(points);
d2o = new ArcForward(destination, origin, length, roadInformation, points);
d2o = new ArcForward(destination, origin, length, roadInformation,
points);
arc = new ArcBackward(d2o);
}
origin.addSuccessor(arc);
@ -78,7 +75,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) {
@ -119,7 +116,6 @@ public final class Node implements Comparable<Node> {
/**
* @return List of successors of this node (unmodifiable list).
*
* @see Collections#unmodifiableList(List)
*/
public List<Arc> getSuccessors() {
@ -148,7 +144,6 @@ public final class Node implements Comparable<Node> {
* Compare the ID of this node with the ID of the given node.
*
* @param other Node to compare this node with.
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override

View File

@ -2,7 +2,6 @@ package org.insa.graphs.model;
/**
* Class representing a point (position) on Earth.
*
*/
public final class Point {
@ -16,7 +15,6 @@ public final class Point {
*
* @param p1 First point.
* @param p2 second point.
*
* @return Distance between the two given points (in meters).
*/
public static double distance(Point p1, Point p2) {
@ -24,7 +22,8 @@ public final class Point {
* Math.sin(Math.toRadians(p2.getLatitude()));
double cosLat = Math.cos(Math.toRadians(p1.getLatitude()))
* Math.cos(Math.toRadians(p2.getLatitude()));
double cosLong = Math.cos(Math.toRadians(p2.getLongitude() - p1.getLongitude()));
double cosLong =
Math.cos(Math.toRadians(p2.getLongitude() - p1.getLongitude()));
return EARTH_RADIUS * Math.acos(sinLat + cosLat * cosLong);
}
@ -60,7 +59,6 @@ public final class Point {
* Compute the distance from this point to the given point
*
* @param target Target point to compute distance to.
*
* @return Distance between this point and the target point, in meters.
*/
public double distanceTo(Point target) {

View File

@ -4,12 +4,10 @@ package org.insa.graphs.model;
* <p>
* Class containing information for road that may be shared by multiple arcs.
* </p>
*
* <p>
* Sharing information between arcs reduces memory footprints of the program (a
* long road is often split into multiple arcs at each intersection).
* Sharing information between arcs reduces memory footprints of the program (a long
* road is often split into multiple arcs at each intersection).
* </p>
*
*/
public class RoadInformation {
@ -21,24 +19,7 @@ public class RoadInformation {
* reference for road types.</a>
*/
public enum RoadType {
MOTORWAY,
TRUNK,
PRIMARY,
SECONDARY,
MOTORWAY_LINK,
TRUNK_LINK,
PRIMARY_LINK,
SECONDARY_LINK,
TERTIARY,
TRACK,
RESIDENTIAL,
UNCLASSIFIED,
LIVING_STREET,
SERVICE,
ROUNDABOUT,
PEDESTRIAN,
CYCLEWAY,
COASTLINE
MOTORWAY, TRUNK, PRIMARY, SECONDARY, MOTORWAY_LINK, TRUNK_LINK, PRIMARY_LINK, SECONDARY_LINK, TERTIARY, TRACK, RESIDENTIAL, UNCLASSIFIED, LIVING_STREET, SERVICE, ROUNDABOUT, PEDESTRIAN, CYCLEWAY, COASTLINE
}
// Type of the road (see above).
@ -60,14 +41,13 @@ public class RoadInformation {
* Create a new RoadInformation instance containing the given parameters.
*
* @param roadType Type of the road (see {@link RoadType}).
* @param access Access restrictions for the road (see
* {@link AccessRestrictions}).
* @param access Access restrictions for the road (see {@link AccessRestrictions}).
* @param isOneWay true if this road is a one way road, false otherwise.
* @param maxSpeed Maximum speed for the road (in kilometers-per-hour).
* @param name Name of the road.
*/
public RoadInformation(RoadType roadType, AccessRestrictions access, boolean isOneWay,
int maxSpeed, String name) {
public RoadInformation(RoadType roadType, AccessRestrictions access,
boolean isOneWay, int maxSpeed, String name) {
this.type = roadType;
this.access = access;
this.oneway = isOneWay;
@ -119,8 +99,8 @@ public class RoadInformation {
if (getType() == RoadType.MOTORWAY) {
typeAsString = "highway";
}
return typeAsString + " : " + getName() + " " + (isOneWay() ? " (oneway) " : "") + maxSpeed
+ " km/h (max.)";
return typeAsString + " : " + getName() + " " + (isOneWay() ? " (oneway) " : "")
+ maxSpeed + " km/h (max.)";
}
}

View File

@ -5,7 +5,6 @@ import java.io.IOException;
/**
* Exception thrown when a format-error is detected when reading a graph (e.g.,
* non-matching check bytes).
*
*/
public class BadFormatException extends IOException {

View File

@ -1,9 +1,7 @@
package org.insa.graphs.model.io;
/**
* Exception thrown when there is a mismatch between expected and actual magic
* number.
*
* Exception thrown when there is a mismatch between expected and actual magic number.
*/
public class BadMagicNumberException extends BadFormatException {
@ -23,8 +21,8 @@ public class BadMagicNumberException extends BadFormatException {
* @param expectedNumber Expected magic number.
*/
public BadMagicNumberException(int actualNumber, int expectedNumber) {
super(String.format("Magic number mismatch, expected %#X, got %#X.", expectedNumber,
actualNumber));
super(String.format("Magic number mismatch, expected %#X, got %#X.",
expectedNumber, actualNumber));
this.actualNumber = actualNumber;
this.expectedNumber = expectedNumber;
}

View File

@ -1,9 +1,7 @@
package org.insa.graphs.model.io;
/**
* Exception thrown when the version of the file is not at least the expected
* one.
*
* Exception thrown when the version of the file is not at least the expected one.
*/
public class BadVersionException extends BadFormatException {
@ -16,7 +14,6 @@ public class BadVersionException extends BadFormatException {
private int actualVersion, expectedVersion;
/**
*
* @param actualVersion Actual version of the file.
* @param expectedVersion Expected version of the file.
*/

View File

@ -20,7 +20,6 @@ import org.insa.graphs.model.RoadInformation.RoadType;
/**
* Implementation of {@link GraphReader} to read graph in binary format.
*
*/
public class BinaryGraphReader extends BinaryReader implements GraphReader {
@ -38,7 +37,6 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
* Parse the given long value into a new instance of AccessRestrictions.
*
* @param access The value to parse.
*
* @return New instance of access restrictions parsed from the given value.
*/
protected static AccessRestrictions toAccessInformation(final long access) {
@ -50,22 +48,25 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
// the order correspond to the 4 bits value (i.e. FORBIDDEN is 0 or PRIVATE is
// 2) - UKNOWN is not included because value above 6 (FORESTRY) are all
// considered unknown.
final AccessRestriction[] allRestrictions = new AccessRestriction[] {
AccessRestriction.FORBIDDEN, AccessRestriction.ALLOWED, AccessRestriction.PRIVATE,
AccessRestriction.DESTINATION, AccessRestriction.DELIVERY,
AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY };
final AccessRestriction[] allRestrictions =
new AccessRestriction[] { AccessRestriction.FORBIDDEN,
AccessRestriction.ALLOWED, AccessRestriction.PRIVATE,
AccessRestriction.DESTINATION, AccessRestriction.DELIVERY,
AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY };
// The order of values inside this array is VERY IMPORTANT: The order is such
// that each 4-bits group of the long value is processed in the correct order,
// i.e. FOOT is processed first (4 lowest bits), and so on.
final AccessMode[] allModes = new AccessMode[] { AccessMode.FOOT, null, AccessMode.BICYCLE,
AccessMode.SMALL_MOTORCYCLE, AccessMode.AGRICULTURAL, AccessMode.MOTORCYCLE,
AccessMode.MOTORCAR, AccessMode.HEAVY_GOODS, null, AccessMode.PUBLIC_TRANSPORT };
final AccessMode[] allModes = new AccessMode[] { AccessMode.FOOT, null,
AccessMode.BICYCLE, AccessMode.SMALL_MOTORCYCLE,
AccessMode.AGRICULTURAL, AccessMode.MOTORCYCLE, AccessMode.MOTORCAR,
AccessMode.HEAVY_GOODS, null, AccessMode.PUBLIC_TRANSPORT };
// fill maps...
final EnumMap<AccessMode, AccessRestriction> restrictions = new EnumMap<>(AccessMode.class);
final EnumMap<AccessMode, AccessRestriction> restrictions =
new EnumMap<>(AccessMode.class);
long copyAccess = access;
for (AccessMode mode: allModes) {
for (AccessMode mode : allModes) {
if (mode == null) {
continue; // filling cells
}
@ -86,49 +87,47 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
* Convert a character to its corresponding road type.
*
* @param ch Character to convert.
*
* @return Road type corresponding to the given character.
*
*/
protected static RoadType toRoadType(char ch) {
switch (ch) {
case 'a':
return RoadType.MOTORWAY;
case 'b':
return RoadType.TRUNK;
case 'c':
return RoadType.PRIMARY;
case 'd':
return RoadType.SECONDARY;
case 'e':
return RoadType.MOTORWAY_LINK;
case 'f':
return RoadType.TRUNK_LINK;
case 'g':
return RoadType.PRIMARY_LINK;
case 'h':
return RoadType.SECONDARY_LINK;
case 'i':
return RoadType.TERTIARY;
case 'j':
return RoadType.RESIDENTIAL;
case 'k':
case 'l':
return RoadType.UNCLASSIFIED;
case 'm':
return RoadType.LIVING_STREET;
case 'n':
return RoadType.SERVICE;
case 'o':
return RoadType.ROUNDABOUT;
case 'p':
return RoadType.PEDESTRIAN;
case 'r':
return RoadType.CYCLEWAY;
case 's':
return RoadType.TRACK;
case 'z':
return RoadType.COASTLINE;
case 'a':
return RoadType.MOTORWAY;
case 'b':
return RoadType.TRUNK;
case 'c':
return RoadType.PRIMARY;
case 'd':
return RoadType.SECONDARY;
case 'e':
return RoadType.MOTORWAY_LINK;
case 'f':
return RoadType.TRUNK_LINK;
case 'g':
return RoadType.PRIMARY_LINK;
case 'h':
return RoadType.SECONDARY_LINK;
case 'i':
return RoadType.TERTIARY;
case 'j':
return RoadType.RESIDENTIAL;
case 'k':
case 'l':
return RoadType.UNCLASSIFIED;
case 'm':
return RoadType.LIVING_STREET;
case 'n':
return RoadType.SERVICE;
case 'o':
return RoadType.ROUNDABOUT;
case 'p':
return RoadType.PEDESTRIAN;
case 'r':
return RoadType.CYCLEWAY;
case 's':
return RoadType.TRACK;
case 'z':
return RoadType.COASTLINE;
}
return RoadType.UNCLASSIFIED;
}
@ -181,8 +180,10 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
final ArrayList<Node> nodes = new ArrayList<Node>(nbNodes);
// Read nodes.
float minLongitude = Float.POSITIVE_INFINITY, minLatitude = Float.POSITIVE_INFINITY,
maxLongitude = Float.NEGATIVE_INFINITY, maxLatitude = Float.NEGATIVE_INFINITY;
float minLongitude = Float.POSITIVE_INFINITY,
minLatitude = Float.POSITIVE_INFINITY,
maxLongitude = Float.NEGATIVE_INFINITY,
maxLatitude = Float.NEGATIVE_INFINITY;
observers.forEach((observer) -> observer.notifyStartReadingNodes(nbNodes));
for (int node = 0; node < nbNodes; ++node) {
// Read longitude / latitude.
@ -230,7 +231,8 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
float maxLength = 0;
final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java...
int nbOneWayRoad = 0;
observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
observers.forEach(
(observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
for (int node = 0; node < nbNodes; ++node) {
for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
@ -250,8 +252,9 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
}
maxLength = Math.max(length, maxLength);
length = Math.max(length, (float) Point.distance(nodes.get(node).getPoint(),
nodes.get(destNode).getPoint()));
length = Math.max(length,
(float) Point.distance(nodes.get(node).getPoint(),
nodes.get(destNode).getPoint()));
// Number of segments.
final int nbSegments = dis.readUnsignedShort();
@ -294,14 +297,14 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
new GraphStatistics(
new BoundingBox(new Point(minLongitude, maxLatitude),
new Point(maxLongitude, minLatitude)),
nbOneWayRoad, nbTotalSuccessors - nbOneWayRoad, maxSpeed, maxLength));
nbOneWayRoad, nbTotalSuccessors - nbOneWayRoad, maxSpeed,
maxLength));
}
/**
* Read the next road information from the stream.
*
* @return The next RoadInformation in the stream.
*
* @throws IOException if an error occurs while reading from the stream.
*/
private RoadInformation readRoadInformation() throws IOException {
@ -315,8 +318,8 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
// TODO: Try to create something...
dis.readUnsignedShort();
}
return new RoadInformation(toRoadType(type), access, (x & 0x80) > 0, (x & 0x7F) * 5,
dis.readUTF());
return new RoadInformation(toRoadType(type), access, (x & 0x80) > 0,
(x & 0x7F) * 5, dis.readUTF());
}
}

View File

@ -10,7 +10,6 @@ import org.insa.graphs.model.Path;
/**
* Implementation of {@link PathReader} to read paths in binary format.
*
*/
public class BinaryPathReader extends BinaryReader implements PathReader {
@ -35,7 +34,8 @@ public class BinaryPathReader extends BinaryReader implements PathReader {
checkVersionOrThrow(dis.readInt());
// Read map ID and check against graph.
final 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());
@ -61,10 +61,8 @@ public class BinaryPathReader extends BinaryReader implements PathReader {
* Read a node from the input stream and returns it.
*
* @param graph Graph containing the nodes.
*
* @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 {

View File

@ -9,7 +9,6 @@ import org.insa.graphs.model.Path;
/**
* Implementation of {@link PathWriter} to write paths in binary format.
*
*/
public class BinaryPathWriter extends BinaryWriter implements PathWriter {
@ -43,7 +42,7 @@ public class BinaryPathWriter extends BinaryWriter implements PathWriter {
// Write nodes.
dos.writeInt(path.getOrigin().getId());
for (Arc arc: path.getArcs()) {
for (Arc arc : path.getArcs()) {
dos.writeInt(arc.getDestination().getId());
}

View File

@ -6,7 +6,6 @@ import java.io.IOException;
/**
* Base class for writing binary file.
*
*/
public abstract class BinaryReader implements AutoCloseable, Closeable {
@ -19,12 +18,12 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
protected final DataInputStream dis;
/**
* Create a new BinaryReader that reads from the given stream and that expected
* the given magic number and at least the given minimum version.
* Create a new BinaryReader that reads from the given stream and that expected 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;
@ -38,13 +37,12 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
}
/**
* Check if the given version is greater than the minimum version, and update
* the current version if it is.
* Check if the given version is greater than the minimum version, and update the
* current version if it is.
*
* @param version Version to check.
*
* @throws BadVersionException if the given version is not greater than the
* minimum version.
* @throws BadVersionException if the given version is not greater than the minimum
* version.
*/
protected void checkVersionOrThrow(int version) throws BadVersionException {
if (version < this.minVersion) {
@ -64,23 +62,21 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
* Check if the given number matches the expected magic number.
*
* @param magicNumber The magic number to check.
*
* @throws BadMagicNumberException If the two magic numbers are not equal.
*/
protected void checkMagicNumberOrThrow(int magicNumber) throws BadMagicNumberException {
protected void checkMagicNumberOrThrow(int magicNumber)
throws BadMagicNumberException {
if (this.magicNumber != magicNumber) {
throw new BadMagicNumberException(magicNumber, this.magicNumber);
}
}
/**
* Check if the next byte in the input stream correspond to the given byte.
*
* This function consumes the next byte in the input stream.
* Check if the next byte in the input stream correspond to the given byte. This
* function consumes the next byte in the input stream.
*
* @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 {
@ -90,17 +86,16 @@ 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'.
* 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.
*
* @throws IOException if an error occurs while reading or converting.
*/
protected String readFixedLengthString(int length, String charset) throws IOException {
protected String readFixedLengthString(int length, String charset)
throws IOException {
byte[] bytes = new byte[length];
this.dis.read(bytes);
return new String(bytes, "UTF-8").trim();
@ -111,7 +106,6 @@ public abstract class BinaryReader implements AutoCloseable, Closeable {
* integer value.
*
* @return Integer value read from the next 24 bits of the stream.
*
* @throws IOException if an error occurs while reading from the stream.
*/
protected int read24bits() throws IOException {

View File

@ -6,7 +6,6 @@ import java.io.IOException;
/**
* Base class for writing binary file.
*
*/
public abstract class BinaryWriter implements AutoCloseable, Closeable {
@ -31,7 +30,6 @@ public abstract class BinaryWriter implements AutoCloseable, Closeable {
* Write a 24-bits integer in BigEndian order to the output stream.
*
* @param value Value to write.
*
* @throws IOException if an error occurs while writing to the stream.
*/
protected void write24bits(int value) throws IOException {

View File

@ -7,7 +7,6 @@ import org.insa.graphs.model.Graph;
/**
* Base interface for classes that can read graph.
*
*/
public interface GraphReader extends AutoCloseable, Closeable {
@ -22,9 +21,7 @@ public interface GraphReader extends AutoCloseable, Closeable {
* Read a graph an returns it.
*
* @return The graph read.
*
* @throws IOException if an exception occurs while reading the graph.
*
*/
public Graph read() throws IOException;
@ -32,7 +29,6 @@ public interface GraphReader extends AutoCloseable, Closeable {
* Close this graph reader.
*
* @throws IOException if an exception occurs while closing the reader.
*
*/
public void close() throws IOException;

View File

@ -5,15 +5,14 @@ import org.insa.graphs.model.Node;
import org.insa.graphs.model.RoadInformation;
/**
* Base interface that should be implemented by classes that want to observe the
* reading of a graph by a {@link GraphReader}.
*
* Base interface that should be implemented by classes that want to observe the reading
* of a graph by a {@link GraphReader}.
*/
public interface GraphReaderObserver {
/**
* Notify observer about information on the graph, this method is always the
* first called
* Notify observer about information on the graph, this method is always the first
* called
*
* @param mapId ID of the graph.
*/

View File

@ -3,9 +3,8 @@ package org.insa.graphs.model.io;
import java.io.IOException;
/**
* Exception thrown when there is mismatch between the expected map ID and the
* actual map ID when reading a graph.
*
* Exception thrown when there is mismatch between the expected map ID and the actual
* map ID when reading a graph.
*/
public class MapMismatchException extends IOException {
@ -20,7 +19,7 @@ public class MapMismatchException extends IOException {
/**
* 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) {

View File

@ -8,7 +8,6 @@ import org.insa.graphs.model.Path;
/**
* Base interface that should be implemented by class used to read paths.
*
*/
public interface PathReader extends AutoCloseable, Closeable {
@ -16,9 +15,7 @@ public interface PathReader extends AutoCloseable, Closeable {
* Read a path of the given graph and returns it.
*
* @param graph Graph of the path.
*
* @return Path read.
*
* @throws IOException When an error occurs while reading the path.
*/
public Path readPath(Graph graph) throws IOException;
@ -27,7 +24,6 @@ public interface PathReader extends AutoCloseable, Closeable {
* Close this graph reader.
*
* @throws IOException if an exception occurs while closing the reader.
*
*/
public void close() throws IOException;

View File

@ -7,7 +7,6 @@ import org.insa.graphs.model.Path;
/**
* Base interface that should be implemented by class used to write paths.
*
*/
public interface PathWriter extends AutoCloseable, Closeable {
@ -15,7 +14,6 @@ public interface PathWriter extends AutoCloseable, Closeable {
* Write the given path.
*
* @param path Path to write.
*
* @throws IOException When an error occurs while writing the path.
*/
public void writePath(Path path) throws IOException;
@ -24,7 +22,6 @@ public interface PathWriter extends AutoCloseable, Closeable {
* Close this graph reader.
*
* @throws IOException if an exception occurs while closing the reader.
*
*/
public void close() throws IOException;

View File

@ -39,23 +39,29 @@ public class GraphTest {
new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[0], nodes[4], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[1], nodes[2], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[2], nodes[3], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[2], nodes[3], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[2], nodes[3], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[3], nodes[0], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[3], nodes[4], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[4], nodes[0], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
graph = new Graph("ID", "", Arrays.asList(nodes), null);
@ -66,7 +72,7 @@ public class GraphTest {
*/
private List<Arc> getArcsBetween(Node a, Node b) {
List<Arc> arcs = new ArrayList<>();
for (Arc arc: a.getSuccessors()) {
for (Arc arc : a.getSuccessors()) {
if (arc.getDestination().equals(b)) {
arcs.add(arc);
}

View File

@ -33,23 +33,29 @@ public class NodeTest {
new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[0], nodes[4], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[1], nodes[2], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[2], nodes[3], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[2], nodes[3], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[2], nodes[3], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[3], nodes[0], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[3], nodes[4], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
Node.linkNodes(nodes[4], nodes[0], 0,
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null),
new ArrayList<>());
}
@ -57,7 +63,7 @@ public class NodeTest {
* @return The first arc between from a to b, or null.
*/
private Arc getFirstArcBetween(Node a, Node b) {
for (Arc arc: a.getSuccessors()) {
for (Arc arc : a.getSuccessors()) {
if (arc.getDestination().equals(b)) {
return arc;
}

View File

@ -30,14 +30,15 @@ public class PathTest {
private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
// Some paths...
private static Path emptyPath, singleNodePath, shortPath, longPath, loopPath, longLoopPath,
invalidPath;
private static Path emptyPath, singleNodePath, shortPath, longPath, loopPath,
longLoopPath, invalidPath;
@BeforeClass
public static void initAll() throws IOException {
// 10 and 20 meters per seconds
RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, true, 36, ""),
RoadInformation speed10 =
new RoadInformation(RoadType.MOTORWAY, null, true, 36, ""),
speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, "");
// Create nodes
@ -65,8 +66,8 @@ public class PathTest {
shortPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1 }));
longPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2e }));
loopPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a }));
longLoopPath = new Path(graph,
Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
longLoopPath = new Path(graph, Arrays
.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
invalidPath = new Path(graph, Arrays.asList(new Arc[] { a2b, c2d_1, d2e }));
}
@ -184,7 +185,8 @@ public class PathTest {
}
// Trap construction!
path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] }));
path = Path.createFastestPathFromNodes(graph,
Arrays.asList(new Node[] { nodes[1] }));
assertEquals(nodes[1], path.getOrigin());
assertEquals(0, path.getArcs().size());
@ -219,7 +221,8 @@ public class PathTest {
}
// Trap construction!
path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] }));
path = Path.createShortestPathFromNodes(graph,
Arrays.asList(new Node[] { nodes[1] }));
assertEquals(nodes[1], path.getOrigin());
assertEquals(0, path.getArcs().size());
@ -232,12 +235,14 @@ public class PathTest {
@Test(expected = IllegalArgumentException.class)
public void testCreateFastestPathFromNodesException() {
Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] }));
Path.createFastestPathFromNodes(graph,
Arrays.asList(new Node[] { nodes[1], nodes[0] }));
}
@Test(expected = IllegalArgumentException.class)
public void testCreateShortestPathFromNodesException() {
Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] }));
Path.createShortestPathFromNodes(graph,
Arrays.asList(new Node[] { nodes[1], nodes[0] }));
}
}

View File

@ -0,0 +1,338 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="13">
<profile kind="CodeFormatterProfile" version="13">
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_cascading_method_invocation_with_arguments.count_dependent" value="16|-1|16" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true" />
<setting id="org.eclipse.jdt.core.formatter.wrap_prefer_two_fragments" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.wrap_comment_inline_tags" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_local_variable_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter" value="1040" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type.count_dependent" value="1585|-1|1585" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields.count_dependent" value="16|-1|16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression.count_dependent" value="16|4|80" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration.count_dependent" value="16|4|48" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration.count_dependent" value="16|4|49" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_cascading_method_invocation_with_arguments" value="16" />
<setting id="org.eclipse.jdt.core.compiler.source" value="1.7" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration.count_dependent" value="16|4|48" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16" />
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_local_variable_annotation" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants.count_dependent" value="16|5|48" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="88" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation.count_dependent" value="16|4|48" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package" value="1585" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="16" />
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error" />
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1" />
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true" />
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_type_annotation" value="true" />
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_field_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_generic_type_arguments" value="16" />
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true" />
<setting id="org.eclipse.jdt.core.formatter.comment_new_line_at_start_of_html_paragraph" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comment_prefix" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true" />
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_parameter_annotation" value="false" />
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method" value="1585" />
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation.count_dependent" value="16|5|80" />
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="true" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter.count_dependent" value="1040|-1|1040" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package.count_dependent" value="1585|-1|1585" />
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.force_if_else_statement_brace" value="true" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="2" />
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_package_annotation" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation.count_dependent" value="16|-1|16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type" value="1585" />
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7" />
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_new_anonymous_class" value="20" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable.count_dependent" value="1585|-1|1585" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field.count_dependent" value="1585|-1|1585" />
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration.count_dependent" value="16|5|80" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert" />
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant.count_dependent" value="16|-1|16" />
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="88" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="2" />
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true" />
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field" value="1585" />
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer.count_dependent" value="16|5|80" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert" />
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80" />
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="16" />
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="true" />
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration.count_dependent" value="16|4|48" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method.count_dependent" value="1585|-1|1585" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression.count_dependent" value="16|-1|16" />
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_member_annotation" value="true" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable" value="1585" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call.count_dependent" value="16|5|80" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_generic_type_arguments.count_dependent" value="16|-1|16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression.count_dependent" value="16|5|80" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration.count_dependent" value="16|5|80" />
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_for_statement" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false" />
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false" />
<setting id="org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position" value="false" />
</profile>
</profiles>

View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.insa.graphs</groupId>