当前位置: 首页>>代码示例>>Java>>正文


Java IteratorUtils类代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtils类的具体用法?Java IteratorUtils怎么用?Java IteratorUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IteratorUtils类属于org.apache.tinkerpop.gremlin.util.iterator包,在下文中一共展示了IteratorUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldSerializeEdgeProperty

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test
public void shouldSerializeEdgeProperty() throws Exception {
    final Graph g = TinkerGraph.open();
    final Vertex v1 = g.addVertex();
    final Vertex v2 = g.addVertex();
    final Edge e = v1.addEdge("test", v2);
    e.property("abc", 123);

    final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
    final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());

    final JsonNode json = mapper.readTree(results);

    assertNotNull(json);
    assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
    final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);

    assertNotNull(converted);
    assertEquals(1, converted.size());

    final JsonNode propertyAsJson = converted.get(0);
    assertNotNull(propertyAsJson);

    assertEquals(123, propertyAsJson.get("value").asInt());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:GraphSONMessageSerializerV1d0Test.java

示例2: shouldSerializeToMapWithElementForKey

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test
public void shouldSerializeToMapWithElementForKey() throws Exception {
    final TinkerGraph graph = TinkerFactory.createClassic();
    final GraphTraversalSource g = graph.traversal();
    final Map<Vertex, Integer> map = new HashMap<>();
    map.put(g.V().has("name", "marko").next(), 1000);

    final ResponseMessage response = convertBinary(map);
    assertCommon(response);

    final Map<Vertex, Integer> deserializedMap = (Map<Vertex, Integer>) response.getResult().getData();
    assertEquals(1, deserializedMap.size());

    final Vertex deserializedMarko = deserializedMap.keySet().iterator().next();
    assertEquals(0, IteratorUtils.count(deserializedMarko.properties()));
    assertEquals(1, deserializedMarko.id());
    assertEquals("", deserializedMarko.label());

    assertEquals(new Integer(1000), deserializedMap.values().iterator().next());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:GryoLiteMessageSerializerV1d0Test.java

示例3: produceTraversalResult

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
private void produceTraversalResult(java.lang.Object result) {
  // The result of the graph traversal will be an iterator, thus, convert result to an iterator here.
  Iterator<?> resultIterator = IteratorUtils.asIterator(result);
  // Iterate result and convert values if necessary. This will perform the actual graph traversal.
  resultIterator.forEachRemaining(value -> {
    if (value instanceof ObjectVertex) {
      // Fetch ObjectEntity and convert to Object model before adding to result.
      ObjectEntity object = ObjectVertex.class.cast(value).getObject();
      traversalResult.add(requestContext.getObjectConverter().apply(object));
    } else if (value instanceof FactEdge) {
      // Fetch FactEntity and convert to Fact model before adding to result.
      FactEntity fact = FactEdge.class.cast(value).getFact();
      traversalResult.add(requestContext.getFactConverter().apply(fact));
    } else {
      // Don't know what this is, just add its string representation to result.
      // For example, it could be a query returning a list of properties.
      // This mimics the behaviour of gremlin-console and avoids returning arbitrary JSON objects.
      traversalResult.add(value.toString());
    }
  });
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:22,代码来源:TraverseGraphDelegate.java

示例4: createElementIterator

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
private <T extends Element> Iterator<T> createElementIterator(final Class<T> clazz, final Map<Object, T> elements,
                                                              final IdManager idManager,
                                                              final Object... ids) {
    final Iterator<T> iterator;
    if (0 == ids.length) {
        iterator = elements.values().iterator();
    } else {
        final List<Object> idList = Arrays.asList(ids);
        validateHomogenousIds(idList);

        // if the type is of Element - have to look each up because it might be an Attachable instance or
        // other implementation. the assumption is that id conversion is not required for detached
        // stuff - doesn't seem likely someone would detach a Titan vertex then try to expect that
        // vertex to be findable in OrientDB
        return clazz.isAssignableFrom(ids[0].getClass()) ?
                IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(clazz.cast(id).id())).iterator(), Objects::nonNull)
                : IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(idManager.convert(id))).iterator(), Objects::nonNull);
    }
    return TinkerHelper.inComputerMode(this) ?
            (Iterator<T>) (clazz.equals(Vertex.class) ?
                    IteratorUtils.filter((Iterator<Vertex>) iterator, t -> this.graphComputerView.legalVertex(t)) :
                    IteratorUtils.filter((Iterator<Edge>) iterator, t -> this.graphComputerView.legalEdge(t.outVertex(), t))) :
            iterator;
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:25,代码来源:TinkerGraph.java

