/** * Get both the outgoing and incoming vertices of this edge. * The first vertex in the iterator is the outgoing vertex. * The second vertex in the iterator is the incoming vertex. * * @return an iterator of the two vertices of this edge */ public default Iterator<Vertex> bothVertices() { return this.vertices(Direction.BOTH); }
/** * Get the outgoing/tail vertex of this edge. * * @return the outgoing vertex of the edge */ public default Vertex outVertex() { return this.vertices(Direction.OUT).next(); }
/** * Get the incoming/head vertex of this edge. * * @return the incoming vertex of the edge */ public default Vertex inVertex() { return this.vertices(Direction.IN).next(); }
@Override protected Iterator<Vertex> flatMap(final Traverser.Admin<Edge> traverser) { return traverser.get().vertices(this.direction); }
@Override public Iterator<Vertex> vertices(final Direction direction) { switch (direction) { case OUT: return IteratorUtils.of(this.graph.vertices(getBaseEdge().vertices(Direction.OUT).next().id())).next(); case IN: return IteratorUtils.of(this.graph.vertices(getBaseEdge().vertices(Direction.IN).next().id())).next(); default: { final Iterator<Vertex> iterator = getBaseEdge().vertices(Direction.BOTH); return IteratorUtils.of(this.graph.vertices(iterator.next().id()).next(), this.graph.vertices(iterator.next().id()).next()); } } }
Vertex vv; if (direction.equals(Direction.IN) || direction.equals(Direction.OUT)) { vv = e.vertices(direction).next(); } else { vv = e.outVertex() == this.vertex ? e.inVertex() : e.outVertex();
@Override public void sendMessage(final MessageScope messageScope, final M message) { if (messageScope instanceof MessageScope.Local) { final MessageScope.Local<M> localMessageScope = (MessageScope.Local) messageScope; final Traversal.Admin<Vertex, Edge> incidentTraversal = SparkMessenger.setVertexStart(localMessageScope.getIncidentTraversal().get().asAdmin(), this.vertex); final Direction direction = SparkMessenger.getOppositeDirection(incidentTraversal); // handle processing for BOTH given TINKERPOP-1862 where the target of the message is the one opposite // the current vertex incidentTraversal.forEachRemaining(edge -> { if (direction.equals(Direction.IN) || direction.equals(Direction.OUT)) this.outgoingMessages.add(new Tuple2<>(edge.vertices(direction).next().id(), localMessageScope.getEdgeFunction().apply(message, edge))); else this.outgoingMessages.add(new Tuple2<>(edge instanceof StarGraph.StarOutEdge ? edge.inVertex().id() : edge.outVertex().id(), localMessageScope.getEdgeFunction().apply(message, edge))); }); } else { ((MessageScope.Global) messageScope).vertices().forEach(v -> this.outgoingMessages.add(new Tuple2<>(v.id(), message))); } }
private void addEdgeToSubgraph(final Edge edge) { final Iterator<Edge> edgeIterator = subgraph.edges(edge.id()); if (edgeIterator.hasNext()) return; final Iterator<Vertex> vertexIterator = edge.vertices(Direction.BOTH); final Vertex subGraphOutVertex = getOrCreate(vertexIterator.next()); final Vertex subGraphInVertex = getOrCreate(vertexIterator.next()); final Edge subGraphEdge = subGraphOutVertex.addEdge(edge.label(), subGraphInVertex, T.id, edge.id()); edge.properties().forEachRemaining(property -> subGraphEdge.property(property.key(), property.value())); } }
@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 shouldReturnOutThenInOnVertexIterator() { final Vertex a = graph.addVertex(); final Vertex b = graph.addVertex(); final Edge e = a.addEdge("knows", b); assertEquals(a, e.outVertex()); assertEquals(b, e.inVertex()); final Iterator<Vertex> iterator = e.vertices(Direction.BOTH); assertTrue(iterator.hasNext()); assertEquals(a, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(b, iterator.next()); assertFalse(iterator.hasNext()); } }
@Test @LoadGraphWith(GraphData.MODERN) public void shouldAttachToVertex() { final Edge toDetach = g.E(convertToEdgeId("josh", "created", "lop")).next(); final Vertex outV = toDetach.vertices(Direction.OUT).next(); final DetachedEdge detachedEdge = DetachedFactory.detach(toDetach, true); final Edge attached = detachedEdge.attach(Attachable.Method.get(outV)); assertEquals(toDetach, attached); assertFalse(attached instanceof DetachedEdge); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldAttachToVertex() { final Edge toReference = g.E(convertToEdgeId("josh", "created", "lop")).next(); final Vertex outV = toReference.vertices(Direction.OUT).next(); final ReferenceEdge referenceEdge = ReferenceFactory.detach(toReference); final Edge attached = referenceEdge.attach(Attachable.Method.get(outV)); assertEquals(toReference, attached); assertFalse(attached instanceof ReferenceEdge); }
@Override public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) { return TinkerHelper.inComputerMode(this.graph) ? direction.equals(Direction.BOTH) ? IteratorUtils.concat( IteratorUtils.map(this.edges(Direction.OUT, edgeLabels), Edge::inVertex), IteratorUtils.map(this.edges(Direction.IN, edgeLabels), Edge::outVertex)) : IteratorUtils.map(this.edges(direction, edgeLabels), edge -> edge.vertices(direction.opposite()).next()) : (Iterator) TinkerHelper.getVertices(this, direction, edgeLabels); }
/** * Get both the outgoing and incoming vertices of this edge. * The first vertex in the iterator is the outgoing vertex. * The second vertex in the iterator is the incoming vertex. * * @return an iterator of the two vertices of this edge */ public default Iterator<Vertex> bothVertices() { return this.vertices(Direction.BOTH); }
/** * Get the outgoing/tail vertex of this edge. * * @return the outgoing vertex of the edge */ public default Vertex outVertex() { return this.vertices(Direction.OUT).next(); }
private Map<String, Object> getVertexFields(Edge edge, Direction direction) { VertexSchema vertexSchema = direction.equals(parentDirection) ? parentVertexSchema : childVertexSchema; Vertex parent = edge.vertices(direction).next(); return vertexSchema.toFields(parent); }
@Override public Iterator<Vertex> vertices(Direction direction, String... edgeLabels) { return SetUtils.set(edges(direction, edgeLabels), e -> SetUtils.set(e.vertices(direction))) .stream() .reduce(new HashSet<>(), (result, next) -> SetUtils.union(result, next)) .iterator(); }
@Test @LoadGraphWith(GraphData.MODERN) public void shouldAttachToVertex() { final Edge toDetach = g.E(convertToEdgeId("josh", "created", "lop")).next(); final Vertex outV = toDetach.vertices(Direction.OUT).next(); final DetachedEdge detachedEdge = DetachedFactory.detach(toDetach, true); final Edge attached = detachedEdge.attach(Attachable.Method.get(outV)); assertEquals(toDetach, attached); assertFalse(attached instanceof DetachedEdge); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldAttachToVertex() { final Edge toReference = g.E(convertToEdgeId("josh", "created", "lop")).next(); final Vertex outV = toReference.vertices(Direction.OUT).next(); final ReferenceEdge referenceEdge = ReferenceFactory.detach(toReference); final Edge attached = referenceEdge.attach(Attachable.Method.get(outV)); assertEquals(toReference, attached); assertFalse(attached instanceof ReferenceEdge); }
@Override public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) { return TinkerHelper.inComputerMode(this.graph) ? direction.equals(Direction.BOTH) ? IteratorUtils.concat( IteratorUtils.map(this.edges(Direction.OUT, edgeLabels), Edge::inVertex), IteratorUtils.map(this.edges(Direction.IN, edgeLabels), Edge::outVertex)) : IteratorUtils.map(this.edges(direction, edgeLabels), edge -> edge.vertices(direction.opposite()).next()) : (Iterator) TinkerHelper.getVertices(this, direction, edgeLabels); }
@Override public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) { return TinkerHelper.inComputerMode(this.graph) ? direction.equals(Direction.BOTH) ? IteratorUtils.concat( IteratorUtils.map(this.edges(Direction.OUT, edgeLabels), Edge::inVertex), IteratorUtils.map(this.edges(Direction.IN, edgeLabels), Edge::outVertex)) : IteratorUtils.map(this.edges(direction, edgeLabels), edge -> edge.vertices(direction.opposite()).next()) : (Iterator) TinkerHelper.getVertices(this, direction, edgeLabels); }