org.apache.tinkerpop.gremlin.structure.Vertex.edges()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(16.8k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.apache.tinkerpop.gremlin.structure.Vertex.edges()方法的一些代码示例,展示了Vertex.edges()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.edges()方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Vertex
类名称:Vertex
方法名:edges

Vertex.edges介绍

[英]Gets an Iterator of incident edges.
[中]获取事件边的迭代器。

代码示例

代码示例来源:origin: thinkaurelius/titan

private Edge findNext() {
  TitanEdge rel = null;
  while (rel == null) {
    if (currentEdges.hasNext()) {
      rel = (TitanEdge)currentEdges.next();
      if (vertices != null && !vertices.contains(rel.vertex(Direction.IN)))
        rel = null;
    } else {
      if (vertexIter.hasNext()) {
        Vertex nextVertex = vertexIter.next();
        currentEdges = nextVertex.edges(Direction.OUT);
      } else break;
    }
  }
  return rel;
}

代码示例来源:origin: JanusGraph/janusgraph

private Edge findNext() {
  JanusGraphEdge rel = null;
  while (rel == null) {
    if (currentEdges.hasNext()) {
      rel = (JanusGraphEdge)currentEdges.next();
      if (vertices != null && !vertices.contains(rel.vertex(Direction.IN)))
        rel = null;
    } else {
      if (vertexIterator.hasNext()) {
        Vertex nextVertex = vertexIterator.next();
        currentEdges = nextVertex.edges(Direction.OUT);
      } else break;
    }
  }
  return rel;
}

代码示例来源:origin: thinkaurelius/titan

@Test
public void testNestedTransactions() {
  Vertex v1 = graph.addVertex();
  newTx();
  Vertex v2 = tx.addVertex();
  v2.property("name", "foo");
  tx.commit();
  v1.addEdge("related", graph.traversal().V(v2).next());
  graph.tx().commit();
  assertCount(1, v1.edges(OUT));
}

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void testNestedTransactions() {
  Vertex v1 = graph.addVertex();
  newTx();
  Vertex v2 = tx.addVertex();
  v2.property("name", "foo");
  tx.commit();
  v1.addEdge("related", graph.traversal().V(v2).next());
  graph.tx().commit();
  assertCount(1, v1.edges(OUT));
}

代码示例来源:origin: apache/tinkerpop

/**
 * Returns an iterator of legal edges incident to the provided vertex.
 * If no edge filter is provided, then all incident edges are returned.
 *
 * @param vertex the vertex whose legal edges are to be access.
 * @return an iterator of edges that are {@link Legal#YES}.
 */
public Iterator<Edge> legalEdges(final Vertex vertex) {
  return null == this.edgeFilter ?
      vertex.edges(Direction.BOTH) :
      TraversalUtil.applyAll(vertex, this.edgeFilter);
}

代码示例来源:origin: apache/tinkerpop

public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Vertex hostVertex) {
  final Edge baseEdge = attachableEdge.get();
  final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT, attachableEdge.get().label());
  while (edgeIterator.hasNext()) {
    final Edge edge = edgeIterator.next();
    if (ElementHelper.areEqual(edge, baseEdge))
      return Optional.of(edge);
  }
  return Optional.empty();
}

代码示例来源:origin: apache/tinkerpop

@Override
protected Iterator<E> flatMap(final Traverser.Admin<Vertex> traverser) {
  return Vertex.class.isAssignableFrom(this.returnClass) ?
      (Iterator<E>) traverser.get().vertices(this.direction, this.edgeLabels) :
      (Iterator<E>) traverser.get().edges(this.direction, this.edgeLabels);
}

代码示例来源:origin: apache/tinkerpop

@Override
public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
  return IteratorUtils.map(this.getBaseVertex().edges(direction, edgeLabels), edge -> HadoopVertex.this.graph.edges(edge.id()).next());
}

代码示例来源:origin: apache/tinkerpop

