Normalize spaces and blank lines according to Java Code Conventions and fix saveToTextFile #12

Merged
antograb merged 1 commits from normalizeSpaces into master 2017-12-16 12:26:26 +00:00
18 changed files with 103 additions and 118 deletions

No files matched your search

+1
View File
@@ -2,3 +2,4 @@
*.css
src/package-list
src/script.js
*.class
+4 -2
View File
@@ -9,9 +9,11 @@ public class MainTest {
Maze mazeTest = new Maze("data/labyrinthe.txt");
Previous previous = (Previous) Dijkstra.dijkstra(mazeTest, mazeTest.getMaze()[1][1]);
Previous previous =
(Previous) Dijkstra.dijkstra(mazeTest, mazeTest.getMaze()[1][1]);
ArrayList<VertexInterface> shortest = previous.getShortestPathTo(mazeTest.getMaze()[5][5]);
ArrayList<VertexInterface> shortest =
previous.getShortestPathTo(mazeTest.getMaze()[5][5]);
for (VertexInterface vertex : shortest) {
System.out.println(vertex);
+1 -9
View File
@@ -4,29 +4,21 @@ import java.util.HashSet;
public class ASet implements ASetInterface {
private HashSet<VertexInterface> vertexHashSet = new HashSet<VertexInterface>() ;
private HashSet<VertexInterface> vertexHashSet;
public ASet(HashSet<VertexInterface> vertexHashSet) {
this.vertexHashSet = new HashSet<VertexInterface>(vertexHashSet);
}
public void add(VertexInterface vertex) {
vertexHashSet.add(vertex);
}
public boolean contains(VertexInterface vertex) {
return vertexHashSet.contains(vertex);
}
public HashSet<VertexInterface> getVertexHashSet() {
return vertexHashSet;
}
}
+6 -5
View File
@@ -3,8 +3,10 @@ package dijkstra;
import java.util.HashSet;
/**
* This is the ASet class as described in the INF101 course of Telecom Paristech.
* The ASet contains vertexes for which the shortest path has already been found (vertexes already examined by the dijkstra algorithm).
* This is the ASet class as described in the
* INF101 course of Telecom Paristech.
* The ASet contains vertexes for which the shortest path
* has already been found (vertexes already examined by the dijkstra algorithm).
*/
public interface ASetInterface {
@@ -19,7 +21,8 @@ public interface ASetInterface {
* Checks if a vertex belongs to the set.
* @param vertex
* The element we must check if it belongs to the set.
* @return <code>true</code> if the element is in the set, <code>false</code> if not.
* @return <code>true</code> if the element is in the set,
* <code>false</code> if not.
*/
public boolean contains(VertexInterface vertex);
@@ -28,6 +31,4 @@ public interface ASetInterface {
* @return A <code>HashSet</code> containing the same elements as in the set.
*/
public HashSet<VertexInterface> getVertexHashSet();
}
+15 -14
View File
@@ -5,23 +5,25 @@ import java.util.Hashtable;
public class Dijkstra {
private static PreviousInterface dijkstra(GraphInterface g, VertexInterface r, ASetInterface a, PiInterface pi, PreviousInterface previous) {
private static PreviousInterface dijkstra(GraphInterface g,
VertexInterface r,
ASetInterface a,
PiInterface pi,
PreviousInterface previous) {
a.add(r) ;
VertexInterface pivot = r;
pi.setPi(0, r) ;
ArrayList<VertexInterface> vertexList = g.getVertexes();
a.add(r);
pi.setPi(0, r);
for (VertexInterface vertex: vertexList) {
if (vertex != r) {
pi.setPi(Integer.MAX_VALUE, vertex);
}
}
int n = g.getVertexNumber();
for (int j = 0; j < n; j++) {
for (int j = 0; j < g.getVertexNumber(); j++) {
for (VertexInterface vertex: g.generateNeighbours(pivot)) {
if (! a.contains(vertex)) {
if (pi.getPi(pivot) + g.getCost(pivot, vertex) < pi.getPi(vertex)) {
@@ -42,24 +44,23 @@ public class Dijkstra {
}
return previous;
}
public static PreviousInterface dijkstra(GraphInterface g, VertexInterface r) {
public static PreviousInterface dijkstra(GraphInterface g,
VertexInterface r) {
HashSet<VertexInterface> vertexHashSet = new HashSet<VertexInterface>();
ASet aSet = new ASet(vertexHashSet);
Hashtable<VertexInterface, Integer> hashPi = new Hashtable<VertexInterface, Integer>() ;
Hashtable<VertexInterface, Integer> hashPi =
new Hashtable<VertexInterface, Integer>();
Pi pi = new Pi(hashPi);
Hashtable<VertexInterface, VertexInterface> hashPrevious = new Hashtable<VertexInterface, VertexInterface>() ;
Hashtable<VertexInterface, VertexInterface> hashPrevious =
new Hashtable<VertexInterface, VertexInterface>();
ArrayList<VertexInterface> shortestPath = new ArrayList<VertexInterface>();
Previous previous = new Previous(hashPrevious, shortestPath);
return dijkstra(g, r, aSet, pi, previous);
}
}
+11 -6
View File
@@ -2,14 +2,18 @@ package dijkstra;
import java.util.ArrayList;
/**
* This is the Graph class as described in the INF101 course of Telecom Paristech.
* Graph contains the representation of all the vertexes, with the information on which vertex(es) a vertex is linked to and at what cost.
* This is the Graph class as described in
* the INF101 course of Telecom Paristech.
* Graph contains the representation of all the vertexes,
* with the information on which vertex(es)
* a vertex is linked to and at what cost.
*/
public interface GraphInterface {
/**
* Gets the number of <code>VertexInterface</code> in the graph.
* @return An integer giving the number of <code>VertexInterface</code> in the graph.
* @return An integer giving the number of
* <code>VertexInterface</code> in the graph.
*/
public int getVertexNumber();
@@ -18,8 +22,10 @@ public interface GraphInterface {
* @param start
* The departure vertex.
* @param end
* The vertex from which we must see the cost of the link to <code>start</code>.
* @return An integer giving the cost of the link between the given <code>VertexInterface</code>.
* The vertex from which we must see the cost
* of the link to <code>start</code>.
* @return An integer giving the cost of the link between
* the given <code>VertexInterface</code>.
*/
public int getCost(VertexInterface start, VertexInterface end);
@@ -36,5 +42,4 @@ public interface GraphInterface {
* @return An <code>ArrayList</code> of <code>VertexInterface</code>.
*/
public ArrayList<VertexInterface> generateNeighbours(VertexInterface vertex);
}
+1 -8
View File
@@ -4,24 +4,17 @@ import java.util.Hashtable;
public class Pi implements PiInterface {
private Hashtable<VertexInterface, Integer> hashPi = new Hashtable<VertexInterface, Integer>() ;
private Hashtable<VertexInterface, Integer> hashPi;
public Pi(Hashtable<VertexInterface, Integer> hashPi) {
this.hashPi = new Hashtable<VertexInterface, Integer>(hashPi);
}
public int getPi(VertexInterface vertex) {
return hashPi.get(vertex);
}
public void setPi(int i, VertexInterface vertex) {
hashPi.put(vertex, i);
}
}
+8 -5
View File
@@ -2,15 +2,18 @@ package dijkstra;
/**
* This is the Pi class as described in the INF101 course of Telecom Paristech.
* It contains the path's cost to reach vertexes (typically, from the root of the graph).
* It contains the path's cost to reach vertexes
* (typically, from the root of the graph).
*/
public interface PiInterface {
/**
* Gets the cost to reach the given <code>VertexInterface</code>
* @param vertex
* The <code>VertexInterface</code> from which we get the Pi value (cost) to reach it.
* @return An <code>integer</code> giving the Pi value (cost) the reach the <code>VertexInterface</code>.
* The <code>VertexInterface</code> from which we get
* the Pi value (cost) to reach it.
* @return An <code>integer</code> giving the Pi value (cost)
* to reach the <code>VertexInterface</code>.
*
*/
public int getPi(VertexInterface vertex);
@@ -20,8 +23,8 @@ public interface PiInterface {
* @param i
* The Pi value (cost) to set.
* @param vertex
* The <code>VertexInterface</code> on which the Pi value (cost) is to be set.
* The <code>VertexInterface</code> on
* which the Pi value (cost) is to be set.
*/
public void setPi(int i, VertexInterface vertex);
}
+7 -7
View File
@@ -5,10 +5,11 @@ import java.util.Hashtable;
public class Previous implements PreviousInterface {
private Hashtable<VertexInterface, VertexInterface> hashPrevious = new Hashtable<VertexInterface, VertexInterface>() ;
private ArrayList<VertexInterface> shortestPath = new ArrayList<VertexInterface>() ;
private Hashtable<VertexInterface, VertexInterface> hashPrevious;
private ArrayList<VertexInterface> shortestPath;
public Previous(Hashtable<VertexInterface, VertexInterface> hashPrevious, ArrayList<VertexInterface> shortestPath) {
public Previous(Hashtable<VertexInterface, VertexInterface> hashPrevious,
ArrayList<VertexInterface> shortestPath) {
this.hashPrevious = new Hashtable<VertexInterface, VertexInterface>(hashPrevious);
this.shortestPath = new ArrayList<VertexInterface>(shortestPath);
@@ -17,13 +18,11 @@ public class Previous implements PreviousInterface {
public VertexInterface getPrevious(VertexInterface vertex) {
return hashPrevious.get(vertex);
}
public void setPrevious(VertexInterface father, VertexInterface son) {
hashPrevious.put(son, father);
}
public ArrayList<VertexInterface> getShortestPathTo(VertexInterface vertex) {
@@ -31,10 +30,11 @@ public class Previous implements PreviousInterface {
VertexInterface father = getPrevious(vertex);
shortestPath.add(father);
if (getPrevious(father) == null) return shortestPath ;
if (getPrevious(father) == null) {
return shortestPath;
}
else {
return getShortestPathTo(father);
}
}
}
+11 -6
View File
@@ -3,16 +3,21 @@ package dijkstra;
import java.util.ArrayList;
/**
* The <code>PreviousInterface</code> contains information about the father (as in the graph's theory) of some <code>VertexInterface</code>.
* The father of a <code>VertexInterface</code> is the <code>VertexInterface</code> used to reach it.
* Typically in Dijkstra, it's the <code>VertexInterface</code> used to reach <code>vertex</code> with the lowest cost.
* The <code>PreviousInterface</code> contains information
* about the father (as in the graph's theory)
* of some <code>VertexInterface</code>.
* The father of a <code>VertexInterface</code> is
* the <code>VertexInterface</code> used to reach it.
* Typically in Dijkstra, it's the <code>VertexInterface</code> used
* to reach <code>vertex</code> with the lowest cost.
*/
public interface PreviousInterface {
/**
* Returns the father of a <code>VertexInterface</code>.
* @param vertex
* The <code>VertexInterface</code> from which we get the father (previous <code>VertexInterface</code>).
* The <code>VertexInterface</code> from which we get
* the father (previous <code>VertexInterface</code>).
* @return The direct previous element used to reach <code>vertex</code>.
*/
public VertexInterface getPrevious(VertexInterface vertex);
@@ -30,8 +35,8 @@ public interface PreviousInterface {
* Shortest path from root to a vertex.
* @param vertex
* The vertex to which the shortest path will be computed.
* @return An <code>ArrayList</code> of the <code>VertexInterface</code> used to reach vertex with the lowest cost.
* @return An <code>ArrayList</code> of the <code>VertexInterface</code>
* used to reach vertex with the lowest cost.
*/
public ArrayList<VertexInterface> getShortestPathTo(VertexInterface vertex);
}
-1
View File
@@ -10,5 +10,4 @@ public interface VertexInterface {
* @return The label of the element.
*/
public String getLabel();
}
+3 -4
View File
@@ -1,19 +1,18 @@
package maze;
/**
* <code>ABox</code> is an arrival <code>Box</code>. It's the last <code>Box</code> to be walked through and it's an exit to the <code>Maze</code>.
* <code>ABox</code> is an arrival <code>Box</code>.
* It's the last <code>Box</code> to be walked through and
* it's an exit to the <code>Maze</code>.
*/
public class ABox extends EBox{
public ABox (String label, int x, int y, Maze maze) {
super(label, x, y, maze);
}
@Override
public boolean isArrival() {
return true;
}
}
+4 -14
View File
@@ -8,7 +8,8 @@ import dijkstra.VertexInterface;
*
* This class describes a Box and implements {@link dijkstra.VertexInterface}.
* <p>
* A Box is represented with its coordinates, its label, and its neighbourList. It also has a reference on the Maze.
* A Box is represented with its coordinates, its label, and its neighbourList.
* It also has a reference on the Maze.
*
* @author Antonin Godard
* @author Sylvain Rager
@@ -20,22 +21,15 @@ public abstract class Box
private int x;
private int y;
private String label = null ;
private String label;
private Maze maze;
private ArrayList<Box> neighbourList = new ArrayList<Box>() ;
public Box (String label, int x, int y, Maze maze) {
this.label = label ;
this.label = new String(label);
this.x = x;
this.y = y;
this.maze = maze;
}
public ArrayList<VertexInterface> generateNeighbors() {
return maze.generateNeighbours(this) ;
}
public boolean isWalkable() {
@@ -50,10 +44,6 @@ public abstract class Box
return false;
}
public ArrayList<Box> getNeighbourList() {
return neighbourList;
}
public int getX() {
return x;
}
+2 -4
View File
@@ -1,20 +1,18 @@
package maze;
/**
* A <code>DBox</code> is the <code>Box</code> on which the user is first in the <code>Maze</code>.
* A <code>DBox</code> is the <code>Box</code> on which the user
* is first in the <code>Maze</code>.
*/
public class DBox extends EBox{
public DBox (String label, int x, int y, Maze maze) {
super(label, x, y, maze);
}
@Override
public boolean isDeparture() {
return true;
}
}
+2 -5
View File
@@ -1,16 +1,13 @@
package maze;
/**
* An <code>EBox</code> is a <code>Box</code> that can be walked through (an empty box).
* An <code>EBox</code> is a <code>Box</code>
* that can be walked through (an empty box).
*/
public class EBox extends Box{
public EBox (String label, int x, int y, Maze maze) {
super(label, x, y, maze);
}
}
+23 -17
View File
@@ -24,9 +24,7 @@ public class Maze
private Box[][] maze;
public Maze(String filename) {
initFromTextFile(filename);
}
// public Maze(Box[][] maze){
@@ -40,7 +38,7 @@ public class Maze
Box startBox = (Box) start;
Box endBox = (Box) end;
return startBox.getNeighbourList().contains(endBox) ? 1 : 0 ;
return generateNeighbours(startBox).contains(endBox) ? 1 : 0;
}
public int getVertexNumber() {
@@ -88,10 +86,10 @@ public class Maze
}
return neighbourList;
}
/**Constructs the maze from a text file, according to each single character on each line.
/** Constructs the maze from a text file, according to each
* single character on each line.
* @param filename
* The path to the file containing the representation of the maze.
*/
@@ -128,25 +126,36 @@ public class Maze
{
currentLineLength = currentLine.length();
for (int compteurColonne = 0 ; compteurColonne < currentLineLength ; compteurColonne++) {
for (int compteurColonne = 0;
compteurColonne < currentLineLength;
compteurColonne++) {
char currentChar = currentLine.charAt(compteurColonne);
switch(currentChar) {
case 'W' : maze[compteurColonne][compteurLigne] = new WBox("W", compteurColonne, compteurLigne, this) ;
case 'W':
maze[compteurColonne][compteurLigne] =
new WBox("W", compteurColonne, compteurLigne, this);
break;
case 'E' : maze[compteurColonne][compteurLigne] = new EBox("E", compteurColonne, compteurLigne, this) ;
case 'E':
maze[compteurColonne][compteurLigne] =
new EBox("E", compteurColonne, compteurLigne, this);
break;
case 'D' : maze[compteurColonne][compteurLigne] = new DBox("D", compteurColonne, compteurLigne, this) ;
case 'D':
maze[compteurColonne][compteurLigne] =
new DBox("D", compteurColonne, compteurLigne, this);
break;
case 'A' : maze[compteurColonne][compteurLigne] = new ABox("A", compteurColonne, compteurLigne, this) ;
case 'A':
maze[compteurColonne][compteurLigne] =
new ABox("A", compteurColonne, compteurLigne, this);
break;
default : throw new MazeReadingException(filename) ;
default:
throw new MazeReadingException(filename);
}
}
@@ -178,11 +187,9 @@ public class Maze
fos = new FileOutputStream(fileName);
pw = new PrintWriter(fos);
for (int i = 0; i < dimensionX ; i++) {
for (int j = 0 ; j < dimensionY ; j++) {
pw.print(maze[i][j].getLabel());
for (int i = 0; i < dimensionY; i++) {
for (int j = 0; j < dimensionX; j++) {
pw.print(maze[j][i].getLabel());
}
pw.print("\n");
}
@@ -205,5 +212,4 @@ public class Maze
public Box[][] getMaze() {
return maze;
}
}
+2 -4
View File
@@ -2,7 +2,8 @@ package maze;
/**<h1> MazeReadingException exception </h1>
* <p>
* This class is used to throw exception when reading and initiating the maze from a text file.
* This class is used to throw exception when reading and
* initiating the maze from a text file.
*
*
*/
@@ -13,9 +14,6 @@ public class MazeReadingException
private static final long serialVersionUID = 1L;
public MazeReadingException (String filename) {
super("Invalid maze format : " + filename);
}
}
+2 -7
View File
@@ -1,23 +1,18 @@
package maze;
/**
* A <code>WBox</code> is a <code>Box</code> that can't be walked through (a wall).
* A <code>WBox</code> is a <code>Box</code>
* that can't be walked through (a wall).
*/
public class WBox extends Box {
public WBox (String label, int x, int y, Maze maze) {
super(label, x, y, maze);
}
@Override
public boolean isWalkable() {
return false;
}
}