Search in sources :

Example 16 with ObjectIdentityHashCodeVisitor

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

the class VisitorListTest method visitorListListIterator.

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

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

the class VisitorSetTest method visitorSetContainsAll.

@Test
public void visitorSetContainsAll() {
    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);
    assertTrue(set.size() == 2 && set.containsAll(list));
}
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 18 with ObjectIdentityHashCodeVisitor

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

the class VisitorSetTest method visitorSetRetainAll.

@Test
public void visitorSetRetainAll() {
    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);
    set.add(JavaParser.parse("class X{}"));
    set.retainAll(list);
    assertTrue(set.size() == 2);
}
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 19 with ObjectIdentityHashCodeVisitor

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

the class VisitorSetTest method visitorSetIterator.

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

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

the class VisitorSetTest method visitorSetRemoveAll.

@Test
public void visitorSetRemoveAll() {
    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);
    set.removeAll(list);
    assertTrue(set.size() == 0);
}
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)

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