@Override
public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
  if (state.equals(State.MAP_REDUCE))
    throw GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce();
  return IteratorUtils.map(this.getBaseVertex().edges(direction, edgeLabels), ComputerEdge::new);
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_INTEGER_VALUES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_EDGES)
public void shouldNotHaveAConcurrentModificationExceptionWhenIteratingAndRemovingAddingEdges() {
  final Vertex v1 = graph.addVertex("name", "marko");
  final Vertex v2 = graph.addVertex("name", "puppy");
  v1.addEdge("knows", v2, "since", 2010);
  v1.addEdge("pets", v2);
  v1.addEdge("walks", v2, "location", "arroyo");
  v2.addEdge("knows", v1, "since", 2010);
  assertEquals(4l, IteratorUtils.count(v1.edges(Direction.BOTH)));
  assertEquals(4l, IteratorUtils.count(v2.edges(Direction.BOTH)));
  v1.edges(Direction.BOTH).forEachRemaining(edge -> {
    v1.addEdge("livesWith", v2);
    v1.addEdge("walks", v2, "location", "river");
    edge.remove();
  });
  //assertEquals(8, v1.outE().count().next().intValue());  TODO: Neo4j is not happy
  //assertEquals(8, v2.outE().count().next().intValue());
  v1.edges(Direction.BOTH).forEachRemaining(Edge::remove);
  assertEquals(0, IteratorUtils.count(v1.edges(Direction.BOTH)));
  assertEquals(0, IteratorUtils.count(v2.edges(Direction.BOTH)));
}

代码示例来源:origin: apache/tinkerpop

public static Property createProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) {
    final Property baseProperty = attachableProperty.get();
    final Element baseElement = baseProperty.element();
    if (baseElement instanceof Vertex) {
      return Method.createVertexProperty((Attachable) attachableProperty, hostVertex);
    } else if (baseElement instanceof Edge) {
      final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT);
      if (edgeIterator.hasNext())
        return edgeIterator.next().property(baseProperty.key(), baseProperty.value());
      throw new IllegalStateException("Could not find edge to create the property on");
    } else { // vertex property
      final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(((VertexProperty) baseElement).key());
      while (vertexPropertyIterator.hasNext()) {
        final VertexProperty<Object> vp = vertexPropertyIterator.next();
        if (ElementHelper.areEqual(vp, baseElement))
          return vp.property(baseProperty.key(), baseProperty.value());
      }
      throw new IllegalStateException("Could not find vertex property to create the attachable property on");
    }
  }
}

代码示例来源:origin: hugegraph/hugegraph

@Test
public void testQueryBothEdgesOfVertex() {
  HugeGraph graph = graph();
  init18Edges();
  // Query edges of a vertex
  Vertex james = vertex("author", "id", 1);
  List<Edge> edges = graph.traversal().V(james.id()).bothE().toList();
  Assert.assertEquals(6, edges.size());
  edges = ImmutableList.copyOf(james.edges(Direction.BOTH));
  Assert.assertEquals(6, edges.size());
}

代码示例来源:origin: apache/tinkerpop

