Search in sources :

Example 11 with ObjectIdentityEqualsVisitor

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

the class VisitorListTest method visitorListRemoveAll.

@Test
public void visitorListRemoveAll() {
    List<CompilationUnit> list = new ArrayList<>();
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    VisitorList<CompilationUnit> vList = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    vList.addAll(list);
    vList.removeAll(list);
    assertTrue(vList.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)

Example 12 with ObjectIdentityEqualsVisitor

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

the class VisitorListTest method visitorAddAll.

@Test
public void visitorAddAll() {
    List<CompilationUnit> list = new ArrayList<>();
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    VisitorList<CompilationUnit> vList = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    vList.addAll(list);
    for (int i = 0; i < list.size(); i++) assertEquals(list.get(i), vList.get(i));
}
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 13 with ObjectIdentityEqualsVisitor

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

the class VisitorListTest method visitorAddAllAtIndex.

@Test
public void visitorAddAllAtIndex() {
    List<CompilationUnit> list = new ArrayList<>();
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class Y{}"));
    VisitorList<CompilationUnit> vList = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    vList.add(JavaParser.parse("class A{}"));
    vList.add(JavaParser.parse("class B{}"));
    vList.addAll(2, list);
    vList.add(JavaParser.parse("class C{}"));
    for (int i = 0; i < list.size(); i++) assertEquals(list.get(i), vList.get(2 + i));
}
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 14 with ObjectIdentityEqualsVisitor

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

the class VisitorListTest method visitorListToArray.

@Test
public void visitorListToArray() {
    List<CompilationUnit> list = new ArrayList<>();
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    List<CompilationUnit> vList = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    vList.addAll(list);
    for (CompilationUnit u : vList.toArray(new CompilationUnit[2])) assertTrue(vList.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 15 with ObjectIdentityEqualsVisitor

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

the class VisitorListTest method visitorListSubList.

@Test
public void visitorListSubList() {
    VisitorList<CompilationUnit> list = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    assertTrue(list.size() == 4);
    List<CompilationUnit> subLst = list.subList(1, 3);
    assertTrue(subLst.size() == 2);
    subLst.add(JavaParser.parse("class X{}"));
    assertTrue(subLst.size() == 3);
    assertTrue(list.size() == 5);
}
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