diff --git a/.gitignore b/.gitignore index 8963733..969d625 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ doc *.jar .settings .classpath +.vscode # Editor specific files and folders *~ @@ -17,4 +18,4 @@ doc *.mapfg *.mapgr *.path -*.tgz \ No newline at end of file +*.tgz diff --git a/be-graphes-algos/pom.xml b/be-graphes-algos/pom.xml index d66075a..42179f0 100644 --- a/be-graphes-algos/pom.xml +++ b/be-graphes-algos/pom.xml @@ -1,19 +1,16 @@ - + 4.0.0 - + org.insa.graphs be-graphes-all 0.0.1-SNAPSHOT - + be-graphes-algos be-graphes-algos - + org.insa.graphs @@ -21,5 +18,5 @@ ${project.version} - + diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractAlgorithm.java index 10fe8c4..6f6f4f7 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractAlgorithm.java @@ -19,7 +19,7 @@ public abstract class AbstractAlgorithm { /** * Create a new algorithm with an empty list of observers. - * + * * @param data Input data for the algorithm. */ protected AbstractAlgorithm(AbstractInputData data) { @@ -29,7 +29,7 @@ public abstract class AbstractAlgorithm { /** * Create a new algorithm with the given list of observers. - * + * * @param data Input data for the algorithm. * @param observers Initial list of observers for the algorithm. */ @@ -40,7 +40,7 @@ public abstract class AbstractAlgorithm { /** * Add an observer to this algorithm. - * + * * @param observer Observer to add to this algorithm. */ public void addObserver(Observer observer) { @@ -62,11 +62,9 @@ public abstract class AbstractAlgorithm { } /** - * 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). */ public AbstractSolution run() { @@ -78,9 +76,9 @@ public abstract class AbstractAlgorithm { /** * 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(); diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java index a2a1b1f..2fb172d 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java @@ -5,16 +5,15 @@ 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 { /** * Enum specifying the top mode of the algorithms. - * + * * @see ArcInspector */ public enum Mode { @@ -29,7 +28,7 @@ public abstract class AbstractInputData { /** * Create a new AbstractInputData instance for the given graph, mode and filter. - * + * * @param graph Graph for this input data. * @param arcInspector Arc inspector for this input data. */ @@ -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,10 +66,10 @@ 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. */ @@ -83,11 +79,9 @@ 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) { diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractSolution.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractSolution.java index 0d271eb..cb312ab 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractSolution.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractSolution.java @@ -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, @@ -29,7 +27,7 @@ public abstract class AbstractSolution { /** * Create a new abstract solution with unknown status. - * + * * @param data */ protected AbstractSolution(AbstractInputData data) { @@ -39,7 +37,6 @@ public abstract class AbstractSolution { } /** - * * @param data * @param status */ @@ -71,7 +68,7 @@ public abstract class AbstractSolution { /** * Set the solving time of this solution. - * + * * @param solvingTime Solving time for the solution. */ protected void setSolvingTime(Duration solvingTime) { diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java index 18e6f2a..ff6d26e 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java @@ -5,26 +5,23 @@ 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 { /** * 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); /** * 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); @@ -40,4 +37,4 @@ public interface ArcInspector { */ public Mode getMode(); -} \ No newline at end of file +} diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java index d43df60..d13caf6 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java @@ -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 diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingAlgorithm.java index a895e38..55a76c7 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingAlgorithm.java @@ -2,7 +2,8 @@ package org.insa.graphs.algorithm.carpooling; import org.insa.graphs.algorithm.AbstractAlgorithm; -public abstract class CarPoolingAlgorithm extends AbstractAlgorithm { +public abstract class CarPoolingAlgorithm + extends AbstractAlgorithm { protected CarPoolingAlgorithm(CarPoolingData data) { super(data); diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchAlgorithm.java index 191e927..6856aba 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchAlgorithm.java @@ -2,11 +2,12 @@ package org.insa.graphs.algorithm.packageswitch; import org.insa.graphs.algorithm.AbstractAlgorithm; -public abstract class PackageSwitchAlgorithm extends AbstractAlgorithm { +public abstract class PackageSwitchAlgorithm + extends AbstractAlgorithm { /** * Create a new PackageSwitchAlgorithm with the given data. - * + * * @param data */ protected PackageSwitchAlgorithm(PackageSwitchData data) { diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/BellmanFordAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/BellmanFordAlgorithm.java index 42986aa..709438e 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/BellmanFordAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/BellmanFordAlgorithm.java @@ -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; diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathAlgorithm.java index 005e40c..fdebcd6 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathAlgorithm.java @@ -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 { +public abstract class ShortestPathAlgorithm + extends AbstractAlgorithm { protected ShortestPathAlgorithm(ShortestPathData data) { super(data); @@ -24,45 +25,45 @@ public abstract class ShortestPathAlgorithm extends AbstractAlgorithm> implements PriorityQueue { /** * Construct a copy of the given heap. - * + * * @param heap Binary heap to copy. */ public BinaryHeap(BinaryHeap heap) { @@ -39,7 +37,7 @@ public class BinaryHeap> implements PriorityQueue { /** * Set an element at the given index. - * + * * @param index Index at which the element should be set. * @param value Element to set. */ @@ -68,15 +66,14 @@ public class BinaryHeap> implements PriorityQueue { /** * Internal method to percolate up in the heap. - * + * * @param index Index at which the percolate begins. */ 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); } @@ -86,7 +83,7 @@ public class BinaryHeap> implements PriorityQueue { /** * Internal method to percolate down in the heap. - * + * * @param index Index at which the percolate begins. */ private void percolateDown(int index) { @@ -158,7 +155,7 @@ public class BinaryHeap> implements PriorityQueue { /** * Creates a multi-lines string representing a sorted view of this binary heap. - * + * * @return a string containing a sorted view this binary heap. */ public String toStringSorted() { @@ -167,10 +164,9 @@ public class BinaryHeap> implements PriorityQueue { /** * 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) { @@ -179,7 +175,7 @@ public class BinaryHeap> implements PriorityQueue { /** * Creates a multi-lines string representing a tree view of this binary heap. - * + * * @return a string containing a tree view of this binary heap. */ public String toStringTree() { @@ -188,9 +184,8 @@ public class BinaryHeap> implements PriorityQueue { /** * 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) { diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java index adad622..a0468fe 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java @@ -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 { @@ -22,9 +21,9 @@ 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) { @@ -35,9 +34,8 @@ 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,40 +43,40 @@ 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)); } } /** * 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 > Context toStringLoop(BinaryHeap 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. - * - * @param heap The binary heap to display. + * Creates a multi-lines string representing a tree view of the given binary heap. + * + * @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 > String toStringTree(BinaryHeap heap, int maxDepth) { + public static > String toStringTree(BinaryHeap 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 > String toStringSorted(BinaryHeap 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"; diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinarySearchTree.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinarySearchTree.java index 32dfbb1..f711b30 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinarySearchTree.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinarySearchTree.java @@ -17,7 +17,7 @@ public class BinarySearchTree> implements PriorityQueue< /** * Create a copy of the given binary search tree. - * + * * @param bst Binary search tree to copy. */ public BinarySearchTree(BinarySearchTree bst) { diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/ElementNotFoundException.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/ElementNotFoundException.java index 3fb2729..fad7f9d 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/ElementNotFoundException.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/ElementNotFoundException.java @@ -3,7 +3,7 @@ package org.insa.graphs.algorithm.utils; public class ElementNotFoundException extends RuntimeException { /** - * + * */ private static final long serialVersionUID = 1L; diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/EmptyPriorityQueueException.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/EmptyPriorityQueueException.java index bf09c5d..d45aa2e 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/EmptyPriorityQueueException.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/EmptyPriorityQueueException.java @@ -3,14 +3,13 @@ package org.insa.graphs.algorithm.utils; public class EmptyPriorityQueueException extends RuntimeException { /** - * + * */ private static final long serialVersionUID = 1L; /** - * + * */ - public EmptyPriorityQueueException() { - } + public EmptyPriorityQueueException() {} } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/PriorityQueue.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/PriorityQueue.java index 104f79e..c7eb60b 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/PriorityQueue.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/PriorityQueue.java @@ -1,79 +1,69 @@ 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> { /** * Check if the priority queue is empty. - * *