return (Optional) Method.getVertexProperty((Attachable) attachableProperty, hostVertex);
} else if (propertyElement instanceof Edge) {
  final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT);
  while (edgeIterator.hasNext()) {
    final Edge edge = edgeIterator.next();

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldTraverseInOutFromVertexWithMultipleEdgeLabelFilter() {
  final Vertex a = graph.addVertex();
  final Vertex b = graph.addVertex();
  final Vertex c = graph.addVertex();
  final String labelFriend = graphProvider.convertLabel("friend");
  final String labelHate = graphProvider.convertLabel("hate");
  final Edge aFriendB = a.addEdge(labelFriend, b);
  final Edge aFriendC = a.addEdge(labelFriend, c);
  final Edge aHateC = a.addEdge(labelHate, c);
  final Edge cHateA = c.addEdge(labelHate, a);
  final Edge cHateB = c.addEdge(labelHate, b);
  List<Edge> results = IteratorUtils.list(a.edges(Direction.OUT, labelFriend, labelHate));
  assertEquals(3, results.size());
  assertTrue(results.contains(aFriendB));
  assertTrue(results.contains(aFriendC));
  assertTrue(results.contains(aHateC));
  results = IteratorUtils.list(a.edges(Direction.IN, labelFriend, labelHate));
  assertEquals(1, results.size());
  assertTrue(results.contains(cHateA));
  results = IteratorUtils.list(b.edges(Direction.IN, labelFriend, labelHate));
  assertEquals(2, results.size());
  assertTrue(results.contains(aFriendB));
  assertTrue(results.contains(cHateB));
  results = IteratorUtils.list(b.edges(Direction.IN, graphProvider.convertLabel("blah1"), graphProvider.convertLabel("blah2")));
  assertEquals(0, results.size());
}

代码示例来源:origin: apache/tinkerpop

@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void testAttachableGetMethod() {
  // vertex host
  g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, DetachedFactory.detach(vertex, true).attach(Attachable.Method.get(vertex))));
  g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, DetachedFactory.detach(vertexProperty, true).attach(Attachable.Method.get(vertex)))));
  g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(vertex))))));
  g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, DetachedFactory.detach(edge, true).attach(Attachable.Method.get(vertex)))));
  g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(vertex))))));
  // graph host
  g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, DetachedFactory.detach(vertex, true).attach(Attachable.Method.get(graph))));
  g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, DetachedFactory.detach(vertexProperty, true).attach(Attachable.Method.get(graph)))));
  g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(graph))))));
  g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, DetachedFactory.detach(edge, true).attach(Attachable.Method.get(graph)))));
  g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(graph))))));
}

代码示例来源:origin: apache/tinkerpop

@Test
  @LoadGraphWith(LoadGraphWith.GraphData.CREW)
  public void testAttachableGetMethod() {
    // vertex host
    g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, ReferenceFactory.detach(vertex).attach(Attachable.Method.get(vertex))));
    g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, ReferenceFactory.detach(vertexProperty).attach(Attachable.Method.get(vertex)))));
    g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ReferenceFactory.detach(property).attach(Attachable.Method.get(vertex))))));
    g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, ReferenceFactory.detach(edge).attach(Attachable.Method.get(vertex)))));
    g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ReferenceFactory.detach(property).attach(Attachable.Method.get(vertex))))));

    // graph host
    g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, ReferenceFactory.detach(vertex).attach(Attachable.Method.get(graph))));
    g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, ReferenceFactory.detach(vertexProperty).attach(Attachable.Method.get(graph)))));
    g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ReferenceFactory.detach(property).attach(Attachable.Method.get(graph))))));
    g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, ReferenceFactory.detach(edge).attach(Attachable.Method.get(graph)))));
    g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ReferenceFactory.detach(property).attach(Attachable.Method.get(graph))))));

  }
}

代码示例来源:origin: apache/tinkerpop

public static void assertNoEdgeGraph(final Graph g1, final boolean assertDouble, final boolean lossyForId) {
  assertEquals(2, IteratorUtils.count(g1.vertices()));
  assertEquals(1, IteratorUtils.count(g1.edges()));
  final Vertex v1 = g1.traversal().V().has("name", "marko").next();
  assertEquals(29, v1.<Integer>value("age").intValue());
  assertEquals(2, v1.keys().size());
  assertEquals(Vertex.DEFAULT_LABEL, v1.label());
  assertId(g1, lossyForId, v1, 1);
  final List<Edge> v1Edges = IteratorUtils.list(v1.edges(Direction.BOTH));
  assertEquals(1, v1Edges.size());
  v1Edges.forEach(e -> {
    if (e.inVertex().value("name").equals("vadas")) {
      assertEquals(Edge.DEFAULT_LABEL, e.label());
      if (assertDouble)
        assertWeightLoosely(0.5d, e);
      else
        assertWeightLoosely(0.5f, e);
      assertEquals(1, e.keys().size());
      assertId(g1, lossyForId, e, 7);
    } else {
      fail("Edge not expected");
    }
  });
}

