From [Box.java#L14](https://git.regar42.fr/antograb/TpMazeJava/src/branch/fixUnneededCode/src/maze/Box.java#L14), I don't get why you create a List from an ArrayList :
private List<Box> neighbourList = new ArrayList<Box>() ;
Fixed in fda73a20.
Here I create an ArrayList from the List class. ArrayList inherits from List, and this is indeed useless since I could just write :
private ArrayList neighbourList = new ArrayList() ;
This would also prevent from importing both List and ArrayList packages, since we only need ArrayList.
Here I create an ArrayList from the List class. ArrayList inherits from List, and this is indeed useless since I could just write :
private ArrayList<Box> neighbourList = new ArrayList<Box>() ;
This would also prevent from importing both List and ArrayList packages, since we only need ArrayList.
you take the object hashPi passed as an argument and put its reference in this.hashPi. It doesn't create a new object. This could be problematic if hashPi, for some reasons, is changed and we don't want to affect hashPi in the Pi instance.
I don't use the clone() method because it only does a shallow copy of the object : it creates a new object and for each of its arguments, sets the reference of the corresponding argument from the original object. Moreover, the implementation of clone() changes depending of the class, making it sometimes do a shallow copy, sometimes a deep copy. For such reasons, clone() is considered as a bad practice in Java programming.
since in this we case we really want to keep a reference on the passed object (and not to create a new independant maze).
Replaced https://git.regar42.fr/antograb/TpMazeJava/src/commit/5f44829371d94c84e03ddce09fb077f059e8f608/src/dijkstra/Pi.java#L11 :
public Pi(Hashtable<VertexInterface, Integer> hashPi) {
this.hashPi = hashPi ;
}
by https://git.regar42.fr/antograb/TpMazeJava/src/commit/ebb91b01b388f6c07f29f2d5fcb3a48402011faf/src/dijkstra/Pi.java#L11 :
public Pi(Hashtable<VertexInterface, Integer> hashPi) {
this.hashPi = new Hashtable<VertexInterface, Integer>(hashPi);
}
In https://git.regar42.fr/antograb/TpMazeJava/src/commit/5f44829371d94c84e03ddce09fb077f059e8f608/src/dijkstra/Pi.java#L11 you take the object `hashPi` passed as an argument and put its reference in `this.hashPi`. It doesn't create a new object. This could be problematic if `hashPi`, for some reasons, is changed and we don't want to affect `hashPi` in the `Pi` instance.
I don't use the `clone()` method because it only does a shallow copy of the object : it creates a new object and for each of its arguments, sets the reference of the corresponding argument from the original object. Moreover, the implementation of `clone()` changes depending of the class, making it sometimes do a shallow copy, sometimes a deep copy. For such reasons, `clone()` is considered as a bad practice in Java programming.
This change, however, doesn't affect https://git.regar42.fr/antograb/TpMazeJava/src/commit/5f44829371d94c84e03ddce09fb077f059e8f608/src/maze/Box.java#L21 since in this we case we really want to keep a reference on the passed object (and not to create a new independant maze).
regar42
changed title from WIP: Useless code removal and code cleanup to [WIP] Useless code removal and code cleanup2017-12-10 11:34:37 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
From Box.java#L14, I don't get why you create a List from an ArrayList :
private List neighbourList = new ArrayList() ;
Fixed in
fda73a20.Here I create an ArrayList from the List class. ArrayList inherits from List, and this is indeed useless since I could just write :
private ArrayList neighbourList = new ArrayList() ;
This would also prevent from importing both List and ArrayList packages, since we only need ArrayList.
Replaced
public Pi(Hashtable<VertexInterface, Integer> hashPi) {
this.hashPi = hashPi ;
}
by
public Pi(Hashtable<VertexInterface, Integer> hashPi) {
this.hashPi = new Hashtable<VertexInterface, Integer>(hashPi);
}
In
hashPipassed as an argument and put its reference inthis.hashPi. It doesn't create a new object. This could be problematic ifhashPi, for some reasons, is changed and we don't want to affecthashPiin thePiinstance.I don't use the
clone()method because it only does a shallow copy of the object : it creates a new object and for each of its arguments, sets the reference of the corresponding argument from the original object. Moreover, the implementation ofclone()changes depending of the class, making it sometimes do a shallow copy, sometimes a deep copy. For such reasons,clone()is considered as a bad practice in Java programming.This change, however, doesn't affect
WIP: Useless code removal and code cleanupto [WIP] Useless code removal and code cleanup