Search in sources :

Example 21 with ObjectIdentityHashCodeVisitor

use of com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor in project javaparser by javaparser.

the class VisitorSetTest method visitorSetToArray.

@Test
public void visitorSetToArray() {
    List<CompilationUnit> list = new ArrayList<>();
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    Set<CompilationUnit> set = new VisitorSet<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    set.addAll(list);
    for (CompilationUnit u : set.toArray(new CompilationUnit[2])) assertTrue(set.contains(u));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ArrayList(java.util.ArrayList) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Example 22 with ObjectIdentityHashCodeVisitor

use of com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor in project javaparser by javaparser.

the class VisitorSetTest method objectIdentityEqualsDoesShallowCompare.

@Test
public void objectIdentityEqualsDoesShallowCompare() {
    Set<CompilationUnit> set = new VisitorSet<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    set.add(JavaParser.parse("class X{}"));
    set.add(JavaParser.parse("class X{}"));
    assertEquals(2, set.size());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Example 23 with ObjectIdentityHashCodeVisitor

use of com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor in project javaparser by javaparser.

the class VisitorMapTest method objectIdentityEqualsDoesShallowCompare.

@Test
public void objectIdentityEqualsDoesShallowCompare() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    CompilationUnit x2 = JavaParser.parse("class X{}");
    Map<CompilationUnit, Integer> map = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    map.put(x1, 1);
    map.put(x2, 2);
    assertEquals(2, map.size());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Example 24 with ObjectIdentityHashCodeVisitor

use of com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor in project javaparser by javaparser.

the class VisitorMapTest method remove.

@Test
public void remove() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    VisitorMap<CompilationUnit, Integer> map = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    map.put(x1, 1);
    assertTrue(map.containsKey(x1));
    map.remove(x1);
    assertFalse(map.containsKey(x1));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)24 ObjectIdentityEqualsVisitor (com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor)24 ObjectIdentityHashCodeVisitor (com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor)24 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)1