代码示例来源:origin: apache/tinkerpop

/**
 * Creates a new {@link StarGraph} from a {@link Vertex}.
 */
public static StarGraph of(final Vertex vertex) {
  if (vertex instanceof StarVertex) return (StarGraph) vertex.graph();
  // else convert to a star graph
  final StarGraph starGraph = new StarGraph();
  final StarVertex starVertex = (StarVertex) starGraph.addVertex(T.id, vertex.id(), T.label, vertex.label());
  final boolean supportsMetaProperties = vertex.graph().features().vertex().supportsMetaProperties();
  vertex.properties().forEachRemaining(vp -> {
    final VertexProperty<?> starVertexProperty = starVertex.property(VertexProperty.Cardinality.list, vp.key(), vp.value(), T.id, vp.id());
    if (supportsMetaProperties)
      vp.properties().forEachRemaining(p -> starVertexProperty.property(p.key(), p.value()));
  });
  vertex.edges(Direction.IN).forEachRemaining(edge -> {
    final Edge starEdge = starVertex.addInEdge(edge.label(), starGraph.addVertex(T.id, edge.outVertex().id()), T.id, edge.id());
    edge.properties().forEachRemaining(p -> starEdge.property(p.key(), p.value()));
  });
  vertex.edges(Direction.OUT).forEachRemaining(edge -> {
    final Edge starEdge = starVertex.addOutEdge(edge.label(), starGraph.addVertex(T.id, edge.inVertex().id()), T.id, edge.id());
    edge.properties().forEachRemaining(p -> starEdge.property(p.key(), p.value()));
  });
  return starGraph;
}

代码示例来源:origin: apache/tinkerpop

public static Edge createEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
  final Edge baseEdge = attachableEdge.get();
  Iterator<Vertex> vertices = hostGraph.vertices(baseEdge.outVertex().id());
  final Vertex outV = vertices.hasNext() ? vertices.next() : hostGraph.features().vertex().willAllowId(baseEdge.outVertex().id()) ? hostGraph.addVertex(T.id, baseEdge.outVertex().id()) : hostGraph.addVertex();
  vertices = hostGraph.vertices(baseEdge.inVertex().id());
  final Vertex inV = vertices.hasNext() ? vertices.next() : hostGraph.features().vertex().willAllowId(baseEdge.inVertex().id()) ? hostGraph.addVertex(T.id, baseEdge.inVertex().id()) : hostGraph.addVertex();
  if (ElementHelper.areEqual(outV, inV)) {
    final Iterator<Edge> itty = outV.edges(Direction.OUT, baseEdge.label());
    while (itty.hasNext()) {
      final Edge e = itty.next();
      if (ElementHelper.areEqual(baseEdge, e))
        return e;
    }
  }
  final Edge e = hostGraph.features().edge().willAllowId(baseEdge.id()) ? outV.addEdge(baseEdge.label(), inV, T.id, baseEdge.id()) : outV.addEdge(baseEdge.label(), inV);
  baseEdge.properties().forEachRemaining(p -> e.property(p.key(), p.value()));
  return e;
}

代码示例来源:origin: apache/tinkerpop

final VertexProperty newMexico = marko.property(VertexProperty.Cardinality.list, "location", "new mexico", "visible", true);
assertEquals(1, IteratorUtils.count(marko.edges(Direction.OUT)));
assertEquals(1, IteratorUtils.count(marko.edges(Direction.OUT, "knows")));
assertEquals(3, IteratorUtils.count(marko.properties()));
assertEquals(2, IteratorUtils.count(marko.properties("location")));
assertEquals(1, IteratorUtils.count(marko.properties("name")));
assertEquals(1, IteratorUtils.count(stephen.edges(Direction.IN)));
assertEquals(1, IteratorUtils.count(stephen.edges(Direction.IN, "knows")));
assertEquals(1, IteratorUtils.count(stephen.properties()));
assertEquals(1, IteratorUtils.count(stephen.properties("name")));

相关文章