Search in sources :

Example 1 with VertexArrayList

use of com.thinkaurelius.titan.graphdb.query.vertex.VertexArrayList in project titan by thinkaurelius.

the class VertexListTest method testLists.

@Test
public void testLists() {
    int num = 13;
    TitanGraph g = TitanFactory.open("inmemory");
    StandardTitanTx tx = (StandardTitanTx) g.newTransaction();
    VertexLongList vll = new VertexLongList(tx);
    VertexArrayList val = new VertexArrayList(tx);
    for (int i = 0; i < num; i++) {
        TitanVertex v = tx.addVertex();
        vll.add(v);
        val.add(v);
    }
    assertEquals(num, Iterables.size(vll));
    assertEquals(num, Iterables.size(val));
    vll.sort();
    val.sort();
    assertTrue(vll.isSorted());
    assertTrue(val.isSorted());
    for (Iterable<TitanVertex> iterable : new Iterable[] { val, vll }) {
        Iterator<TitanVertex> iter = iterable.iterator();
        TitanVertex previous = null;
        for (int i = 0; i < num; i++) {
            TitanVertex next = iter.next();
            if (previous != null)
                assertTrue(previous.longId() < next.longId());
            previous = next;
        }
        try {
            iter.next();
            fail();
        } catch (NoSuchElementException ex) {
        }
    }
    tx.commit();
    g.close();
}
Also used : TitanGraph(com.thinkaurelius.titan.core.TitanGraph) VertexLongList(com.thinkaurelius.titan.graphdb.query.vertex.VertexLongList) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) VertexArrayList(com.thinkaurelius.titan.graphdb.query.vertex.VertexArrayList) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Aggregations

TitanGraph (com.thinkaurelius.titan.core.TitanGraph)1 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 VertexArrayList (com.thinkaurelius.titan.graphdb.query.vertex.VertexArrayList)1 VertexLongList (com.thinkaurelius.titan.graphdb.query.vertex.VertexLongList)1 StandardTitanTx (com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)1 NoSuchElementException (java.util.NoSuchElementException)1 Test (org.junit.Test)1