示例5: specificEdges

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Override
protected Iterator<Edge> specificEdges(Direction direction, String... edgeLabels) {
    List<Iterator<?>> iterators = new LinkedList<>();
    if (edgeLabels.length == 0) {
        edgeLabels = ALL_EDGES;
    }
    for (String label : edgeLabels) {
        if (label == WrittenBy.label) {
            if (direction == Direction.IN || direction == Direction.BOTH) {
                iterators.add(getWrittenByIn().iterator());
            }
        } else if (label == SungBy.label) {
            if (direction == Direction.IN || direction == Direction.BOTH) {
                iterators.add(getSungByIn().iterator());
            }
        }
    }

    Iterator<Edge>[] iteratorsArray = iterators.toArray(new Iterator[iterators.size()]);
    return IteratorUtils.concat(iteratorsArray);
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:22,代码来源:Artist.java

示例6: testSaveScopes

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT,
        invocationCount = CONCURRENT_TEST_INVOCATIONS)
public void testSaveScopes() {
    SubjectEntity subject = persistScopedHierarchy(AGENT_MULDER + getRandomNumber(), SITE_BASEMENT);
    assertThat(IteratorUtils.count(this.graphTraversalSource.V(subject.getId()).outE(PARENT_EDGE_LABEL)),
            equalTo(2L));

    // Persist again (i.e. update) and make sure vertex and edge count are stable.
    this.subjectRepository.save(subject);
    assertThat(IteratorUtils.count(this.graphTraversalSource.V(subject.getId()).outE(PARENT_EDGE_LABEL)),
            equalTo(2L));

    Parent parent = null;
    for (Parent tempParent : this.subjectRepository.findOne(subject.getId()).getParents()) {
        if (tempParent.getIdentifier().contains(TOP_SECRET_GROUP)) {
            parent = tempParent;
        }
    }
    assertThat(parent, notNullValue());
    assertThat("Expected scope not found on subject.", parent.getScopes().contains(SITE_BASEMENT));
    GraphResourceRepositoryTest.deleteTwoLevelEntityAndParents(subject, TEST_ZONE_1, this.subjectRepository);
}
 
开发者ID:eclipse,项目名称:keti,代码行数:23,代码来源:GraphSubjectRepositoryTest.java

示例7: shouldTriggerAddVertexWithPropertyThenPropertyAdded

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldTriggerAddVertexWithPropertyThenPropertyAdded() {
    final StubMutationListener listener1 = new StubMutationListener();
    final StubMutationListener listener2 = new StubMutationListener();
    final EventStrategy.Builder builder = EventStrategy.build()
            .addListener(listener1)
            .addListener(listener2);

    if (graph.features().graph().supportsTransactions())
        builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));

    final EventStrategy eventStrategy = builder.create();

    final Vertex vSome = graph.addVertex("some", "thing");
    vSome.property(VertexProperty.Cardinality.single, "that", "thing");
    final GraphTraversalSource gts = create(eventStrategy);
    gts.V().addV().property("any", "thing").property(VertexProperty.Cardinality.single, "this", "thing").next();

    tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("this", "thing"))));

    assertEquals(1, listener1.addVertexEventRecorded());
    assertEquals(1, listener2.addVertexEventRecorded());
    assertEquals(1, listener2.vertexPropertyChangedEventRecorded());
    assertEquals(1, listener1.vertexPropertyChangedEventRecorded());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:27,代码来源:EventStrategyProcessTest.java

