Search in sources :

Example 1 with ObjectIdentityEqualsVisitor

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

the class VisitorMapTest method visitorMapContainsKey.

@Test
public void visitorMapContainsKey() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    Map<CompilationUnit, Integer> map = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    map.put(x1, 1);
    assertTrue(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)

Example 2 with ObjectIdentityEqualsVisitor

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

the class VisitorMapTest method visitorMapPutAll.

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

Example 3 with ObjectIdentityEqualsVisitor

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

the class VisitorMapTest method visitorMapGet.

@Test
public void visitorMapGet() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    Map<CompilationUnit, Integer> map = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    map.put(x1, 1);
    assertEquals(1, (int) map.get(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)

Example 4 with ObjectIdentityEqualsVisitor

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

the class VisitorListTest method visitorListIterator.

@Test
public void visitorListIterator() {
    VisitorList<CompilationUnit> list = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    CompilationUnit x1 = JavaParser.parse("class X{}");
    list.add(x1);
    CompilationUnit x2 = JavaParser.parse("class X{}");
    list.add(x2);
    Iterator<CompilationUnit> itr = list.iterator();
    assertEquals(x1, itr.next());
    itr.remove();
    assertTrue(list.size() == 1);
    assertEquals(x2, itr.next());
    itr.remove();
    assertTrue(list.size() == 0);
}
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 5 with ObjectIdentityEqualsVisitor

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

the class VisitorListTest method visitorListRemove.

@Test
public void visitorListRemove() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    VisitorList<CompilationUnit> list = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    list.add(x1);
    assertTrue(list.remove(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