Skip to content

Commit

Permalink
Removed innerMap from the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lebouc Romain committed Aug 25, 2017
1 parent afa8c65 commit e3e3123
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Expand Up @@ -17,15 +17,15 @@
*/
public class VisitorMap<N extends Node, V> implements Map<N, V> {
// Cheat generics by removing them
private final Map innerMap;
private final Map<EqualsHashcodeOverridingFacade, V> innerMap;
private final GenericVisitor<Integer, Void> hashcodeVisitor;
private final GenericVisitor<Boolean, Visitable> equalsVisitor;

/**
* Wrap a map and use different visitors for equals and hashcode.
*/
public VisitorMap(Map<N, V> innerMap, GenericVisitor<Integer, Void> hashcodeVisitor, GenericVisitor<Boolean, Visitable> equalsVisitor) {
this.innerMap = innerMap;
public VisitorMap(GenericVisitor<Integer, Void> hashcodeVisitor, GenericVisitor<Boolean, Visitable> equalsVisitor) {
this.innerMap = new HashMap<>();
this.hashcodeVisitor = hashcodeVisitor;
this.equalsVisitor = equalsVisitor;
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ public void objectIdentityEqualsDoesShallowCompare() {
CompilationUnit x1 = JavaParser.parse("class X{}");
CompilationUnit x2 = JavaParser.parse("class X{}");

Map<CompilationUnit, Integer> normalMap = new VisitorMap<>(new HashMap<>(), new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
Map<CompilationUnit, Integer> normalMap = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
normalMap.put(x1, 1);
normalMap.put(x2, 2);
assertEquals(2, normalMap.size());
Expand All @@ -39,7 +39,7 @@ public void objectIdentityEqualsDoesShallowCompare() {
public void visitorMapGet(){
CompilationUnit x1 = JavaParser.parse("class X{}");

Map<CompilationUnit, Integer> normalMap = new VisitorMap<>(new HashMap<>(), new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
Map<CompilationUnit, Integer> normalMap = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
normalMap.put(x1, 1);
assertEquals(1, (int)normalMap.get(x1));
}
Expand All @@ -48,7 +48,7 @@ public void visitorMapGet(){
public void visitorMapContainsKey(){
CompilationUnit x1 = JavaParser.parse("class X{}");

Map<CompilationUnit, Integer> normalMap = new VisitorMap<>(new HashMap<>(), new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
Map<CompilationUnit, Integer> normalMap = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
normalMap.put(x1, 1);
assertTrue(normalMap.containsKey(x1));
}
Expand All @@ -60,7 +60,7 @@ public void visitorMapPutAll(){
Map<CompilationUnit, Integer> normalMap = new HashMap<>();
normalMap.put(x1, 1);
normalMap.put(x2, 2);
Map<CompilationUnit, Integer> visitorMap = new VisitorMap<>(new HashMap<>(), new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
Map<CompilationUnit, Integer> visitorMap = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
visitorMap.putAll(normalMap);
assertEquals(2, visitorMap.size());
}
Expand Down

0 comments on commit e3e3123

Please sign in to comment.