示例8: shouldTriggerAddVertexFromStart

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldTriggerAddVertexFromStart() {
    final StubMutationListener listener1 = new StubMutationListener();
    final StubMutationListener listener2 = new StubMutationListener();
    final EventStrategy.Builder builder = EventStrategy.build()
            .addListener(listener1)
            .addListener(listener2);

    if (graph.features().graph().supportsTransactions())
        builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));

    final EventStrategy eventStrategy = builder.create();

    graph.addVertex("some", "thing");
    final GraphTraversalSource gts = create(eventStrategy);
    gts.addV().property("any", "thing").next();

    tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("any", "thing"))));
    assertEquals(1, listener1.addVertexEventRecorded());
    assertEquals(1, listener2.addVertexEventRecorded());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:EventStrategyProcessTest.java

示例9: computerAlgorithm

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Override
protected Iterator<Traverser.Admin<S>> computerAlgorithm() throws NoSuchElementException {
    final Traverser.Admin<S> start = this.starts.next();
    if (doUntil(start, true)) {
        start.resetLoops();
        start.setStepId(this.getNextStep().getId());
        start.addLabels(this.labels);
        return IteratorUtils.of(start);
    } else {
        start.setStepId(this.repeatTraversal.getStartStep().getId());
        if (doEmit(start, true)) {
            final Traverser.Admin<S> emitSplit = start.split();
            emitSplit.resetLoops();
            emitSplit.setStepId(this.getNextStep().getId());
            return IteratorUtils.of(start, emitSplit);
        } else {
            return IteratorUtils.of(start);
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:RepeatStep.java

示例10: HasContainer

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
public HasContainer(final String key, final P<?> predicate) {
    this.key = key;
    this.predicate = predicate;

    if (!this.key.equals(T.id.getAccessor()))
        testingIdString = false;
    else {
        // the values should be homogenous if a collection is submitted
        final Object predicateValue = this.predicate.getValue();

        // enforce a homogenous collection of values when testing ids
        enforceHomogenousCollectionIfPresent(predicateValue);

        // grab an instance of a value which is either the first item in a homogeneous collection or the value itself
        final Object valueInstance = this.predicate.getValue() instanceof Collection ?
                ((Collection) this.predicate.getValue()).toArray()[0] : this.predicate.getValue();

        // if the key being evaluated is id then the has() test can evaluate as a toString() representation of the
        // identifier.  this could be done in the test() method but it seems cheaper to do the conversion once in
        // the constructor.  the original value in P is maintained separately
        this.testingIdString = this.key.equals(T.id.getAccessor()) && valueInstance instanceof String;
        if (this.testingIdString)
            this.predicate.setValue(this.predicate.getValue() instanceof Collection ? IteratorUtils.set(IteratorUtils.map(((Collection<Object>) this.predicate.getValue()).iterator(), Object::toString)) : this.predicate.getValue().toString());
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:HasContainer.java

示例11: lookupEdges

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
private Iterator<Edge> lookupEdges(final Traverser.Admin<Vertex> traverser, final List<HasContainer> hasContainers) {
    final HBaseGraph graph = (HBaseGraph) this.getTraversal().getGraph().get();
    if (getEdgeLabels().length == 1) {
        final String label = getEdgeLabels()[0];
        // find an edge by label and key/value
        for (final HasContainer hasContainer : hasContainers) {
            if (Compare.eq == hasContainer.getBiPredicate() && !hasContainer.getKey().equals(T.label.getAccessor())) {
                if (graph.hasIndex(OperationType.READ, ElementType.EDGE, label, hasContainer.getKey())) {
                    return IteratorUtils.stream(((HBaseVertex) traverser.get()).edges(getDirection(), label, hasContainer.getKey(), hasContainer.getValue()))
                            .filter(vertex -> HasContainer.testAll(vertex, hasContainers)).iterator();
                }
            }
        }
    }

    // linear scan
    return CloseableIteratorUtils.filter(traverser.get().edges(getDirection(), getEdgeLabels()),
            edge -> HasContainer.testAll(edge, hasContainers));
}
 
开发者ID:rayokota,项目名称:hgraphdb,代码行数:20,代码来源:HBaseVertexStep.java

示例12: shouldUseOneTimeBulkLoader

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test
@LoadGraphWith(MODERN)
public void shouldUseOneTimeBulkLoader() throws Exception {
    for (int iteration = 1; iteration <= 2; iteration++) {
        final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build()
                .bulkLoader(OneTimeBulkLoader.class)
                .writeGraph(getWriteGraphConfiguration()).create(graph);
        final BulkLoader loader = getBulkLoader(blvp);
        assertTrue(loader instanceof OneTimeBulkLoader);
        graphProvider.getGraphComputer(graph).workers(1).program(blvp).submit().get();
        final Graph result = getWriteGraph();
        assertEquals(6 * iteration, IteratorUtils.count(result.vertices()));
        assertEquals(6 * iteration, IteratorUtils.count(result.edges()));
        result.close();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:BulkLoaderVertexProgramTest.java

示例13: shouldHashAndEqualsCorrectly

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldHashAndEqualsCorrectly() {
    final Vertex gremlin = g.V(convertToVertexId("gremlin")).next();
    final StarGraph gremlinStarGraph = StarGraph.of(gremlin);
    final StarGraph.StarVertex gremlinStar = gremlinStarGraph.getStarVertex();

    final Vertex marko = g.V(convertToVertexId("marko")).next();
    final StarGraph markoStarGraph = StarGraph.of(marko);
    final StarGraph.StarAdjacentVertex gremlinStarAdjacentGraph = (StarGraph.StarAdjacentVertex) IteratorUtils.filter(markoStarGraph.getStarVertex().edges(Direction.OUT, "uses"), x -> x.inVertex().id().equals(convertToVertexId("gremlin"))).next().inVertex();

    final Set<Vertex> set = new HashSet<>();
    for (int i = 0; i < 100; i++) {
        set.add(gremlin);
        set.add(gremlinStar);
        set.add(gremlinStarAdjacentGraph);
    }
    assertEquals(1, set.size());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:20,代码来源:StarGraphTest.java

示例14: map

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Override
protected S map(final Traverser.Admin<S> traverser) {
    // We may consider optimizing the iteration of these containers using subtype-specific interfaces.  For
    // example, we could use descendingIterator if we have a Deque.  But in general, we cannot reliably iterate a
    // collection in reverse, so we use the range algorithm with dynamically computed boundaries.
    final S start = traverser.get();
    final long high =
            start instanceof Map ? ((Map) start).size() :
                    start instanceof Collection ? ((Collection) start).size() :
                            start instanceof Path ? ((Path) start).size() :
                                    start instanceof Iterable ? IteratorUtils.count((Iterable) start) :
                                            this.limit;
    final long low = high - this.limit;
    final S result = RangeLocalStep.applyRange(start, low, high);
    return result;
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:TailLocalStep.java

示例15: shouldConstructDetachedEdgeFromParts

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入依赖的package包/类
@Test
public void shouldConstructDetachedEdgeFromParts() {
    final Map<String, Object> properties = new HashMap<>();
    properties.put("x", "a");
    properties.put("y", "b");

    final DetachedEdge de = new DetachedEdge(10, "bought", properties, Pair.with(1, "person"), Pair.with(2, "product"));

    assertEquals(10, de.id());
    assertEquals("bought", de.label());
    assertEquals("person", de.vertices(Direction.OUT).next().label());
    assertEquals(1, de.vertices(Direction.OUT).next().id());
    assertEquals("product", de.vertices(Direction.IN).next().label());
    assertEquals(2, de.vertices(Direction.IN).next().id());

    assertEquals("a", de.properties("x").next().value());
    assertEquals(1, IteratorUtils.count(de.properties("x")));

    assertEquals("a", de.property("x").value());
    assertEquals("x", de.property("x").key());

    assertEquals("b", de.property("y").value());
    assertEquals("y", de.property("y").key());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:25,代码来源:DetachedEdgeTest.java


注:本文中的org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。