* Complexity: O(1) *

- * + * * @return true if the queue is empty, false otherwise. */ public boolean isEmpty(); /** * Get the number of elements in this queue. - * *

* Complexity: O(1) *

- * + * * @return Current size (number of elements) of this queue. */ public int size(); /** * Insert the given element into the queue. - * *

* Complexity: O(log n) *

- * + * * @param x Item to insert. */ public void insert(E x); /** * Remove the given element from the priority queue. - * *

* Complexity: O(log n) *

- * + * * @param x Item to remove. */ public void remove(E x) throws ElementNotFoundException; /** * Retrieve (but not remove) the smallest item in the queue. - * *

* Complexity: O(1) *

- * + * * @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. - * *

* Complexity: O(log n) *

- * + * * @return The smallest item in the queue. - * * @throws EmptyPriorityQueueException if this queue is empty. */ public E deleteMin() throws EmptyPriorityQueueException; diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentObserver.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentObserver.java index e7b0a5a..e47dbcb 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentObserver.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentObserver.java @@ -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 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 nodes); + /** + * 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 the algorithm has computed a new component. + * + * @param nodes List of nodes in the component. + */ + public void notifyEndComponent(ArrayList nodes); } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentTextObserver.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentTextObserver.java index 1a725c7..862ebc7 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentTextObserver.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentTextObserver.java @@ -5,32 +5,33 @@ import java.util.ArrayList; import org.insa.graphs.model.Node; -public class WeaklyConnectedComponentTextObserver implements WeaklyConnectedComponentObserver { - - // Number of the current component. - private int numComponent = 1; - - // Output stream - PrintStream stream; +public class WeaklyConnectedComponentTextObserver + implements WeaklyConnectedComponentObserver { - public WeaklyConnectedComponentTextObserver(PrintStream stream) { - this.stream = stream; - } + // Number of the current component. + private int numComponent = 1; - @Override - public void notifyStartComponent(Node curNode) { - stream.print("Entering component #" + numComponent + " from node #" + curNode.getId() + "... "); - } + // Output stream + PrintStream stream; - @Override - public void notifyNewNodeInComponent(Node node) { - } + public WeaklyConnectedComponentTextObserver(PrintStream stream) { + this.stream = stream; + } - @Override - public void notifyEndComponent(ArrayList nodes) { - stream.println(nodes.size() + " nodes found."); - stream.flush(); - numComponent += 1; - } + @Override + public void notifyStartComponent(Node curNode) { + stream.print("Entering component #" + numComponent + " from node #" + + curNode.getId() + "... "); + } + + @Override + public void notifyNewNodeInComponent(Node node) {} + + @Override + public void notifyEndComponent(ArrayList nodes) { + stream.println(nodes.size() + " nodes found."); + stream.flush(); + numComponent += 1; + } } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java index 42462bb..74cc623 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java @@ -34,34 +34,33 @@ public class WeaklyConnectedComponentsAlgorithm /** * Notify all observers that the algorithm is entering a new component. - * + * * @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); } } /** * Notify all observers that the algorithm has computed a new component. - * + * * @param nodes List of nodes in the component. */ protected void notifyEndComponent(ArrayList nodes) { - for (WeaklyConnectedComponentObserver obs: getObservers()) { + for (WeaklyConnectedComponentObserver obs : getObservers()) { obs.notifyEndComponent(nodes); } } @@ -77,8 +76,8 @@ public class WeaklyConnectedComponentsAlgorithm res.add(new HashSet()); } - 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 bfs(ArrayList> ugraph, boolean[] marked, int cur) { + protected ArrayList bfs(ArrayList> ugraph, boolean[] marked, + int cur) { Graph graph = getInputData().getGraph(); ArrayList component = new ArrayList(); @@ -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); } } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsSolution.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsSolution.java index a0b2d4a..ac422f4 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsSolution.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsSolution.java @@ -14,8 +14,8 @@ public class WeaklyConnectedComponentsSolution extends AbstractSolution { super(data); } - protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data, Status status, - ArrayList> components) { + protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data, + Status status, ArrayList> components) { super(data, status); this.components = components; } @@ -34,14 +34,14 @@ public class WeaklyConnectedComponentsSolution extends AbstractSolution { /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override public String toString() { int nIsolated = 0; int nGt10 = 0; - for (ArrayList component: components) { + for (ArrayList 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."; } diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinaryHeapTest.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinaryHeapTest.java index df91636..ba9b9ed 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinaryHeapTest.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinaryHeapTest.java @@ -8,7 +8,8 @@ public class BinaryHeapTest extends PriorityQueueTest { } @Override - public PriorityQueue createQueue(PriorityQueue queue) { + public PriorityQueue createQueue( + PriorityQueue queue) { return new BinaryHeap<>((BinaryHeap) queue); } diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinarySearchTreeTest.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinarySearchTreeTest.java index 803846d..102e440 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinarySearchTreeTest.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinarySearchTreeTest.java @@ -8,7 +8,8 @@ public class BinarySearchTreeTest extends PriorityQueueTest { } @Override - public PriorityQueue createQueue(PriorityQueue queue) { + public PriorityQueue createQueue( + PriorityQueue queue) { return new BinarySearchTree<>((BinarySearchTree) queue); } diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/PriorityQueueTest.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/PriorityQueueTest.java index c796598..2da689f 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/PriorityQueueTest.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/PriorityQueueTest.java @@ -25,7 +25,7 @@ public abstract class PriorityQueueTest { /** * Needs to be implemented by child class to actually provide priority queue * implementation. - * + * * @return A new instance of a PriorityQueue implementation. */ public abstract PriorityQueue createQueue(); @@ -33,12 +33,12 @@ public abstract class PriorityQueueTest { /** * Needs to be implemented by child class to actually provide priority queue * implementation. - * + * * @param queue Queue to copy. - * * @return Copy of the given queue. */ - public abstract PriorityQueue createQueue(PriorityQueue queue); + public abstract PriorityQueue createQueue( + PriorityQueue queue); protected static class MutableInteger implements Comparable { @@ -58,7 +58,7 @@ public abstract class PriorityQueueTest { /** * Update the integer value stored inside this MutableInteger. - * + * * @param value New value to set. */ public void set(int value) { @@ -92,7 +92,6 @@ public abstract class PriorityQueueTest { /** * Set of parameters. - * */ @Parameters public static Collection 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 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 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); diff --git a/be-graphes-gui/pom.xml b/be-graphes-gui/pom.xml index 8efa922..6a27386 100644 --- a/be-graphes-gui/pom.xml +++ b/be-graphes-gui/pom.xml @@ -1,8 +1,5 @@ - + 4.0.0 org.insa.graphs @@ -16,7 +13,7 @@ be-graphes-gui be-graphes-gui - + @@ -26,13 +23,13 @@ - + org.insa.graphs be-graphes-model ${project.version} - + org.insa.graphs be-graphes-algos diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/AlgorithmPanel.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/AlgorithmPanel.java index 75da459..8c5f4b1 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/AlgorithmPanel.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/AlgorithmPanel.java @@ -34,14 +34,14 @@ import org.insa.graphs.model.Node; public class AlgorithmPanel extends JPanel implements DrawingChangeListener { /** - * + * */ private static final long serialVersionUID = 1L; public class StartActionEvent extends ActionEvent { /** - * + * */ private static final long serialVersionUID = 4090710269781229078L; @@ -57,8 +57,8 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener { private final boolean graphicVisualization; private final boolean textualVisualization; - public StartActionEvent(Class> algoClass, List nodes, - ArcInspector arcFilter, boolean graphicVisualization, + public StartActionEvent(Class> algoClass, + List nodes, ArcInspector arcFilter, boolean graphicVisualization, boolean textualVisualization) { super(AlgorithmPanel.this, START_EVENT_ID, START_EVENT_COMMAND); this.nodes = nodes; @@ -124,19 +124,18 @@ 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 true to enable - * {@link ArcInspector} selection. - * + * @param enableArcFilterSelection true to enable {@link ArcInspector} + * selection. * @see ArcInspectorFactory */ - public AlgorithmPanel(Component parent, Class> baseAlgorithm, - String title, String[] nodeNames, boolean enableArcFilterSelection) { + public AlgorithmPanel(Component parent, + Class> 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()), @@ -278,9 +277,8 @@ 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) { @@ -296,18 +294,15 @@ 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 createAlgoritmSelectComboBox( Class> baseAlgorithm) { - JComboBox algoSelect = new JComboBox<>( - AlgorithmFactory.getAlgorithmNames(baseAlgorithm).toArray(new String[0])); + JComboBox algoSelect = new JComboBox<>(AlgorithmFactory + .getAlgorithmNames(baseAlgorithm).toArray(new String[0])); algoSelect.setBackground(Color.WHITE); algoSelect.setAlignmentX(Component.LEFT_ALIGNMENT); return algoSelect; @@ -316,9 +311,8 @@ 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 null - * value. - * + * Check if the given list of nodes does not contain any null value. + * * @param nodes List of {@link Node} to check. - * * @return true if the list does not contain any null * value, false otherwise. */ protected boolean allNotNull(List 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); @@ -363,7 +355,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener { /** * Add a new start action listener to this class. - * + * * @param listener Listener to add. */ public void addStartActionListener(ActionListener listener) { @@ -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() {} } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/DrawingChangeListener.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/DrawingChangeListener.java index 40d6bfd..dd618a0 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/DrawingChangeListener.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/DrawingChangeListener.java @@ -6,18 +6,16 @@ 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(); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphChangeListener.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphChangeListener.java index d438b7d..3a29eea 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphChangeListener.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphChangeListener.java @@ -6,7 +6,7 @@ public interface GraphChangeListener { /** * Event fire when a new graph has been loaded. - * + * * @param graph The new graph. */ public void newGraphLoaded(Graph graph); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphReaderProgressBar.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphReaderProgressBar.java index 8827a40..1ee0701 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphReaderProgressBar.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphReaderProgressBar.java @@ -19,14 +19,13 @@ import org.insa.graphs.model.io.GraphReaderObserver; /** * One-time use GraphReaderObserver that display progress in three different * JProgressBar. - * - * @author Mikael * + * @author Mikael */ public class GraphReaderProgressBar extends JDialog implements GraphReaderObserver { /** - * + * */ private static final long serialVersionUID = -1; @@ -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) { diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/MainWindow.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/MainWindow.java index 41ff400..dbd15fc 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/MainWindow.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/MainWindow.java @@ -75,17 +75,17 @@ import org.insa.graphs.model.io.MapMismatchException; public class MainWindow extends JFrame { /** - * + * */ private static final long serialVersionUID = 1L; /** - * + * */ private static final String WINDOW_TITLE = "BE Graphes INSA"; /** - * + * */ private static final int THREAD_TIMER_DELAY = 1000; // in milliseconds @@ -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,19 +437,19 @@ 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); } } /** * Notify all listeners that a new drawing has been set up. - * + * * @param oldDrawing * @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, @@ -566,7 +576,7 @@ public class MainWindow extends JFrame { } /** - * + * */ private void drawGraph() { drawGraph(null, this.currentPalette); @@ -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); } } @@ -622,12 +634,12 @@ public class MainWindow extends JFrame { /** * Show and enable the given AlgorithmPanel (and hide all others). - * + * * @param algorithmPanel */ 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()); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/NodesInputPanel.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/NodesInputPanel.java index 0c41fe7..d7ba90f 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/NodesInputPanel.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/NodesInputPanel.java @@ -33,16 +33,14 @@ public class NodesInputPanel extends JPanel implements DrawingClickListener, DrawingChangeListener, GraphChangeListener { /** - * + * */ private static final long serialVersionUID = 1L; 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,12 +78,11 @@ public class NodesInputPanel extends JPanel /** * Event data send when a node input has changed. - * */ public class InputChangedEvent extends ActionEvent { /** - * + * */ private static final long serialVersionUID = 3440024811352247731L; @@ -98,7 +94,8 @@ public class NodesInputPanel extends JPanel List nodes; public InputChangedEvent(List 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 nodeInputs = new ArrayList<>(); - private final Map markerTrackers = new IdentityHashMap(); + private final Map markerTrackers = + new IdentityHashMap(); // Component that can be enabled/disabled. private ArrayList 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 nodes = getNodeForInputs(); // Trigger change event. - for (ActionListener lis: inputChangeListeners) { + for (ActionListener lis : inputChangeListeners) { lis.actionPerformed(new InputChangedEvent(nodes)); } } @@ -317,21 +313,21 @@ 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 getNodeForInputs() { List 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 */ protected JTextField getInputToFill() { @@ -350,7 +346,7 @@ public class NodesInputPanel extends JPanel /** * Set the next input to fill to the given text field. - * + * * @param input */ protected void setInputToFill(JTextField input) { @@ -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(), diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/PathsPanel.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/PathsPanel.java index 29ea418..80d628c 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/PathsPanel.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/PathsPanel.java @@ -41,23 +41,23 @@ 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 { /** - * + * */ private static final long serialVersionUID = 1L; private class PathPanel extends JPanel { /** - * + * */ private static final long serialVersionUID = 1L; /** * Simple icon that represents a unicolor rectangle. - * */ protected class ColorIcon implements Icon { @@ -103,11 +103,9 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh /** * Create a new bundle with the given path and create a new overlay * 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; @@ -287,7 +290,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ public String toString() { @@ -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(); } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/SolutionPanel.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/SolutionPanel.java index e96bcef..b41812d 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/SolutionPanel.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/SolutionPanel.java @@ -26,10 +26,11 @@ 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 { /** - * + * */ private static final long serialVersionUID = 1L; @@ -44,9 +45,8 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap /** * Create a new bundle with the given solution and create a new overlay * 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 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 { @@ -122,7 +121,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ public String toString() { @@ -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); } } @@ -224,10 +226,9 @@ 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(); } } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/StreamCapturer.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/StreamCapturer.java index 0a7d010..c70c3f9 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/StreamCapturer.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/StreamCapturer.java @@ -23,7 +23,7 @@ public class StreamCapturer extends OutputStream { /** * Create a new StreamCapturer without prefix. - * + * * @param output Output JTextArea to which this stream should print. */ public StreamCapturer(JTextArea output) { diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BasicGraphPalette.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BasicGraphPalette.java index 7c7d26e..630d782 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BasicGraphPalette.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BasicGraphPalette.java @@ -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; } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BlackAndWhiteGraphPalette.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BlackAndWhiteGraphPalette.java index 3141227..7c9fc91 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BlackAndWhiteGraphPalette.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BlackAndWhiteGraphPalette.java @@ -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) { diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Drawing.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Drawing.java index ee2a018..d636def 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Drawing.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Drawing.java @@ -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 { @@ -30,14 +30,14 @@ public interface Drawing { /** * Add a listener to click to this drawing. - * + * * @param listener DrawingClickListener to add to this Drawing. */ public void addDrawingClickListener(DrawingClickListener listener); /** * Remove the given listener from the drawing. - * + * * @param listener DrawingClickListener to remove from this Drawing. */ public void removeDrawingClickListener(DrawingClickListener listener); @@ -53,47 +53,43 @@ 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); /** * Draw the given graph using the given palette. - * + * * @param graph Graph to draw. * @param palette Palette to use to draw the graph. - * * @see BasicGraphPalette * @see BlackAndWhiteGraphPalette */ @@ -101,42 +97,37 @@ public interface Drawing { /** * Draw the given graph using a default palette specific to the implementation. - * + * * @param graph Graph to draw. */ public void drawGraph(Graph graph); /** * Draw a path using the given color. - * + * * @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); /** * Draw a path with both origin and destination markers using the given color. - * + * * @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); /** * Draw a path using a default color specific to the implementation - * + * * @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); @@ -144,12 +135,9 @@ 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); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/DrawingClickListener.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/DrawingClickListener.java index fddfd9a..494603b 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/DrawingClickListener.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/DrawingClickListener.java @@ -6,7 +6,7 @@ public interface DrawingClickListener { /** * Event triggered when a click is made on the map. - * + * * @param point Position (on the map) of the mouse click. */ public void mouseClicked(Point point); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/GraphPalette.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/GraphPalette.java index 00af58d..2091d6a 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/GraphPalette.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/GraphPalette.java @@ -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); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/MercatorProjection.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/MercatorProjection.java index 374c20d..c680cb1 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/MercatorProjection.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/MercatorProjection.java @@ -28,10 +28,10 @@ public class MercatorProjection implements Projection { /** * Create a new MercatorProjection corresponding to the given BoundingBox and * 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. @@ -51,9 +51,8 @@ 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 diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/PlateCarreProjection.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/PlateCarreProjection.java index 0b15490..48e33f1 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/PlateCarreProjection.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/PlateCarreProjection.java @@ -13,10 +13,10 @@ public class PlateCarreProjection implements Projection { /** * Create a new PlateCarreProjection corresponding to the given BoundingBox and * 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); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Projection.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Projection.java index f05dd9c..9e2eadb 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Projection.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Projection.java @@ -14,36 +14,32 @@ 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); /** * 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); /** * 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); /** * 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); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java index 6d51a05..333a20c 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java @@ -45,7 +45,7 @@ import org.insa.graphs.model.GraphStatistics.BoundingBox; public class BasicDrawing extends JPanel implements Drawing { /** - * + * */ private static final long serialVersionUID = 96779785877771827L; @@ -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 points, Color color, BasicMarkerOverlay origin, - BasicMarkerOverlay destination) { + public BasicPathOverlay(List 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 arr: this.overlays) { - for (BasicOverlay overlay: arr) { + for (ArrayList 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 arr: this.overlays) { + for (ArrayList 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); } } @@ -476,7 +476,7 @@ public class BasicDrawing extends JPanel implements Drawing { /* * (non-Javadoc) - * + * * @see org.insa.graphics.drawing.Drawing#clear() */ @Override @@ -490,7 +490,7 @@ public class BasicDrawing extends JPanel implements Drawing { /* * (non-Javadoc) - * + * * @see org.insa.graphics.drawing.Drawing#clearOverlays() */ @Override @@ -508,16 +508,14 @@ public class BasicDrawing extends JPanel implements Drawing { /** * Return the longitude and latitude corresponding to the given position of the * 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]). @@ -531,9 +529,8 @@ 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 @@ -543,7 +540,7 @@ public class BasicDrawing extends JPanel implements Drawing { /* * (non-Javadoc) - * + * * @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa. * graphics.drawing.DrawingClickListener) */ @@ -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 @@ -575,17 +575,18 @@ 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 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 it1 = pts.iterator(); Point prev = it1.next(); @@ -608,7 +609,7 @@ public class BasicDrawing extends JPanel implements Drawing { /** * Initialize the drawing for the given graph. - * + * * @param graph */ protected void initialize(Graph graph) { @@ -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 points = new ArrayList(); if (!path.isEmpty()) { points.add(path.getOrigin().getPoint()); - for (Arc arc: path.getArcs()) { + for (Arc arc : path.getArcs()) { Iterator 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); } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapViewDrawing.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapViewDrawing.java index 604a6db..36f15a6 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapViewDrawing.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapViewDrawing.java @@ -56,13 +56,12 @@ import org.mapsforge.map.rendertheme.InternalRenderTheme; public class MapViewDrawing extends MapView implements Drawing { /** - * + * */ private static final long serialVersionUID = 8606967833704938092L; /** * 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 points = new ArrayList<>(); private final Polygon polygon; @@ -205,8 +204,9 @@ public class MapViewDrawing extends MapView implements Drawing { List 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(); } @@ -340,14 +342,15 @@ public class MapViewDrawing extends MapView implements Drawing { /* * (non-Javadoc) - * + * * @see org.mapsforge.map.awt.view.MapView#paint(java.awt.Graphics) */ @Override 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); @@ -357,7 +360,7 @@ public class MapViewDrawing extends MapView implements Drawing { /* * (non-Javadoc) - * + * * @see org.insa.graphics.drawing.Drawing#clear() */ @Override @@ -368,14 +371,15 @@ public class MapViewDrawing extends MapView implements Drawing { /* * (non-Javadoc) - * + * * @see org.insa.graphics.drawing.Drawing#clearOverlays() */ @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 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 { diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapZoomControls.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapZoomControls.java index 0db6628..3d25d7e 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapZoomControls.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapZoomControls.java @@ -61,8 +61,8 @@ public class MapZoomControls { private final List zoomInListeners = new ArrayList<>(); private final List 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(); @@ -109,7 +111,7 @@ public class MapZoomControls { /** * Add a zoom-in listener. - * + * * @param listener Zoom-in listener to add to this MapZoomControls instance. */ public void addZoomInListener(ActionListener listener) { @@ -118,7 +120,7 @@ public class MapZoomControls { /** * Add a zoom-out listener. - * + * * @param listener Zoom-out listener to add to this MapZoomControls instance. */ public void addZoomOutListener(ActionListener listener) { @@ -134,7 +136,7 @@ public class MapZoomControls { /** * Set the current zoom level without requesting a redraw. - * + * * @param level Zoom level to set. */ public void setZoomLevel(int level) { @@ -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(); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/ZoomAndPanListener.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/ZoomAndPanListener.java index fc43671..5f8d002 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/ZoomAndPanListener.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/ZoomAndPanListener.java @@ -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(); @@ -174,4 +177,4 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M public void setCoordTransform(AffineTransform coordTransform) { this.coordTransform = coordTransform; } -} \ No newline at end of file +} diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerAutoScaling.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerAutoScaling.java index 6d6b097..43e2277 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerAutoScaling.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerAutoScaling.java @@ -12,12 +12,10 @@ 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) * @see PaintUtils#getStrokeWidth(int, byte) @@ -29,7 +27,7 @@ public class MarkerAutoScaling extends Marker { /** * Create a new MarkerAutoScaling at the given position with the given image. - * + * * @param latLong Initial position of the marker. * @param image Image for this marker. */ @@ -40,7 +38,7 @@ public class MarkerAutoScaling extends Marker { /** * Set a new image for this marker overlay - * + * * @param image New image to set. */ public void setImage(Image image) { @@ -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); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerOverlay.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerOverlay.java index 75b01b5..6575e3c 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerOverlay.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerOverlay.java @@ -11,7 +11,7 @@ public interface MarkerOverlay extends Overlay { /** * Move this marker to the specified location. - * + * * @param point New position for the marker. */ public void moveTo(Point point); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerUtils.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerUtils.java index 523d5d9..22248a2 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerUtils.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerUtils.java @@ -12,11 +12,10 @@ public class MarkerUtils { /** * Create an image to represent a marker using the given color for the outer and * inner part, and the given mode for the inner part. - * + * * @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. diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/Overlay.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/Overlay.java index 8815c57..9883268 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/Overlay.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/Overlay.java @@ -6,7 +6,7 @@ public interface Overlay { /** * Set the color of this overlay. - * + * * @param color New color for the overlay. */ public void setColor(Color color); @@ -18,7 +18,7 @@ public interface Overlay { /** * Show or hide this marker - A marker should be visible when created. - * + * * @param visible true to show the marker, false to hide. */ public void setVisible(boolean visible); diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PaintUtils.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PaintUtils.java index a2c4929..7ba1ee5 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PaintUtils.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PaintUtils.java @@ -14,21 +14,19 @@ 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) { diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PointSetOverlay.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PointSetOverlay.java index ec105a6..a9f3d2e 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PointSetOverlay.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PointSetOverlay.java @@ -8,14 +8,14 @@ public interface PointSetOverlay extends Overlay { /** * Set the width of this overlay for future addPoint(). - * + * * @param width New default width for this overlay. */ public void setWidth(int width); /** * Set color and width for this overlay for future addPoint(). - * + * * @param width New default width for this overlay. * @param color New default color for this overlay. */ @@ -23,9 +23,8 @@ 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) */ @@ -33,10 +32,9 @@ public interface PointSetOverlay extends Overlay { /** * Set the current width and then add a new point. - * + * * @param point Position of the point to add. * @param width New default width for this overlay. - * * @see #setWidth(int) * @see PointSetOverlay#addPoint(Point) */ @@ -44,23 +42,21 @@ public interface PointSetOverlay extends Overlay { /** * Set the current color and then add a new point. - * + * * @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) diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PolylineAutoScaling.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PolylineAutoScaling.java index e18d0ae..2846c53 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PolylineAutoScaling.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PolylineAutoScaling.java @@ -15,11 +15,10 @@ 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) */ public class PolylineAutoScaling extends Polyline { @@ -32,10 +31,9 @@ public class PolylineAutoScaling extends Polyline { /** * Create a new PolylineAutoScaling with the given width and color. - * + * * @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) { @@ -47,7 +45,7 @@ public class PolylineAutoScaling extends Polyline { /** * Set the color for this polyline. - * + * * @param color New color for this polyline. */ public void setColor(Color color) { @@ -73,18 +71,19 @@ public class PolylineAutoScaling extends Polyline { */ public void addAll(Collection points) { ArrayList 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); } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/observers/WeaklyConnectedComponentGraphicObserver.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/observers/WeaklyConnectedComponentGraphicObserver.java index 426e3ff..53b313a 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/observers/WeaklyConnectedComponentGraphicObserver.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/observers/WeaklyConnectedComponentGraphicObserver.java @@ -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; diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java index 301cfc9..34f0efb 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java @@ -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 folderToEntry = new EnumMap<>( - FolderType.class); + private static final Map folderToEntry = + new EnumMap<>(FolderType.class); // Map folder type -> File Filter - private static final Map folderToFilter = new EnumMap<>( - FolderType.class); + private static final Map 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) { diff --git a/be-graphes-model/pom.xml b/be-graphes-model/pom.xml index 6f62a74..a63feff 100644 --- a/be-graphes-model/pom.xml +++ b/be-graphes-model/pom.xml @@ -1,17 +1,14 @@ - + 4.0.0 - + org.insa.graphs be-graphes-all 0.0.1-SNAPSHOT - + be-graphes-model be-graphes-model - + diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/AccessRestrictions.java b/be-graphes-model/src/main/java/org/insa/graphs/model/AccessRestrictions.java index eac0077..e86d4c0 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/AccessRestrictions.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/AccessRestrictions.java @@ -7,18 +7,15 @@ import java.util.EnumSet; *

* Class containing access restrictions for roads/arcs. *

- * *

- * 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. *

- * *

- * 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. *

- * */ public class AccessRestrictions { @@ -73,24 +70,20 @@ public class AccessRestrictions { /** * {@code EnumSet} containing all possible transport modes. - * - * */ public static final EnumSet ALL = EnumSet.allOf(AccessMode.class); /** * {@code EnumSet} containing all vehicle transport modes. - * */ - public static final EnumSet VEHICLE = EnumSet.range(AccessMode.BICYCLE, - AccessMode.PUBLIC_TRANSPORT); + public static final EnumSet VEHICLE = + EnumSet.range(AccessMode.BICYCLE, AccessMode.PUBLIC_TRANSPORT); /** * {@code EnumSet} containing all motorized vehicle transport modes. - * */ - public static final EnumSet MOTOR_VEHICLE = EnumSet - .range(AccessMode.SMALL_MOTORCYCLE, AccessMode.PUBLIC_TRANSPORT); + public static final EnumSet MOTOR_VEHICLE = + EnumSet.range(AccessMode.SMALL_MOTORCYCLE, AccessMode.PUBLIC_TRANSPORT); } /** @@ -103,53 +96,52 @@ public class AccessRestrictions { public enum AccessRestriction { /** - * + * */ ALLOWED, /** - * + * */ FORBIDDEN, /** - * + * */ PRIVATE, /** - * + * */ DESTINATION, /** - * + * */ DELIVERY, /** - * + * */ CUSTOMERS, /** - * + * */ FORESTRY, /** - * + * */ UNKNOWN; /** * {@code EnumSet} corresponding to restrictions that are not totally private. - * */ - public static final EnumSet ALLOWED_FOR_SOMETHING = EnumSet.of( - AccessRestriction.ALLOWED, AccessRestriction.DESTINATION, - AccessRestriction.DESTINATION, AccessRestriction.DELIVERY, - AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY); + public static final EnumSet ALLOWED_FOR_SOMETHING = + EnumSet.of(AccessRestriction.ALLOWED, AccessRestriction.DESTINATION, + AccessRestriction.DESTINATION, AccessRestriction.DELIVERY, + AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY); } @@ -161,16 +153,15 @@ 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); } } /** * 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 restrictions) { this.restrictions = restrictions; @@ -178,9 +169,8 @@ 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) { @@ -190,24 +180,22 @@ 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 restrictions) { + public boolean isAllowedForAny(AccessMode mode, + EnumSet restrictions) { return restrictions.contains(getRestrictionFor(mode)); } /** - * Check if the restriction for the given mode corresponds to the given - * restriction. - * - * @param mode Mode for which the restriction should be checked. + * Check if the restriction for the given mode corresponds to the given restriction. + * + * @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. */ @@ -218,10 +206,9 @@ 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. */ diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Arc.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Arc.java index 2bbed68..df34d52 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Arc.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Arc.java @@ -4,18 +4,16 @@ import java.util.List; /** *

- * 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). *

- * *

* 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. *

- * */ public abstract class Arc { @@ -36,9 +34,8 @@ 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). */ @@ -49,9 +46,8 @@ public abstract class Arc { /** * Compute and return the minimum time required to travel this arc, or the time * 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() { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/ArcBackward.java b/be-graphes-model/src/main/java/org/insa/graphs/model/ArcBackward.java index 4203fb5..db2cec9 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/ArcBackward.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/ArcBackward.java @@ -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,9 +14,8 @@ 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. */ protected ArcBackward(Arc originalArc) { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/ArcForward.java b/be-graphes-model/src/main/java/org/insa/graphs/model/ArcForward.java index df5871e..9ca5ab8 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/ArcForward.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/ArcForward.java @@ -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 { @@ -24,15 +23,15 @@ class ArcForward extends Arc { /** * Create a new ArcForward with the given attributes. - * + * * @param origin Origin of this arc. * @param dest Destination of this arc. * @param length Length of this arc (in meters). * @param roadInformation Road information for this arc. * @param points Points representing this arc. */ - protected ArcForward(Node origin, Node dest, float length, RoadInformation roadInformation, - List points) { + protected ArcForward(Node origin, Node dest, float length, + RoadInformation roadInformation, List points) { this.origin = origin; this.destination = dest; this.length = length; diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Graph.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Graph.java index 5a0cb68..da253b9 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Graph.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Graph.java @@ -8,12 +8,10 @@ import java.util.List; *

* Main graph class. *

- * *

- * This class acts as a object-oriented adjacency list 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 adjacency list for a graph, i.e., it + * holds a list of nodes and each node holds a list of its successors. *

- * */ public final class Graph { @@ -31,13 +29,14 @@ 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 nodes, GraphStatistics graphStatistics) { + public Graph(String mapId, String mapName, List 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 getNodes() { @@ -99,16 +94,17 @@ public final class Graph { */ public Graph transpose() { final ArrayList 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()); } } diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/GraphStatistics.java b/be-graphes-model/src/main/java/org/insa/graphs/model/GraphStatistics.java index 658492a..408457a 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/GraphStatistics.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/GraphStatistics.java @@ -2,30 +2,24 @@ package org.insa.graphs.model; /** *

- * 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. *

- * *

- * 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. *

- * */ 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 { @@ -34,7 +28,7 @@ public class GraphStatistics { /** * Create a new BoundingBox represented by the given top-left and bottom-right * points. - * + * * @param topLeft Top left corner of the bounding box. * @param bottomRight Bottom right corner of the bounding box. */ @@ -60,17 +54,17 @@ public class GraphStatistics { /** * Create a new bounding box by extending the current one according to the given * value for each side. - * + * * @param left Extra size to add to the left of the box. * @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)); } @@ -78,9 +72,8 @@ public class GraphStatistics { /** * Create a new bounding box by extending the current one according by the given * 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 + ")"; } } @@ -130,13 +121,13 @@ public class GraphStatistics { /** * Create a new GraphStatistics instance with the given value. - * + * * @param boundingBox Bounding-box for the graph. * @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; diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java index 778b48a..8539407 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java @@ -8,16 +8,13 @@ import java.util.List; *

* Class representing a Node in a {@link Graph}. *

- * *

* This class holds information regarding nodes in the graph together with the * successors associated to the nodes. *

- * *

* Nodes are comparable based on their ID. *

- * */ public final class Node implements Comparable { @@ -26,19 +23,17 @@ public final class Node implements Comparable { * Link the two given nodes with one or two arcs (depending on roadInformation), * with the given attributes. *

- * *

* 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. *

- * - * @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 { 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); @@ -77,8 +74,8 @@ public final class Node implements Comparable { /** * 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) { @@ -89,7 +86,7 @@ public final class Node implements Comparable { /** * Add a successor to this node. - * + * * @param arc Arc to the successor. */ protected void addSuccessor(Arc arc) { @@ -119,7 +116,6 @@ public final class Node implements Comparable { /** * @return List of successors of this node (unmodifiable list). - * * @see Collections#unmodifiableList(List) */ public List getSuccessors() { @@ -146,9 +142,8 @@ public final class Node implements Comparable { /** * 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 diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java index 82c6f57..13302dd 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java @@ -2,7 +2,6 @@ package org.insa.graphs.model; /** * Class representing a point (position) on Earth. - * */ public final class Point { @@ -13,10 +12,9 @@ public final class Point { /** * Compute the distance in meters between the two given points. - * + * * @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); } @@ -33,7 +32,7 @@ public final class Point { /** * Create a new point corresponding to the given (longitude, latitude) position. - * + * * @param longitude Longitude of the point (in degrees). * @param latitude Latitude of the point (in degrees). */ @@ -58,9 +57,8 @@ 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) { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/RoadInformation.java b/be-graphes-model/src/main/java/org/insa/graphs/model/RoadInformation.java index f5fa39c..e0472eb 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/RoadInformation.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/RoadInformation.java @@ -4,41 +4,22 @@ package org.insa.graphs.model; *

* Class containing information for road that may be shared by multiple arcs. *

- * *

- * 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). *

- * */ public class RoadInformation { /** * Enumeration for road types. - * + * * @see OpenStreetMap * reference for road types. */ 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). @@ -58,16 +39,15 @@ 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.)"; } } diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadFormatException.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadFormatException.java index 78439f0..23e5077 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadFormatException.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadFormatException.java @@ -5,12 +5,11 @@ 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 { /** - * + * */ private static final long serialVersionUID = 1270945933549613579L; @@ -23,7 +22,7 @@ public class BadFormatException extends IOException { /** * Create a new format exception with the given message. - * + * * @param message Message for the exception. */ public BadFormatException(String message) { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadMagicNumberException.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadMagicNumberException.java index 31d9f42..5bb4799 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadMagicNumberException.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadMagicNumberException.java @@ -1,14 +1,12 @@ 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 { /** - * + * */ private static final long serialVersionUID = -2176603967548838864L; @@ -18,13 +16,13 @@ public class BadMagicNumberException extends BadFormatException { /** * Create a new BadMagicNumberException with the given expected and actual magic * number. - * + * * @param actualNumber Actual magic number (read from a file). * @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; } diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadVersionException.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadVersionException.java index 892f534..808d6ab 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadVersionException.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BadVersionException.java @@ -1,14 +1,12 @@ 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 { /** - * + * */ private static final long serialVersionUID = 7776317018302386042L; @@ -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. */ diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryGraphReader.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryGraphReader.java index 84833e8..9e52574 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryGraphReader.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryGraphReader.java @@ -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 { @@ -36,9 +35,8 @@ 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 restrictions = new EnumMap<>(AccessMode.class); + final EnumMap restrictions = + new EnumMap<>(AccessMode.class); long copyAccess = access; - for (AccessMode mode: allModes) { + for (AccessMode mode : allModes) { if (mode == null) { continue; // filling cells } @@ -84,58 +85,56 @@ 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; } /** * Create a new BinaryGraphReader that read from the given input stream. - * + * * @param dis Input stream to read from. */ public BinaryGraphReader(DataInputStream dis) { @@ -181,8 +180,10 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader { final ArrayList nodes = new ArrayList(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()); } } diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathReader.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathReader.java index 4aca938..7ebb8f9 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathReader.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathReader.java @@ -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 { @@ -20,7 +19,7 @@ public class BinaryPathReader extends BinaryReader implements PathReader { /** * Create a new BinaryPathReader that read from the given input stream. - * + * * @param dis Input stream to read from. */ public BinaryPathReader(DataInputStream dis) { @@ -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()); @@ -59,12 +59,10 @@ 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 { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathWriter.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathWriter.java index 52b00df..4cc1cc8 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathWriter.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryPathWriter.java @@ -9,13 +9,12 @@ import org.insa.graphs.model.Path; /** * Implementation of {@link PathWriter} to write paths in binary format. - * */ public class BinaryPathWriter extends BinaryWriter implements PathWriter { /** * Create a new BinaryPathWriter that writes to the given output stream. - * + * * @param dos Output stream to write to. */ public BinaryPathWriter(DataOutputStream dos) { @@ -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()); } diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryReader.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryReader.java index 159a59b..b73a745 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryReader.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryReader.java @@ -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) { @@ -62,25 +60,23 @@ 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'. - * - * @param length Number of bytes to read. + * 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 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(); @@ -109,9 +104,8 @@ public abstract class BinaryReader implements AutoCloseable, Closeable { /** * Read 24 bits in BigEndian order from the stream and return the corresponding * 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 { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryWriter.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryWriter.java index 34cad06..8152afe 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryWriter.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/BinaryWriter.java @@ -6,7 +6,6 @@ import java.io.IOException; /** * Base class for writing binary file. - * */ public abstract class BinaryWriter implements AutoCloseable, Closeable { @@ -15,7 +14,7 @@ public abstract class BinaryWriter implements AutoCloseable, Closeable { /** * Create a new BinaryWriter that writes to the given output stream. - * + * * @param dos Stream to write to. */ protected BinaryWriter(DataOutputStream dos) { @@ -29,9 +28,8 @@ 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 { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReader.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReader.java index 29ed437..7d01fb1 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReader.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReader.java @@ -7,32 +7,28 @@ import org.insa.graphs.model.Graph; /** * Base interface for classes that can read graph. - * */ public interface GraphReader extends AutoCloseable, Closeable { /** * Add a new observer to this graph reader. - * + * * @param observer Observer to add. */ public void addObserver(GraphReaderObserver observer); /** * 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; /** * Close this graph reader. - * + * * @throws IOException if an exception occurs while closing the reader. - * */ public void close() throws IOException; diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReaderObserver.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReaderObserver.java index 4f25835..6722c55 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReaderObserver.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/GraphReaderObserver.java @@ -5,16 +5,15 @@ 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. */ public void notifyStartReading(String mapId); @@ -26,42 +25,42 @@ public interface GraphReaderObserver { /** * Notify that the reader is starting to read node. - * + * * @param nNodes Number of nodes to read. */ public void notifyStartReadingNodes(int nNodes); /** * Notify that a new nodes has been read. - * + * * @param node read. */ public void notifyNewNodeRead(Node node); /** * Notify that the reader is starting to read descriptor/road informations. - * + * * @param nDesc Number of descriptors to read. */ public void notifyStartReadingDescriptors(int nDesc); /** * Notify that a new descriptor has been read. - * + * * @param desc Descriptor read. */ public void notifyNewDescriptorRead(RoadInformation desc); /** * Notify that the reader is starting to read arcs. - * + * * @param nArcs Number of arcs to read (!= number of arcs in the graph). */ public void notifyStartReadingArcs(int nArcs); /** * Notify that a new arc has been read. - * + * * @param arc Arc read. */ public void notifyNewArcRead(Arc arc); diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/MapMismatchException.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/MapMismatchException.java index ea80056..f559d74 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/MapMismatchException.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/MapMismatchException.java @@ -3,14 +3,13 @@ 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 { /** - * + * */ private static final long serialVersionUID = 1L; @@ -19,8 +18,8 @@ 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) { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathReader.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathReader.java index e14a5a2..4d6ff7c 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathReader.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathReader.java @@ -8,26 +8,22 @@ import org.insa.graphs.model.Path; /** * Base interface that should be implemented by class used to read paths. - * */ 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; /** * Close this graph reader. - * + * * @throws IOException if an exception occurs while closing the reader. - * */ public void close() throws IOException; diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathWriter.java b/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathWriter.java index b261763..e094e8e 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathWriter.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/io/PathWriter.java @@ -7,24 +7,21 @@ import org.insa.graphs.model.Path; /** * Base interface that should be implemented by class used to write paths. - * */ 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; /** * Close this graph reader. - * + * * @throws IOException if an exception occurs while closing the reader. - * */ public void close() throws IOException; diff --git a/be-graphes-model/src/test/java/org/insa/graphes/model/GraphTest.java b/be-graphes-model/src/test/java/org/insa/graphes/model/GraphTest.java index f9333b9..34e1989 100644 --- a/be-graphes-model/src/test/java/org/insa/graphes/model/GraphTest.java +++ b/be-graphes-model/src/test/java/org/insa/graphes/model/GraphTest.java @@ -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 getArcsBetween(Node a, Node b) { List arcs = new ArrayList<>(); - for (Arc arc: a.getSuccessors()) { + for (Arc arc : a.getSuccessors()) { if (arc.getDestination().equals(b)) { arcs.add(arc); } diff --git a/be-graphes-model/src/test/java/org/insa/graphes/model/NodeTest.java b/be-graphes-model/src/test/java/org/insa/graphes/model/NodeTest.java index 057c5d5..b2146d1 100644 --- a/be-graphes-model/src/test/java/org/insa/graphes/model/NodeTest.java +++ b/be-graphes-model/src/test/java/org/insa/graphes/model/NodeTest.java @@ -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; } diff --git a/be-graphes-model/src/test/java/org/insa/graphes/model/PathTest.java b/be-graphes-model/src/test/java/org/insa/graphes/model/PathTest.java index fbef0f3..e8cf97e 100644 --- a/be-graphes-model/src/test/java/org/insa/graphes/model/PathTest.java +++ b/be-graphes-model/src/test/java/org/insa/graphes/model/PathTest.java @@ -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] })); } } diff --git a/eclipse-java-google-style.xml b/eclipse-java-google-style.xml new file mode 100644 index 0000000..840826c --- /dev/null +++ b/eclipse-java-google-style.xml @@ -0,0 +1,338 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 260a625..bcd9806 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 org.insa.graphs