From ebb91b01b388f6c07f29f2d5fcb3a48402011faf Mon Sep 17 00:00:00 2001 From: "Sylvain Rager (regar42)" Date: Sat, 9 Dec 2017 23:48:50 +0100 Subject: [PATCH] Code cleanup * Remove unwanted getters and setters * Properly handle object passed to constructors * Remove redundant condition check on ASet.contains()'s return * Make Maze.initFromTextFile() private --- src/dijkstra/ASet.java | 7 +++---- src/dijkstra/Pi.java | 2 +- src/dijkstra/Previous.java | 4 ++-- src/maze/Maze.java | 21 +++++++-------------- src/maze/MazeReadingException.java | 4 ---- 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/dijkstra/ASet.java b/src/dijkstra/ASet.java index 5dc12b5..76c569b 100644 --- a/src/dijkstra/ASet.java +++ b/src/dijkstra/ASet.java @@ -11,20 +11,19 @@ public class ASet implements ASetInterface { public ASet(HashSet vertexHashSet) { - this.vertexHashSet = vertexHashSet; + this.vertexHashSet = new HashSet(vertexHashSet); } public void add(VertexInterface vertex) { - vertexHashSet.add((Box)vertex) ; + vertexHashSet.add(vertex) ; } public boolean contains(VertexInterface vertex) { - if (vertexHashSet.contains(vertex)) return true ; - return false ; + return vertexHashSet.contains(vertex); } diff --git a/src/dijkstra/Pi.java b/src/dijkstra/Pi.java index 6cd3c7d..2b21078 100644 --- a/src/dijkstra/Pi.java +++ b/src/dijkstra/Pi.java @@ -8,7 +8,7 @@ public class Pi implements PiInterface { public Pi(Hashtable hashPi) { - this.hashPi = hashPi ; + this.hashPi = new Hashtable(hashPi); } diff --git a/src/dijkstra/Previous.java b/src/dijkstra/Previous.java index b6acaeb..bde8d5f 100644 --- a/src/dijkstra/Previous.java +++ b/src/dijkstra/Previous.java @@ -15,8 +15,8 @@ public class Previous implements PreviousInterface { public Previous(Hashtable hashPrevious, ArrayList shortestPath) { - this.hashPrevious = hashPrevious; - this.shortestPath = shortestPath; + this.hashPrevious = new Hashtable(hashPrevious); + this.shortestPath = new ArrayList(shortestPath); } public VertexInterface getPrevious(VertexInterface vertex) { diff --git a/src/maze/Maze.java b/src/maze/Maze.java index 34d5cf0..652a87b 100644 --- a/src/maze/Maze.java +++ b/src/maze/Maze.java @@ -21,6 +21,12 @@ public class Maze } + // public Maze(Box[][] maze){ + // //Replacement for setMaze() + // //Todo : check if the given array is a proper maze + // //and then set dimensionX and dimensionX + // } + public int getCost(VertexInterface start, VertexInterface end) { Box startBox = (Box) start ; @@ -77,7 +83,7 @@ public class Maze } - public final void initFromTextFile(String filename) { + private final void initFromTextFile(String filename) { FileReader fr = null ; BufferedReader br = null ; @@ -182,25 +188,12 @@ public class Maze return dimensionX; } - public void setDimensionX(int dimensionX) { - this.dimensionX = dimensionX; - } - public int getDimensionY() { return dimensionY; } - public void setDimensionY(int dimensionY) { - this.dimensionY = dimensionY; - } - public Box[][] getMaze() { return maze; } - public void setMaze(Box[][] maze) { - this.maze = maze; - } - - } diff --git a/src/maze/MazeReadingException.java b/src/maze/MazeReadingException.java index 0bfd24c..432f077 100644 --- a/src/maze/MazeReadingException.java +++ b/src/maze/MazeReadingException.java @@ -12,8 +12,4 @@ public class MazeReadingException } - public String getFilename() { - return filename ; - } - }