Java Code Examples for org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils#asList()

The following examples show how to use org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils#asList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertexProgramStrategy.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public static VertexProgramStrategy create(final Configuration configuration) {
    try {
        final VertexProgramStrategy.Builder builder = VertexProgramStrategy.build();
        for (final String key : (List<String>) IteratorUtils.asList(configuration.getKeys())) {
            if (key.equals(GRAPH_COMPUTER))
                builder.graphComputer((Class) Class.forName(configuration.getString(key)));
            else if (key.equals(WORKERS))
                builder.workers(configuration.getInt(key));
            else if (key.equals(PERSIST))
                builder.persist(GraphComputer.Persist.valueOf(configuration.getString(key)));
            else if (key.equals(RESULT))
                builder.result(GraphComputer.ResultGraph.valueOf(configuration.getString(key)));
            else if (key.equals(VERTICES))
                builder.vertices((Traversal) configuration.getProperty(key));
            else if (key.equals(EDGES))
                builder.edges((Traversal) configuration.getProperty(key));
            else
                builder.configure(key, configuration.getProperty(key));
        }
        return builder.create();
    } catch (final ClassNotFoundException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 2
Source File: IndexedTraverserSetTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMaintainIndexOfTraversersAfterSort() {
    final IndexedTraverserSet<String, String> ts = makeOtherTraverserSet();

    final List<Traverser.Admin<String>> testTraversers = new ArrayList<>(ts.get("test"));
    assertEquals(1, testTraversers.size());
    assertEquals(4, testTraversers.get(0).bulk());

    final List<Traverser.Admin<String>> nopeTraversers = new ArrayList<>(ts.get("nope"));
    assertEquals(1, nopeTraversers.size());
    assertEquals(1, nopeTraversers.get(0).bulk());

    final List<Traverser<String>> traversersBefore = IteratorUtils.asList(ts.iterator());

    ts.sort(Comparator.comparing(Traverser::get));

    final List<Traverser<String>> traversersAfter = IteratorUtils.asList(ts.iterator());

    final List<Traverser.Admin<String>> testTraversersAfterSort = new ArrayList<>(ts.get("test"));
    assertEquals(1, testTraversersAfterSort.size());
    assertEquals(4, testTraversersAfterSort.get(0).bulk());

    final List<Traverser.Admin<String>> nopeTraversersAfterSort = new ArrayList<>(ts.get("nope"));
    assertEquals(1, nopeTraversersAfterSort.size());
    assertEquals(1, nopeTraversersAfterSort.get(0).bulk());

    assertNotEquals(traversersBefore, traversersAfter);
}
 
Example 3
Source File: AddVertexTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
public void g_V_addVXanimalX_propertyXname_valuesXnameXX_propertyXname_an_animalX_propertyXvaluesXnameX_labelX() {
    final Traversal<Vertex, Vertex> traversal = get_g_V_addVXanimalX_propertyXname_valuesXnameXX_propertyXname_an_animalX_propertyXvaluesXnameX_labelX();
    printTraversalForm(traversal);
    while (traversal.hasNext()) {
        final Vertex vertex = traversal.next();
        assertEquals("animal", vertex.label());
        assertEquals(2, IteratorUtils.count(vertex.properties("name")));
        List<String> names = IteratorUtils.asList(vertex.values("name"));
        assertEquals(2, names.size());
        assertTrue(names.contains("an animal"));
        assertTrue(names.contains("marko") || names.contains("vadas") || names.contains("josh") || names.contains("lop") || names.contains("ripple") || names.contains("peter"));
        if (names.contains("marko")) {
            assertEquals("person", vertex.value("marko"));
        } else if (names.contains("vadas")) {
            assertEquals("person", vertex.value("vadas"));
        } else if (names.contains("josh")) {
            assertEquals("person", vertex.value("josh"));
        } else if (names.contains("ripple")) {
            assertEquals("software", vertex.value("ripple"));
        } else if (names.contains("lop")) {
            assertEquals("software", vertex.value("lop"));
        } else if (names.contains("peter")) {
            assertEquals("person", vertex.value("peter"));
        } else {
            throw new IllegalStateException("This state should not have been reached");
        }
    }
}
 
Example 4
Source File: TestTopology.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testRollback() {
    loadModern();
    final Traversal<Vertex, Edge> traversal = this.sqlgGraph.traversal().V().aggregate("x").as("a").select("x").unfold().addE("existsWith").to("a").property("time", "now");
    IteratorUtils.asList(traversal);
    this.sqlgGraph.tx().rollback();
}
 
Example 5
Source File: ShortestPathVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
private List<VertexMessage> messages(Messenger<VertexMessage> messenger) {
    return IteratorUtils.asList(messenger.receiveMessages());
}
 
Example 6
Source File: ShortestPathVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
private List<MessageFromSource> messageFromSource(List<VertexMessage> messages) {
    return IteratorUtils.asList(Iterators.filter(messages.iterator(), e -> e instanceof MessageFromSource));
}
 
Example 7
Source File: ShortestPathVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
private List<MessageFromDestination> messageFromDestination(List<VertexMessage> messages) {
    return IteratorUtils.asList(Iterators.filter(messages.iterator(), e -> e instanceof MessageFromDestination));
}